Skip to content

Instantly share code, notes, and snippets.

@jsn789
Last active April 9, 2018 13:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsn789/dbc9b7443e5ad98e51b2a08ed37d316e to your computer and use it in GitHub Desktop.
Save jsn789/dbc9b7443e5ad98e51b2a08ed37d316e to your computer and use it in GitHub Desktop.
GTM Custom JavaScript - Set Client ID in a Custom Dimension. Used as a {{Variable}} in a customTask
function () {
return function () {
try {
// Retrieve all trackers
var trackers = ga.getAll();
trackers.forEach(function(tracker) {
// Get the Client ID
var cid = tracker.get('clientId');
// Set the Client ID in a custom dimension
tracker.set('dimension1', cid); //change dimension number here
});
} catch (e) {}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment