1

UPDATE: It took 5 hours

I have set up a Google Experiment using Google Tag Manager code to send a hit with the ID and Variation. I'm just wondering how long it takes the Google Experiment to record session data as I'm anxious that its not working?

Thanks

This is my code:


<script type="text/javascript">

var expID = 'XXXXXXXXXXXX'; //Set up an experiment and pull through the ID;
var cusDom = [1, 'example.com']; //If Needed set BOOLEAN to 1, if not 0;
var trackingType = "GAClassic"; //Select Only One;
var variations = [
    {
        'fn' : function () {
            ;
        }
    },

    {
        'fn' : function () {
document.getElementById("ContactUs").innerHTML = "Register Interest";
        }
    }
];

var tempBoolean = false;

var gaExScript = document.createElement('script');
gaExScript.src="https://www.google-analytics.com/cx/api.js?experiment="+expID;
document.head.appendChild(gaExScript);

function bleep() {  
    if(tempBoolean == true){
    var variNum = 999;

    if(cusDom[0] === true){cxApi.setDomainName(cusDom[1]);}

    var variationNumber = Math.floor(Math.random() * variations.length);
    var previousVariation = cxApi.getChosenVariation(expID);

    if (previousVariation != -1){
        cxApi.setChosenVariation(previousVariation);
        window.onload = variations[previousVariation].fn;
        variNum = previousVariation;
    }else{
        cxApi.setChosenVariation(variationNumber);
        window.onload = variations[variationNumber].fn;
        variNum = variationNumber;
    }
    var analyticsScript = document.createElement('script');
    if(trackingType == "GAClassic"){analyticsScript.innerHTML = "_gaq.push(['_trackEvent', 'CRO Experiment', 'Experiment ID: " + expID + "', 'Variation ID: " + variNum + "']);";}
    else if(trackingType == "GAUniversal"){analyticsScript.innerHTML = "ga('send', 'event', 'CRO Experiment', 'Experiment ID: " + expID + "', 'Variation ID: " + variNum + "', {nonInteraction: true});";}
    else if(trackingType == "GTM"){analyticsScript.innerHTML = "dataLayer.push({'event': 'eventGA', 'eventCategory': 'CRO Experiment', 'eventAction': 'Experiment ID: " + expID + "', 'eventLabel': 'Variation ID: " + variNum + "', 'eventValue': '0', 'eventNonInteraction': 'false'});";}
    document.head.appendChild(analyticsScript);
    } 
};

gaExScript.onload = function(){
        tempBoolean = true;
        bleep();
}

</script>

It appears that the events are firing correctly. However, the sessions are not showing on my experiment.

3
  • In answer to my own question - it took 5 hours and now works!! Commented Jan 26, 2017 at 13:06
  • 1
    Thanks for the update. Can you add it as an answer below and accept it when you can so we can consider this question closed? Thanks.
    – dan
    Commented Jan 27, 2017 at 1:34
  • Thanks, you should be able to in 24 hours - if not, comment back.
    – dan
    Commented Jan 27, 2017 at 8:34

1 Answer 1

2

In addition to my update above, my experiment is now tracking correctly. The data took around 5 hours to come through so if you're setting one up, I recommend being patient!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.