I've started rolling out new features to a site using Netlify's branch split testing so I can say ex. 10% of users gets a branch with a specific UI change to see if it produces measurably different results. I have google analytics events set up to track some useful metrics already.

How can I compare the events in branch A with branch B in google analytics? I think there are two parts here: how to change the analytics code to identify sessions on branch A vs branch B, and also where to create a view in google analytics that I can compare events from sessions in A to sessions in B.

I'm happy with the tools I'm using so I'd like to avoid cluttering my page with yet another tracking script from a single-purpose A/B test provider when I'm pretty sure my existing tools can do this, I just don't know how.


Google Analytics has built in support for multivariate A/B testing. The first is available within GA under "Behavior" -> "Experiments." The second way to do this is via Google Optimize.

I'm not sure how these would work with the A/B testing solution you are already using but it will provide a great way to compare analytic performance between the different versions.

  • Thanks for the help. Optimize seems like an interesting and easy to use tool for testing text changes and other cosmetic edits on a page - netlify A/B gets a bit more powerful since I can deploy code base changes. – Nick Dec 20 '18 at 17:24

After a bit more experimentation, I figured out what I was looking for:

Netlify adds an environmental variable BRANCH that tells you what portion of the A/B test you're on. I created a new dimension in google analytics and used my analytics tags to set dimension4: process.env.BRANCH.

To compare against normal traffic in google analytics, I created a fresh segment that was based off my new dimension, matching the branch name exactly. Now I can compare traffic or events on any screen that can compare between segments.

  • 1
    can you detailed your process to create your dimension and get the data in a segment on Analytics. I added the following code on our branches: ga('send', 'pageview', { 'Branch': 'branch-name' }); I created a personalized dimension in analytics named 'branch-name' but I don't see any data when looking at this dimension in my report. Did I forget any steps? – Yann Jan 31 at 13:29
  • The key name isn't Branch, it's dimension4 or whichever dimension number you want to use. – Nick Jan 31 at 21:30

protected by Community Feb 4 at 7:14

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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