Setting up the A / B test on Google Analytics with Universal Analytics

Modified on Tue, 4 Dec, 2018 at 2:04 PM

Adding the variable in the different pages

(function(i, s, o, g, r, a, m) {
  i['GoogleAnalyticsObject'] = r;
  (i[r] =
    i[r] ||
    function() {
      (i[r].q = i[r].q || []).push(arguments);
    }),
    (i[r].l = 1 * new Date());
  (a = s.createElement(o)), (m = s.getElementsByTagName(o)[0]);
  a.async = 1;
  a.src = g;
  m.parentNode.insertBefore(a, m);
})(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');

// 1 - rajouter {'siteSpeedSampleRate': 100} dans les options du tracker pour suivre la vitesse d'un maximum de pages

ga('create', 'UA-XXXXXX-XX', 'example.com', { siteSpeedSampleRate: 100 });

// 2 - rajouter le code suivant

var cookie = document.cookie;

if (cookie.indexOf('fstrz=') !== -1) {
  ga('set', 'dimension1', cookie.indexOf('fstrz=true') !== -1 ? 'yes' : 'no');
} else {
  ga('set', 'dimension1', 'untracked');
}

// fin du code à rajouter

ga('send', 'pageview');


Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article