From 7df6e5d318c173ac11e9efd3847d71d73d09ff4c Mon Sep 17 00:00:00 2001 From: Maxime Quandalle Date: Sun, 8 Mar 2020 19:43:21 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20D=C3=A9sactive=20les=20cookies?= =?UTF-8?q?=20pour=20les=20iframes=20sur=20Safari=20Mobile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Relatif à #893. --- source/Tracker.ts | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/source/Tracker.ts b/source/Tracker.ts index 3e80fc4a7..ce3bde045 100644 --- a/source/Tracker.ts +++ b/source/Tracker.ts @@ -7,7 +7,9 @@ declare global { } } -type PushArgs = ['trackPageView'] | ['trackEvent', ...Array] +type TrackingAction = 'trackPageView' | 'trackEvent' | 'disableCookies' + +type PushArgs = [TrackingAction, ...Array] type PushType = (args: PushArgs) => void const ua = window.navigator.userAgent @@ -22,18 +24,15 @@ export default class Tracker { previousPath: string | undefined constructor( - pushFunction: PushType = args => { - // There is an issue with the way Safari handle cookies in iframe, cf. - // https://gist.github.com/iansltx/18caf551baaa60b79206. We could probably - // do better but for now we don't track action of iOs Safari user in - // iFrame -- to avoid errors in the number of visitors in our stats. - if (!(iOSSafari && inIframe)) { - window._paq.push(args) - } - } + pushFunction: PushType = args => (window?._paq ?? []).push(args) ) { - if (typeof window !== 'undefined') window._paq = window._paq || [] this.push = debounce(200, pushFunction) as PushType + // There is an issue with the way Safari handle cookies in iframe, cf. + // https://gist.github.com/iansltx/18caf551baaa60b79206. + // TODO : We don't need to disable cookies if a cookie is already set + if (iOSSafari && inIframe) { + pushFunction(['disableCookies']) + } } connectToHistory(history: History) {