Last active
April 9, 2018 13:05
-
-
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
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
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