Created
January 17, 2019 20:04
-
-
Save kyle-mccarthy/f3f29baf77605e8b8b00c7f25af897d6 to your computer and use it in GitHub Desktop.
Decorate outbound link for cross domain tracking
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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