diff --git a/index.html b/index.html index 78f84421b..612f2fc07 100644 --- a/index.html +++ b/index.html @@ -257,6 +257,22 @@ <% if (htmlWebpackPlugin.options.injectTrackingScript) { %> <% for (var chunk in htmlWebpackPlugin.files.chunks) { %> - + <% } %> diff --git a/source/Tracker.ts b/source/Tracker.ts index 830ee274b..3e80fc4a7 100644 --- a/source/Tracker.ts +++ b/source/Tracker.ts @@ -1,5 +1,5 @@ import { History, Location } from 'history' -import { debounce } from './utils' +import { debounce, inIframe } from './utils' declare global { interface Window { @@ -10,12 +10,28 @@ declare global { type PushArgs = ['trackPageView'] | ['trackEvent', ...Array] type PushType = (args: PushArgs) => void +const ua = window.navigator.userAgent +const iOSSafari = + (!!ua.match(/iPad/i) || !!ua.match(/iPhone/i)) && + !!ua.match(/WebKit/i) && + !ua.match(/CriOS/i) + export default class Tracker { push: PushType unlistenFromHistory: (() => void) | undefined previousPath: string | undefined - constructor(pushFunction: PushType = args => window._paq.push(args)) { + 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) + } + } + ) { if (typeof window !== 'undefined') window._paq = window._paq || [] this.push = debounce(200, pushFunction) as PushType }