I\'m using the Google Tag Manager container for managing scripts. I\'m trying to perform a server-side Optimize/Analytics experiment. I require server-side for performance r
Solved by explicitly specifying a tracker id.
I used Analytics Debugger Chrome by Google to debug the issue and found that Google Tag Manager (GTM) made the tracker id gtm1
so I had to prefix things with that.
To find out your tracker ID, call ga.getAll()[0].get('name')
(may be gtm1
, gtm2
, etc.).
Changed my setGAExperiment function to the following
function setGAExperimentCX(_expId, _vId){
ga('gtm1.set', 'exp', _expId.toString() + '.' + _vId.toString());
// this forces the above exp set to be sent to GA, you can name the event whatever you want with whatever values you want
ga('gtm1.send', 'event', 'Experiment', 'Trigger', _expId.toString() + '.' + _vId.toString());
}
The function that calls setGAExperimentCX is
function performNewCartExp(_vId) {
if (typeof ga == "undefined") {
if (_performNewCartExp != undefined) { clearTimeout(_performNewCartExp); }
_performNewCartExp = setTimeout(function () { performNewCartExp(_str); }, 250);
} else {
setGAExperimentCX('XXXXXXXXXXX', parseInt(_vId, 10));
}
}