Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to read ExperimentId and VariationId in Javascript with Google Optimize?

I have created an A/B-test using Google Optimize. Now I would like to read the current experimentId and variationId in Javascript. My goal is to run different javascript based on the given variation.

I can't seem to find any info on this in the documentation. Is it possible?

like image 304
Øyvind Holmstad Avatar asked Jun 07 '17 12:06

Øyvind Holmstad


People also ask

How do I use Google optimize for JavaScript?

Method 2: Run JavaScriptStep 1 – Click and highlight the CTA you want to change. Step 2 – Click 'Edit element' or press right-click. Then click 'Run JavaScript'. Step 3 – Add the JavaScript code and click 'Apply'.

What can you test with Google optimize?

Google Optimize is a native Google Optimization Platform, which has direct integration with Google Analytics, and allows you to run AB, multivariate tests, and redirect tests – all based on the previous data collected.

How do I get Google optimized experiment ID?

Experiment ID – A unique ID available in the information panel on the Optimize experiment details page. E.g. IzxbYxEfTeuq3bQqIAHB9g. Experiment ID with Variant – The Experiment ID with the Variant ID appended to it. Available in the information panel on the Optimize experiment details page.

What can you do with Google optimize?

Optimize allows you to test variants of web pages and see how they perform against an objective that you specify. Optimize monitors the results of your experiment and tells you which variant is the leader.


1 Answers

Now there is also the Google Optimize javascript API available that is a better option:

The experimentId is now available in the Optimize UI, as soon as the experiment is created (before start).

The API is already available in the page and you can use it like this:

google_optimize.get('<experimentId>'); 

(note: this will work only after the Optimize container script has been loaded)

You can also register a callback to run the javascript that you want at any time (even before the Optimize script has been loaded) using:

function gtag() {dataLayer.push(arguments)}  function implementExperimentA(value) {   if (value ==  '0') {     // Provide code for visitors in the original.   } else if (value == '1') {     // Provide code for visitors in first variant.   }  gtag('event', 'optimize.callback', {     name: '<experiment_id_A>',     callback: implementExperimentA  }); 

If you want to find both the experimentId and variation you can register a callback for any experiment:

function implementManyExperiments(value, name) {   if (name == '<experiment_id_A>') {     // Provide implementation for experiment A     if (value ==  '0') {       // Provide code for visitors in the original.     } else if (value == '1') {       // Provide code for visitors in first variant.     ...   } else if (name == '<experiment_id_B>') {     // Provide implementation for experiment B     ... }  gtag('event', 'optimize.callback', {     callback: implementManyExperiments  }); 

For more details

https://support.google.com/optimize/answer/9059383

like image 148
Optimize Team Avatar answered Sep 21 '22 22:09

Optimize Team