Skip to content

Instantly share code, notes, and snippets.

@jeremyyeo
Created November 12, 2017 20:19
Show Gist options
  • Save jeremyyeo/4a21e51c157ef62df5fc7c82189684e0 to your computer and use it in GitHub Desktop.
Save jeremyyeo/4a21e51c157ef62df5fc7c82189684e0 to your computer and use it in GitHub Desktop.
Extracts google analytics client id from _ga cookie
// 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';
}
}
@Aliance
Copy link

Aliance commented Jun 1, 2023

This is outdated code, now GA client ID should be got from the cookie: https://www.analyticsmania.com/post/get-google-analytics-client-id/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment