From c5a8f86c8df4839b396b00647abc0eea4a1c3f77 Mon Sep 17 00:00:00 2001 From: Maxime Quandalle Date: Wed, 11 Mar 2020 13:43:39 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20D=C3=A9sactivation=20des=20actio?= =?UTF-8?q?ns=20pour=20les=20iFrames=20Safari?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Revert de 233e9d3 et 7df6e5d --- index.html | 1 + source/Tracker.ts | 25 +++++++++++++------------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/index.html b/index.html index 791294843..612f2fc07 100644 --- a/index.html +++ b/index.html @@ -279,6 +279,7 @@ 'setDomains', ['*.mon-entreprise.fr', '*.mycompanyinfrance.fr'] ]) + _paq.push(['trackPageView']) _paq.push(['enableHeartBeatTimer', 30]) _paq.push(['enableLinkTracking']) ;(function() { diff --git a/source/Tracker.ts b/source/Tracker.ts index 22d590aed..b6efbd9c6 100644 --- a/source/Tracker.ts +++ b/source/Tracker.ts @@ -7,12 +7,11 @@ declare global { } } -type TrackingAction = 'trackPageView' | 'trackEvent' | 'disableCookies' - -type PushArgs = [TrackingAction, ...Array] +type PushArgs = ['trackPageView'] | ['trackEvent', ...Array] type PushType = (args: PushArgs) => void const ua = window.navigator.userAgent +// https://chromium.googlesource.com/chromium/src.git/+/master/docs/ios/user_agent.md const iOSSafari = (!!ua.match(/iPad/i) || !!ua.match(/iPhone/i)) && !!ua.match(/WebKit/i) && @@ -24,16 +23,18 @@ export default class Tracker { previousPath: string | undefined constructor( - pushFunction: PushType = args => (window?._paq ?? []).push(args) - ) { - 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']) + 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(['trackPageView']) + ) { + if (typeof window !== 'undefined') window._paq = window._paq || [] + this.push = debounce(200, pushFunction) as PushType } connectToHistory(history: History) {