Skip to content

Instantly share code, notes, and snippets.

@kyle-mccarthy
Created January 17, 2019 20:04
Show Gist options
  • Save kyle-mccarthy/f3f29baf77605e8b8b00c7f25af897d6 to your computer and use it in GitHub Desktop.
Save kyle-mccarthy/f3f29baf77605e8b8b00c7f25af897d6 to your computer and use it in GitHub Desktop.
Decorate outbound link for cross domain tracking
const decorateLink = (destinationUrl) => {
if (ga !== undefined && typeof ga.getAll === 'function') {
const trackers = ga.getAll();
if (trackers.length > 0) {
const linker = new window.gaplugins.Linker(trackers[0]);
return linker.decorate(destinationUrl);
}
}
return destinationUrl;
}
// usage
// decorateLink('https://google.com')
// https://google.com?_ga=XXXX
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment