Rich-text Reply

Redirect with cookie

Michael_Yang 01-16-19
Accepted Solution

Redirect with cookie

We are having a test where we implement custom JavaScropt code like this

if (getCookie("Name of cookie").indexOf("true") === -1) {
  setCookie("Name of cookie", "true", 14);
  setCookie("referrerCookie", document.referrer, 1);
  window.location.href = window.location.href;
}
check_ga_referrer();

With this code, we are setting a redirect with our server to run the experiment.

 

But when looking at the data, we found in GA that we only got data from the control group, not the variation group. After debugging, we noticed that the assign to campaign event did not fire when the users enter the experiment.

 

Does anyone know why this is happening and how we can fix it?

 

Thanks to the community! 

JasonDahlin 01-16-19
 

Re: Redirect with cookie

If I'm following this correctly...

1- the code you provided is what you are doing inside the variation and not inside control

2- If the cookie does not say "true", set the cookie and reload the page

3- when the page does not reload, check_ga_referrer() runs

 

What does check_ga_referrer do? Is this where experiment information is sent to GA?

If the redirect happens before you send the experiment information to GA, then you need to make sure that whatever page they are redirected to is a page within the experiment.

--Jason Dahlin
Analytics and Testing Guru Smiley Happy


Experimentation Hero

Re: Redirect with cookie

HI Jason,
the check_ga_referrer is just for our SEO effort.
We found that the Optimizely event "assigned to campaign" does not fire after the redirect. Is this the problem you were mentioning about the page not being in the experiment?

We think the event not firing is why we only have control group data in GA and not the variation group.

Do you know how we can solve this.

Thank you very much!
JasonDahlin 01-16-19
 

Re: Redirect with cookie

Hi @Michael_Yang,

If the code you posted above runs before Optimizely has a chance to send the experiment information to GA (perhaps you have GA installed after Optimizely, which is the recommended approach to reduce flashing, etc.), then the user appearing in the experiment will NOT be sent on this page. To get around this, you should include the page you are redirecting to in your experiment.

 

e.g.

Users lands on "home"

Control group stays on "home" and your experiment info is available top be sent to GA

Test group is redirected to "newpage"

- if "newpage" is not included in your experiment setup, then that information is not available for GA to send

- solution: add "newpage" to the experiment so that when the page hit happens, the experiment is running on that page and therefore your GA integration will record the page hit with the experiment info

 

if users can hit "newpage" outside of the experiment, then these users that access it directly will be randomly bucketed into A/B... so you may need to "wiggle" how you do things so that you are only capturing those users redirected as part of the experiment.

 

Sidenote: this ought not affect the users appearing in the experiment within Optimizely, since they  place the information into a queue (inside localStorage - I think) which persists across pages and would then send on the next page hit on the same domain where Optimizely exists, even if the experiment is not running on that page.

--Jason Dahlin
Analytics and Testing Guru Smiley Happy


Experimentation Hero

Re: Redirect with cookie

Hi Jason,

With your example, do you mean I should add "newpage" to the targeting setup for the experiment?
or are you referring to another method to include pages in the experiment?

And since the information is placed in a queue, we can know that the redirected traffic to the "new page" won't be targeted and bucketed again, since they already have optimizely experiment information existing.

Thanks!



JasonDahlin 01-17-19
 

Re: Redirect with cookie

Hi @Michael_Yang,

"do you mean I should add "newpage" to the targeting setup "

Yes. you'll want the experiment to run on the page (even if it does nothing) so that you can track it in GA

 

"we can know that the redirected traffic to the "new page" won't be targeted and bucketed again, since they already have optimizely experiment information existing"

Yes, but only if you are absolutely positive that users cannot reach this page outside of the experiment. If a user can reach this page through any other links (on your site, via Google, etc.), then you will want to take steps to make sure that unbucketed users are not placed into the experiment (otherwise you'd see A users interacting with the B page which could cause confusion in your analysis)

--Jason Dahlin
Analytics and Testing Guru Smiley Happy


Experimentation Hero

Re: Redirect with cookie

Hi Jason,
It is working as expected! Thank you very much!