AdWords is now Google Ads. Our new name reflects the full range of advertising options we offer across Search, Display, YouTube, and more. Learn more

Optimize
4.9K members online now
4.9K members online now
Discover how to select who is eligible to be in your experiment, and when they’re served experiment variations.
Guide Me
star_border
Reply
Highlighted

Prevent overlapping between 2 Experiments

[ Edited ]
Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

Hi,


Could you please help me with a rule that can exclude users that have already been exposed to one of other experiments in Google Optimize?

 

What is the best approach?

 

I am thinking about using 1st party cookie variable or some other custom variable that would mark the user as "exposed" so that another experiment will not affect him.

In addition I can use "run custom "JavaScript" in Optimize's visual editor that will create such a cookie. Will that solve the problem?

 

Also I can't understand how to prevent 2 experiments from running simultaneously. So that user who sees experiment A will not see experiment B or C (free version is limited to 3 experiments). Is there any rules or configuration that can help with that?

 

1 Expert replyverified_user

Prevent overlapping between 2 Experiments

Google Employee
# 2
Google Employee

Hi

 

I hope that there is soon better in-product support for this.

 

One idea could be to use "bucketing" based on the Google Analytics client Id so that you don't need to have another cookie.

 

Just create a "Custom Javascript" macro named to something like "Experiment Traffic Bucket" with code like

 

function() {

  return parseInt(ga.getAll()[0].get('clientId'))%3 + 1;

}

 

This will allow you to split your users in 3 buckets and then you can use experiment rules like

 

"Experiment Traffic Bucket" equals 3

 

or you could use multiple buckets.

 

"Experiment Traffic Bucket" equals 1, 3

 

 

Hope that this helps

Prevent overlapping between 2 Experiments

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭

@DimitrisD

 

Just to confirm, for the js code, can we just update the "3" with "10" if we wanted to create 10 separate buckets?

 

Secondly, do you know of any way to check in the developer console (or anywhere) to see which of the buckets we are currently listed in? Trying to find a way to verify the bucket and all optimize tests that are being provided to the user. 

Prevent overlapping between 2 Experiments

Google Employee
# 4
Google Employee

Yes, you can update '3' with '10' or any other number to have more buckets.

 

If you want to see which bucket you are in, in the developer console you could perhaps change the code above to print the bucket number. Or you can assign it in a global variable so that you could inspect it at anytime.

 

For example:

 

function() {

  window.optimize_bucket = parseInt(ga.getAll()[0].get('clientId'))%3 + 1;

  return window.optimize_bucket;

}

 

Now in the dev console you can just type window.optimize_bucket and see what it has been assigned to.

 

Now, if you want to see which experiments have been "triggered" at a page, there are a few methods.

 

- You can inspect the gaData window property and its "experiments" field for a property.

  It should have an object with all the experiments that were triggered and the assigned variant.

 

- You can search for the "collect" requests in the network tab and inspect their parameters. If there are experiments running, then one named "exp" should contain the assigned variants

 

- You can insect the value of the _gaexp cookie in the Application tab (for your domain). This collects the assigned variants to a visitor on any page.

Prevent overlapping between 2 Experiments

Visitor ✭ ✭ ✭
# 5
Visitor ✭ ✭ ✭

Dimitris D appreciate the help. By chance do you know if its possible post-launch of a test to force yourself into one of the variations?

 

Compared to going into incognito windows until you get into the experience. 

Prevent overlapping between 2 Experiments

Google Employee
# 6
Google Employee

Hi Brian

 

You can always use the preview functionality of the variants or the original. This is not identical with being in the test - for example you will not be sending any data to GA but this is usually a good thing if you want to see how the page looks like without affecting the real experiment data.

 

If you really want to force going into the test, you can use browser devtools and modify or set the experiment cookie. This is called _gaexp and contains the variant that a user is assigned to for each experiment. Its value looks like: 

GAX1.2.<experimentId1>.<expireInfo>.<variantIndex>!<experimentId1>.<expireInfo>.<variantIndex>

 

So you could for example change the variantIndex to force your self into another variant, (by reloading the page).

Prevent overlapping between 2 Experiments

[ Edited ]
Follower ✭ ☆ ☆
# 7
Follower ✭ ☆ ☆

@Dimitris: 

 

This method of using the ga.getAll() function like you showed (copied below) does not work for reliably for me. It seems to not work 50% of the time on Firefox and seems to work fine on Chrome and Edge. 

 

"""

function() {

  return parseInt(ga.getAll()[0].get('clientId'))%3 + 1;

}

"""

EDITED: 

Perhaps the ga object is not available in time every time to be able to do this. Do we really need to use a unchanging number like the userID or GA client ID like we do here? Can we instead just use the time when the user arrives: 

"""

function() {
var idx = document.cookie.indexOf( 'exp_bucket=' ) ;
if( idx >= 0 ) {
return document.cookie.substring(idx+11,idx+12);
}
else {
var bucket = parseInt(new Date().getTime())%5 + 1;
document.cookie = "exp_bucket=" + bucket;
return bucket
}
}

"""

Once the user is bucketed, we can store this as a cookie using document.cookie method as above and check for that each time.

 

Thoughts?

 

 

 

Prevent overlapping between 2 Experiments

Visitor ✭ ✭ ✭
# 8
Visitor ✭ ✭ ✭

@Kedar NWB Did this work better for you? 

 

And excuse my ignorance but am a designer rather than a developer, how/where do I beed to implement the custom javascript macro?

Re: Prevent overlapping between 2 Experiments

[ Edited ]
Follower ✭ ☆ ☆
# 9
Follower ✭ ☆ ☆

 @Tim C

 

Hi Tim, 

 

I managed to get this to work although I haven't checked if this has any impact on the pageload speeds. At least I did not perceive any significant delay just testing in my browser. 

 

Try out using Dimitrs's code and test it. It is simpler. Hopefully you don't have the same issue as me (i.e. it does not work in Firefox). Let me know if you do test it. 

 

Anyway here's where you include the Custom Javascript

1) Under Targeting,  click on "+ CREATE RULE" or the "AND" button (whichever is showing)

2) You'll see the targeting menu. In the this menu you'll see Custom JavaScript option (see screenshot below)

 

 CustomJavaScript.pngTargeting menu - Custom JavaScript

 

3) Then click on variable  >>   create new   (see screenshot below)

 

CustomJavaScript_p4.PNG

 

4) You'll then be able to enter your code there (screenshot below). You can name your variable anything you want. 

 

CustomJavaScript_p2.PNG

 

4)  If you want to use my approach: here's the latest code I use: (enter this in the box shown above) .  This will create 5 buckets and your variable will have values from 1 to 5. 

 

function() {
  var idx = document.cookie.indexOf( 'exp_bucket=' ) ;
  if(  idx  >= 0  ) {
       return  document.cookie.substring(idx+11,idx+12);
  }
  else {
      var bucket =  parseInt(new Date().getTime())%5 + 1;
      document.cookie  = "exp_bucket=" +  bucket;
      return bucket
          }  
}

 

If you want more or less buckets just replace the "5" in the line: 

var bucket =  parseInt(new Date().getTime())%5 + 1;

 with however many buckets you want to make. 

 

 

 5) Then to set the condition, choose less than or  greater than or equal etc.  (see screenshot below). 

In the screenshot below I have set the condition that my variable  <  3 (i.e.this experiment will include buckets 1,2. That's around 2/5th of the traffic). If I set it less than 6, it will include all traffic since the variable only takes values 1-5 . If I set it to just 1 it will include approximately 1/5th of the traffic and so on.

 

If you want to run two experiments on the same page. Set variable < 3 on one experiment and variable > 2 on the other. The one with variable > 2 will get a little more traffic but it will allow you to keep the visitors in these experiments separate.

 

CustomJavaScript_p3.PNG

 

 

Hope that helps. Let me know if you hit roadblocks. 

 

Cheers! 

 

 

Prevent overlapping between 2 Experiments

Google Employee
# 10
Google Employee

Hi

 

Yes if you store a cookie yourself, then this would work fine too.

The reason for using the ga.getAll was just to avoid having another cookie.
As long as the user is in the same "bucket", you will be be fine.

 

I will look into the problem that you mention though.

Do you follow the default inline installation method for Optimize (using a GA plugin?).