Running GA Experiments across domains w/ Universal Analytics, linker works but Experiment code ignores clientId

532 Views Asked by At

Been trying to get this working for a few weeks now. Any help is greatly appreciated.

I have recently upgraded to Universal Analytics and managed to successfully set up cross domain tracking with the autoLinker but I can't get my Analytics Experiment to pass the _ga variable when redirecting the user to a domain part of the experiment.

Setup

  • Both domains have two trackers, one (t0) which they share [UA-xxxxxxx-5] and one (domainUniqueTracker) which logs to a trackingId unique for that specific domain ([UA-xxxxxxx-1] for main domain and [UA-xxxxxxx-14] for new experimental domain).
  • Linker is loaded on t0 to enable sharing across domains.
  • Linker is loaded with an array of domains, including the domain I'm trying to send traffic to via the experiment.
  • Experiment is created on shared trackingId [UA-xxxxxxx-5].

Context

My company has a product called LIME Pro where we until now have had info about on our company web page. Now, as an experiment we have created a one-page about the system on a separate domain, and they want to see which page (old or new) attracts most leads.

Old product page within company web page (experiment code installed there) http://www.lundalogik.se/crm-system/lime-pro/

New product page on separate domain (shares trackingId with main domain on tracker t0) http://www.lime-pro.se

Problem

If I visit www.lundalogik.se and from there click on a normal link to the new, external site (normal anchor link on dummy-page lundalogik.se/experiment/) the clientId is successfully passed along in the URL and the tracker at the external site recognises this and starts using the clientId.

But if I browse to the page where the experiment code is installed, I am redirected to the external site without the clientId being passed along, so the tracker at the external site generates a new clientId.

Thanks and sorry about long post, wanted to explain in as much detail as I could.

2

There are 2 best solutions below

0
On BEST ANSWER

My apologies for only having half an answer but I got orders from above to drop this before I got it fully working. Hopefully it will still be somewhat helpful for someone looking to do the same.

If you do get the receiving part done, please post your code here and I'll update this answer/reward you with the answer.

OK here goes nothing..


The sending side works and adds the clientId to the hash and it is successfully transfered when the experiment does a cross domain redirect.

PAGE WITH EXPERIMENT CODE

Execute this before you run the experiment code.

var z, y, x = document.cookie.split("; ");
for (var i = 0; i < x.length; i++) {
    y=x[i].split("=");
    if (y[0] == "_ga") window.location.hash = y[1];
}

PAGE ON CROSS DOMAIN

Here is where I never got to before receiving my orders to drop this. But you would do something like:

  1. checking window.location.hash and if it contains a clientId (window.location.hash.substr(0,3) == "#GA")
  2. check for existing cookie 2.1. (exists) split cookie by "; ", find "_ga" and replace it's value with above hash (remove "#" first) 2.2. (doesnt exist) create a new cookie at domain level and set "_ga=(hash-value)"
  3. initiate google analytics tracker which would assume the visitor already had accessed the page before and accept the client-id from the cookie
  4. live long and prosper

So, sorry again for an answer is only partially complete but hopefully someone will benefit from this.

Or at least not assume they are mad like I did when I couldn't get it working :).

If the community would like I will of course remove the "accepted answer" if this is considered bad practice (this is only my second post ever to the SO network).

2
On

The various linker functions in UA add _ga to outgoing links (form, frames etc.). Since the redirect happens in the experiment javascript the client id cannot be added to the url (which in a way seems to be an oversight on Googles part - it seems they did not anticipate your use case, i.e. content experiments across domains).

I have a few untested ideas to contribute, maybe you can build a solution on top of one of them.

1) Before the experiment code fires push the client id to window.document.location.hash. At least in Chrome this does no cause a reload (as far as I can tell from looking at the network tab). Since the hash is now a part of the url it should be sent along when the redirect fires. Then you need a script on the receiving page that checks the hash for a clientID and passes it to analytics if present.

2) Basically the same, only this time with the pushState method (https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Manipulating_the_browser_history) which should allow you to provide the query parameter without reload.

3) Make the variation page a page within your main domain. Instead of any content put a javascscript there that reads the clientId from the cookie and redirects to the other domain

4) Same as 3, only serverside (don't forget to include the content experiment parameter in the redirect)

As I've said this is basically thinking aloud but it might provide clues toward a solution.