Google Tag Manager & Optimize Server-Side experiment sending variation

后端 未结 3 461
醉话见心
醉话见心 2020-12-28 10:24

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

3条回答
  •  时光取名叫无心
    2020-12-28 11:14

    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));
        }
    }
    

提交回复
热议问题