Skip to content

Instantly share code, notes, and snippets.

@ju1
Created January 20, 2018 15:04
Show Gist options
  • Save ju1/e3f19e95bd7df2c2a8a5d12266b7ee23 to your computer and use it in GitHub Desktop.
Save ju1/e3f19e95bd7df2c2a8a5d12266b7ee23 to your computer and use it in GitHub Desktop.
Google Analytics Cross-domain tracking: Find and decorate iFrame
function() {
return function() {
try {
var gobj = window[window.GoogleAnalyticsObject];
var iframe = document.querySelector('#myIframe');
var tracker, linker;
if (gobj) {
tracker = gobj.getAll()[0];
linker = new window.gaplugins.Linker(tracker);
iframe.src = linker.decorate(iframe.src);
}
} catch(e) {}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment