5.6K members online now
5.6K members online now
Dive into multiple domain (Cross/Sub) tracking, implementing Ecommerce and Enhanced Ecommerce, setting up Event tracking, and Universal Analytics code.
 
Guide Me
star_border
Reply

Google Analytics Content Experiment Code in Google Tag Manager

Follower ✭ ✭ ☆
# 1
Follower ✭ ✭ ☆

Can I implement a GA content experiment code through GTM? I read the guide and it said to hard-code the code right after the opening header tag. Can I fire the code on experiment pages through GTM?

Highlighted

Google Analytics Content Experiment Code in Google Tag Manager

[ Edited ]
Participant ✭ ✭ ✭
# 2
Participant ✭ ✭ ✭

Hi Kevin,

 

I would say that this isn’t a replacement for any of the real A/B testing tools out there. Google Experiments are not supported in Google Tag Manager. There's something called Google Optimize that you can use if it's available in your country (unfortunately, not in my country). Here you can read more on how to implement Google Optimize through GTM.

 

Technically, yes, you can implement Content Experiments through GTM but you might come across with some problems. Let me explain.

 

GTM in its current state is not an A/B testing tool because it doesn’t support synchronous tags yet. Because it doesn’t support synchronous tags, you won’t be able to set up a variation before the page load begins. This means that you might see a flicker effect (can have a significant effect on test results) of the control variation before changes are applied to the elements you’re testing.

 

If the user sees the wrong variation before the right variation comes visible, the test won’t be that reliable, as some of the visitors will know they are being tested.

 

One of the things to do in order to reduce the flickering effect is splitting up the GTM container snippet and moving the script part of the snippet all the way to the top of the head (this is already an official recommendation as well). That way GTM will load earlier, which then loads the A/B test earlier but it's still not the ideal solution because GTM tag is asynchronous.

 

Yes, there are couple of tools available that helps to set up A/B testing through GTM but I haven't used them yet. For example: https://abtestguide.com/gtmtesting/  - let me know the results if you test it out. Smiley Happy

 

If you use Google Optimize, I know that there are some effective ways to mitigate the risk of page flicker when loading Optimize is to temporarily hide the page while the Optimize container loads. This can be accomplished by adding the page-hiding snippet as the first script on your page(s) – after the <meta charset> declarations and before your Optimize, Analytics and/or Tag Manager tags. Here you can read more about that: https://support.google.com/360suite/optimize/answer/6262084?hl=en

 

Hope this helps. If someone has an experience running A/B tests with GTM, let us know. That would be great to hear your thoughts. Smiley Happy

 

Cheers,

Taavi

Google Analytics Content Experiment Code in Google Tag Manager

Follower ✭ ✭ ☆
# 3
Follower ✭ ✭ ☆

Hi Kevin,

 

If you use Content Experiment with GTM, you should try to use "Content Experiments JavaScript API".

 

The guide is following: https://developers.google.com/analytics/devguides/collection/analyticsjs/experiments?hl=en#cxjs

 

You need to execute "cxApi.chooseVariation" as setup tag before sending pageview.

 

>> If the user sees the wrong variation before the right variation comes visible, the test won’t be that reliable, as some of the visitors will know they are being tested.

 

Yes, but markup with the corresponding elements hidden will improve somewhat.

 


Thanks.