Tracking Sitecore A/B tests with Google Analytics

Jack Spektor
Nov 8, 2020

As many of you may know Sitecore comes with handy A/B tests functionality OOTB.

It allows you to easily specify variations for your data sources and components, measure the performance with Sitecore analytics and choose the winner based on that performance.

Yet many websites uses Google Analytics for tracking the website performance. Without doubt with Google tracking you could get much more information about visiting patterns, and its far more reliable and industry standard.

So can we use both of them?

Luckily we can. For that we are going to push the current variation information into the dataLayer and later we’d be able to use it to track the users that were exposed to specific variation in Sitecore A/B tests.

Step #1 — Getting current A/B test variation in a pipeline

We are going to use the page item tracking field to find the related A/B test and then we’ll use TestManager Sitecore API class to get the variation that is currently exposed to the user.

Step #2 — Exposing current variation in the dataLayer

We’ll create an ASP.NET HTML helper that would build and join all available A/B test data together in the dataLayer variable.

Now all we need to track the A/B tests is to call the @Html.ContentTestingDataLayer in our code and configure the GTM to pickup the dataLayer in the analytics.

Happy coding!

--

--

Jack Spektor

Sitecore MVP 2018–2020, Sitecore Developer in AKQA, traveler and lover of life.