google-analyticsuniversal-analyticsgoogle-experimentsanalytics.js

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


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

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.


Solution

  • 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).