Tacking multiple domains using Google Analytics
If you have two or more domains / sites, it is a headache to track all of them using Google Analytics. Yes you can track 10 sites using 10 profiles, but you lost the whole picture. Here is how to track multiple domains using a single profile (so-called cross domains tracking).
Basically you have to do two tricks: a) modifying the google tracking js b)creating a custom filter to make the results more readable.
Let’s suppose you own two sites, www.orangecabin.com and www.google.com
Step 1 : Create profile
You have to decide which domain is the primary domain, and create a normal profile for it as usual. Since www.orangecabin.com is more important (I hope so), you use it. It really doesn’t matter which one you use.
Step 2 : Customize tracking js
Now google show you the tracking javascript you are supposed to add to your site. Copy the js, save it to a file and edit it to something like this:
<script type="text/javascript"> var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); </script> <script type="text/javascript"> try { var pageTracker = _gat._getTracker("UA-4966487-9"); // tracking multiple domains pageTracker._setDomainName("none"); pageTracker._setAllowLinker(true); pageTracker._setAllowHash(false); pageTracker._trackPageview(); } catch(err) {}</script>
These lines are added:
// tracking multiple domains pageTracker._setDomainName("none"); pageTracker._setAllowLinker(true); pageTracker._setAllowHash(false);
You will use this js instead of the original one.
Step 3 : Create a custom filter
The customized js is enough for google to collect information for all domains, but it won’t handle domain names correctly, www.google.com/index.html and www.orange.com/index.html will be reported as the same page. So you have to add a custom filter. If you don’t know what it is, don’t worry just follow me.
Return to the profile list, find the newly created profile and click edit
Find “Add Filter” on the new page
Click “Add Filter”, Create it using these parameters:
Filter Name: MultipleDomains
Filter Type: Custom filter > Advanced
Field A: Hostname
Extract A: (.*)
Field B: Request URI
Extract B: (.*)
Output To: Request URI
Constructor: /$A1$B1
as shown on this image:
Click save changes.
The next time you create another multiple-domain profile, you can reuse this filter instead of creating one.
step 4 add your customized js to your sites
That is it. Once you have enough data, you can get some report like this:
Very easy to implement and provides great help for further Google Analytics segmentation on the websites. Thanks
pageTracker._setDomainName(“none”);
So when we use the below mentioned code in case of multiple domain tracking
pageTracker._setDomainName(“.domain.com”);
If you have any idea please reply.
@Akash
Hi, sorry but I am not quite sure what you mean.
Using my code, you don’t need pageTracker._setDomainName(”.domain.com”);
This is great because it is so convenient, but looking at these three lines:
// tracking multiple domains
pageTracker._setDomainName(“none”);
pageTracker._setAllowLinker(true);
pageTracker._setAllowHash(false);
makes me think that if someone malicious were to “view source” on one of your tracked pages, copy your google analytics javascript from your page and put it in one of their pages, they could possibly “contaminate” your results. Is this true?