Rich-text Reply

Is There a straight forward way to Passing the Experiment ID into Google Analytics

SBarbera 03-14-16

Is There a straight forward way to Passing the Experiment ID into Google Analytics

Has anyone successfully been able to pass the Experiment ID into a specific custom dimension set through Tealium to pass along into Google Analytics?

Level 1

David_Orr 03-15-16
 

Re: Is There a straight forward way to Passing the Experiment ID into Google Analytics

Hi,

I haven't created an implementation you mentioned but here is a high level of the order of events that need to occur. Please note, the steps assume you are firing GA and Optimizely through Tealium.

 

1. Tealium loads.
2. Optimizely loads.
3. GA object is created.
4. Optimizely populates a specific dimension.
5. GA pageview fires.

 

You will need to be able to control the order of events. Step 4 will require you to run javascript on tealium before the pageview call fires. The code will check set a dimension with the last running active experiment that matches the dimension in the code.

 

To use the code, replace the 3 in "if(slot == 3)" and "dimension3" near the last part of the code with the custom dimension you defined.

 

 

function () {

if(window.optimizely) {

var o = optimizely;

if(o.activeExperiments && o.allExperiments) {

for(var i=0;i<o.activeExperiments.length;i++) {

var experimentId = o.activeExperiments[i];

var experiment = o.allExperiments[experimentId];

if(experiment && experiment.universal_analytics) {

var slot = experiment.universal_analytics.slot;

if(slot == 3) { // you would fill this in with the slot you are using in Optimizely for this experiment.

if(o.variationIdsMap && o.variationNamesMap) {

var experimentName = experimentId + ': ' + o.variationNamesMap[experimentId];

ga('set', 'dimension3', experimentName);

return

                                }

                        }

                }

        }

}

}

return undefined;

}

 

 David

Senior Technical Support Engineer
Optimizely