So, I created "javascript code" variable in GTM and trying to get clientID via ga.getAll, and have the following code:
function foo() {
var trackers = ga.getAll();
if (trackers.length > 0) {
return trackers[0].get('trackingId') === 'UA-188398635-1' ? trackers[0].get('clientId') : 'nonon';
}
}
But it always returns undefined, even if I make it return a string constant 'asdasd' - having ga.getAll in the code is enough for the function to break. And the most confusing thing - the same code works in debug console just fine. Help please.
Since foo returns undefined, that means that trackers.length is 0. Try this:
function foo() {
var trackers = ga.getAll();
if(trackers.length >0) {
return trackers[0].get('trackingId') === 'UA-188082465-1' ? trackers[0].get('clientId') : 'nonon';
} else {
return 'This is not undefined';
}
}