zombiecode
zombiecode

Reputation: 325

Cross Domain Google Analytics Showing Multiple Users

I'm using analytics to track clicks and views, though due to the awkward setup (with iframes too) there's between 2 and 4 domains being used. I want to track each of them like they are one site.

I know you can set the linker to create links that transfer the cookie data from one domain to the other.

My problem: It's more likely that each of the domains that will loaded will be linked to from elsewhere, not within the site, so the linker will not work in the normal way. If I view both pages at one, it records me as two users as there's two cookies created.

The links that will take them to each of the possible urls I cannot control, so can't add a linker to.

Does anyone know how get analytics to show two domains on one account so that it doesnt count as two users?

This is the code I currently have (had a fair few versions)

(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-XXXXXXXX-X', 'auto', {'allowLinker': true});
ga('require', 'linker');
ga('linker:autoLink', ['url1', 'url2', 'url3']);
ga('send', 'pageview');

Thank you!!

ADDED:

Sorry it would be a little like this:

Website 1 - Main website www.mywebsite.com

Website 2 - Blog site www.blogs.com/myblog

These are two entirely separate websites, and you may get to either one independantly and not just links between.

With linking, you can allow links between to keep the same cookie, so it registers as one user within the same tracking code covering both sites.

What I would like is for it to register as one user when you hit the sites independently.

The setup doesn’t matter too much, so long as it’s using the same tracking code so that I can track clicks and views for both sites in one place…

I hope that makes sense…

Upvotes: 0

Views: 404

Answers (1)

zombiecode
zombiecode

Reputation: 325

I managed to get this working.. I couldn't get this working at all in the usual way, so instead I managed to use the User ID option.

Rather an generate a cookie based on the user / domain / browser etc as per default, you can set your own ID. This then allows you to track the same user over multiple devices and browsers, so long as you can assign the same ID to the user...

I chose to base a user ID on the IP address of the user like this:

$.get("http://ipinfo.io", function(response) {
    var myIp = "";
    if(typeof response.ip!='undefined'){myIp="ID"+response.ip;myIp = myIp.replace(/\./g, "");}

    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
    m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

    ga('create', 'UA-xxxxxxx-x', 'auto');
    ga('set', '&uid', myIp);
    ga('send', 'pageview');

}, "jsonp")

This seems to work perfectly so far, and tracks the same person on all sites even if they use more than one browser / mobile on the same network. The only flaw being multiple users on the same IP address, which for this is unlikely and not worth the worry for the odd rare occurrence..

Upvotes: 1

Related Questions