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
2.3K members online now
2.3K members online now
Learn how to create your first experiment and get tips on creating A/B, redirect, and multivariate tests.
Guide Me
star_border
Reply

Querying the google optimize cookies in code

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

I'd like to use google optimize for for controlling of tests and reporting, but not for changing content in the page. I'd like to use it in my code as I have with other ab testing setups, so if I'm in one side of the split test then do something different. Assuming I should do that here by just checking the value of a cookie. But what cookies are set based on my split test? Will they be easy to spot?

 

Previously we were using some split testing code that set a cookie with name ab_ + the test name and set it to a value of experiment so the cookie might match /ab_MY_TEST=MY_EXPERIMENT/ but normally there'd be a helper function to test this, say

 

if (abba.test('MY_TEST').is('MY_EXPERIMENT')) {

  // we're in the split test

}

 

do I have ga helper functions to help me identify which split test I'm on? If not what cookie do I look for to tell me this? Guessing it's going to be code names of tests rather than friendly strings.

 

if (document.cookie.match(/ab_hosted_session=.*hosted_session/)) {

  // we're in our split test

}

 

2 Expert replyverified_user
1 ACCEPTED SOLUTION

Accepted Solutions
Marked as Best Answer.
Solution
Accepted by Jason O (Community Manager)
December 2016

Querying the google optimize cookies in code

Google Employee
# 4
Google Employee

An idea would be to add a single "Run Javascript" change in each of your variations where you set a global window variable with a value or your preference.

 

You could then use this global variable in your own code - just make sure that this is happening after the Optimize container has been loaded and run.

View solution in original post

Querying the google optimize cookies in code

Visitor ✭ ✭ ✭
# 2
Visitor ✭ ✭ ✭

to answer my own questions slightly I can see a cookie being set, along the lines of

 

_gaexp=GAX1.3.a2rn7FxGTuOEl_0hna455w.17230.0

 

what does this mean? How do I decode it? Or are their other tools I can use to say "what experiment is running? what side of that experiment am I in?"

Querying the google optimize cookies in code

Top Contributor
# 3
Top Contributor

Hi @Paul C - the last number is the variation - all the rest I have no idea yet. The info you seek will probably be available once and if an Optimize API is exposed.

 

Kind regards,

Zorin

Web analyst @ escapestudio.net
Marked as Best Answer.
Solution
Accepted by Jason O (Community Manager)
December 2016

Querying the google optimize cookies in code

Google Employee
# 4
Google Employee

An idea would be to add a single "Run Javascript" change in each of your variations where you set a global window variable with a value or your preference.

 

You could then use this global variable in your own code - just make sure that this is happening after the Optimize container has been loaded and run.

Querying the google optimize cookies in code

Visitor ✭ ✭ ✭
# 5
Visitor ✭ ✭ ✭

thanks, but feels like an extra manual step that we should be able to avoid

Querying the google optimize cookies in code

Visitor ✭ ✭ ✭
# 6
Visitor ✭ ✭ ✭

Hi @Paul C ,

Did u ever figure this one out? We too want to know the variation in javascript code Smiley Happy

thx

Querying the google optimize cookies in code

Visitor ✭ ✭ ✭
# 7
Visitor ✭ ✭ ✭

sorry no, I stopped trying to use google optimise for this purpose

Querying the google optimize cookies in code

Visitor ✭ ✭ ✭
# 8
Visitor ✭ ✭ ✭