Created
November 12, 2017 20:19
-
-
Save jeremyyeo/4a21e51c157ef62df5fc7c82189684e0 to your computer and use it in GitHub Desktop.
Extracts google analytics client id from _ga cookie
This file contains 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
// For use as custom variable in Google Tag Manager. | |
function() { | |
try { | |
var tracker = ga.getAll()[0]; | |
return tracker.get('clientId'); | |
} catch(e) { | |
return 'N/A'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is outdated code, now GA client ID should be got from the cookie: https://www.analyticsmania.com/post/get-google-analytics-client-id/