How to run Google Experiment within Google Tag Manager
Asked Answered
A

4

11

I have been trying to get this to work for sometime and there seems to be very little information on how this works.

First, I would like to say that I tried the below method to get it working, so please read this before posting a solution.

What I tried: I added the google analytics experiment code in a custom HTML block and had it fire only of the original page as stated by google. This doesn't work and seems to create a loop for users. A white page appears when users get to the experiment pages.

Does anyone know how to get this to work? Much appreciated

Agateware answered 10/5, 2014 at 0:21 Comment(0)
M
7

The Javascript versions of Google Content Experiments are not actually supported in GTM at the moment (they have do do either redirects or change the site on the fly and since it's hard to say in advance at which point during page load the tags fire, and it which order, this does not work very well - in the very best case the original page would load completely before the visitor is redirected to a variation).

The features page for GTM lists A/b testing tags as "coming soon" but does so since at least a year ago, so I wouldn't hold my breath.

However you can do variations serverside (you'd have to implement your own logic to display the proper variation to each users) and pass and experiment id and the variation number to GA via GTM. I do not think there is another (reliable) way to do this, at least not yet. If you need to do it with javascript you should add the experiment scripts to the page code instead of deploying them via tag managemement.

Having said that, there are descriptions for hacking around the GTM limitations using the Experiments Javascript API and some jQuery (here is one). When Google says that something is "not supported" it might just mean they didn't want to test all possible edge cases and err on the safe side. So you if you absolutely have to use GTM for Content Experiments you would have to test if something like this would work for you.

Mattheus answered 10/5, 2014 at 13:48 Comment(1)
Thanks dood. This forum is much better than google forums. Some adwords agent said you can do it, but turns out they don't know shit and keep proving it! +EikeAgateware
A
1

I hope that I understand your problem well. If yes, you can use Google Optimize instead of Google Experiment. The Google Optimize works with Google Tag Manager by default.

Aberrant answered 3/10, 2017 at 9:57 Comment(0)
C
0

Here's what worked for me

  1. For the pages in the Experiment, I implemented Google Analytics the "old fashioned way" with analytics.js instead of GTM.

  2. I tested (with Realtime analytics) this and the Experiment page and the Google Tag Pages both report data.

I did post asking if there might be conflicts from ths.

Caulis answered 22/10, 2015 at 20:10 Comment(0)
H
-1

It's possible to modify the Google Tag Manager (GTM) snippet to run synchronously by removing the j.async=true; line and placing it at the top of your page, immediately after the opening <head> element. Like so:

<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.src=
'//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-XXXX');</script>
<!-- End Google Tag Manager -->

You can also retain support for users without Javascript by inserting the <iframe> part of the code in the original location specified by GTM (after your opening <body> element).

<noscript><iframe src="//www.googletagmanager.com/ns.html?id=GTM-XXXX"
height="0" width="0" style="display:none;visibility:hidden"></iframe</noscript>

It's then possible to insert the Google Analytics Experiments code as a Custom HTML tag in GTM. Just make sure you check the 'support document.write()' checkbox.

Just don't forget to update GTM-XXXX with your container ID.

Hypomania answered 15/5, 2015 at 13:44 Comment(1)
I tried this and it didn't work. When I tried to Validate the Google Experiment Code it "was not found".Caulis

© 2022 - 2024 — McMap. All rights reserved.