Upcoming LunaMetrics Seminars
Washington DC, Sep 22-26 Boston, Oct 6-10 Chicago, Oct 20-24 Seattle, Nov 3-7

Pitfalls of Tracking to Multiple Accounts in Google Analytics





Tracking to multiple accounts? What’s that?

googleyticslogoWhen you create a GA account, you get an account number starting with “UA-” followed by a string of digits. When you put the GA Tracking Code on your pages you must specify what account you want it to send the data to by including this account number. If you want to send that data to multiple accounts you need to duplicate portions of the Tracking Code and include both account numbers:

<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”>
var pageTracker = _gat._getTracker(“UA-11111-1″);
pageTracker._trackPageview();

var otherTracker = _gat._getTracker(“UA-22222-1″);
otherTracker._trackPageview();
</script>

Async Version:

<script type=”text/javascript”>

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-11111-1']);
_gaq.push(['_trackPageview']);

_gaq.push(['_setAccount', 'UA-22222-1']);
_gaq.push(['_trackPageview']);

(function() {
var ga = document.createElement(‘script’); ga.type = ‘text/javascript’; ga.async = true;
ga.src = (‘https:’ == document.location.protocol ? ‘https://ssl’ : ‘http://www’) + ‘.google-analytics.com/ga.js’;
var s = document.getElementsByTagName(‘script’)[0]; s.parentNode.insertBefore(ga, s);
})();

</script>

Above we see two lines duplicated with different UA numbers. The data for the page that includes this code will be sent first to the account UA-11111-1 and then to the account UA-22222-1.

But when you do this there is the possibility that you may not get what you think you’ll get.

Using this method, the same cookies are used for both keeping tracking of information sent to both accounts. This opens the door for some potential problems.

1. Non-Identical Code

Some things you can do with the GA code can cause it to write cookies in different formats. If this happens GA can get a little confused. Okay, a lot confused. Here’s an example that will cause you you problems:

<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”>
var pageTracker = _gat._getTracker(“UA-11111-1″);
pageTracker._setAllowHash(false);
pageTracker._setAllowLinker(true);
pageTracker._trackPageview();

var otherTracker = _gat._getTracker(“UA-22222-1″);
otherTracker._trackPageview();
</script>

Async Version

<script type=”text/javascript”>

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-11111-1']);
_gaq.push(['_setAllowHash','false']);
_gaq.push(['_setAllowLinker','true']);
_gaq.push(['_trackPageview']);

_gaq.push(['_setAccount', 'UA-22222-1']);
_gaq.push(['_trackPageview']);

(function() {
var ga = document.createElement(‘script’); ga.type = ‘text/javascript’; ga.async = true;
ga.src = (‘https:’ == document.location.protocol ? ‘https://ssl’ : ‘http://www’) + ‘.google-analytics.com/ga.js’;
var s = document.getElementsByTagName(‘script’)[0]; s.parentNode.insertBefore(ga, s);
})();

</script>

In the above code, the first tracker includes the lines to allow for Cross-domain tracking in GA. This means that the first set of code will try to write cookies in one format, but the second set of code will try to use a different format.

Using Cross-domain tracking is fine, but you have to make sure that the code is the same for both trackers. If you do it in one, make sure you put the same lines into any additional trackers.

2. Different Pages

Another problem you can encounter is not having the Tracking Code on all the same pages. That is, some pages are tracked to both accounts, while others are only tracked to one account.

The problem here is, again, that the same cookies are being used. So, I view a page that is only tracked to Account A, and then view a page that is tracked to both Account A and Account B.  The Account B code will see the cookies that were originally created by a page that had No Account B tracking code. The first pageview recorded to Account B will have referral information created on a different page. It will think this is the second pageview, etc.

So, make sure the same code is on all the same pages for consistent tracking.

3. User Defined Segments

The User Defined Segment value is stored in a cookie (__utmv). Since both sets of code are using the same cookies, once you set a User Defined Segment for one, you’ve set it for the other as well. You can’t have one set of User Defined Segments for the first set of code, and another set of User Defined Segments for the second set of code.

For example, you can’t use the first set to keep track of Member/Non-member and the second set to keep track of Male/Female because they will overwrite each other.

<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”>
var pageTracker = _gat._getTracker(“UA-11111-1″);
pageTracker._setVar(‘Member’);
pageTracker._trackPageview();

var otherTracker = _gat._getTracker(“UA-22222-1″);
otherTracker._setVar(‘Male’);
otherTracker._trackPageview();
</script>

Async Version:

<script type=”text/javascript”>

var _gaq = _gaq || [];

_gaq.push(['_setAccount', 'UA-11111-1']);

_gaq.push(['_setVar','Member']);
_gaq.push(['_trackPageview']);

_gaq.push(['_setAccount', 'UA-22222-1']);

_gaq.push(['_setVar','Male']);

_gaq.push(['_trackPageview']);

(function() {
var ga = document.createElement(‘script’); ga.type = ‘text/javascript’; ga.async = true;
ga.src = (‘https:’ == document.location.protocol ? ‘https://ssl’ : ‘http://www’) + ‘.google-analytics.com/ga.js’;
var s = document.getElementsByTagName(‘script’)[0]; s.parentNode.insertBefore(ga, s);
})();

</script>

In this example, because of the way that GA handles _setVar, when the visitor comes back for a second visit he will be classified as “Male” in both accounts.

These are some of the most common issues I’ve seen when troubleshooting these types of implementations.  Hope this gives you some things to look out for, and if you have any questions, feel free to use the comments to ask.

John

http://www.lunametrics.com/blog/2009/02/26/pitfalls-tracking-multiple-accounts-ga/

32 Responses to “Pitfalls of Tracking to Multiple Accounts in Google Analytics”

DangerMouse says:

You mention in a previous post about benchmarking a way around these issues? Care to elabourate?

Is it possible to ensure each account uses an individual cookie?

John says:

Yes. I was planning on saving that for another post — this one was getting way too long.

There are ways to keep the cookies separate with _setDomainName(‘…’); and _setCookiePath(‘…’);

For example if you have the site http://www.domain.com

you can have one set of code that writes cookies with “www.domain.com” and another set of code that writes cookies with the domain “domain.com”

Of course, if your site is more complicated it can be harder to figure out a way to keep everything separate.

Also don’t forget to add an extra trackPageview call on the links you tagged manually. For example: if you added some tracking code to a print button it wil look like this: onclick=”pageTracker._trackPageview(‘print’); otherTracker._trackPageview(‘print’);”

open seo says:

Some good detailed info to look at about cookies
http://code.google.com/apis/analytics/docs/gaJSApiDomainDirectory.html

Mehdi says:

Hi John,

I’m Mehdi from Brussels, Belgium (do you remember the waw in Mountain view ;)

Thanks for your post, very interesting but I have a question:

Could we use the function setCookiePath to circumvent this issue?

example:

var pageTracker = _gat._getTracker(”UA-11111-1?);
pageTracker._setCookiePath(“/directory1/”);
pageTracker._setAllowHash(false);
pageTracker._setAllowLinker(true);
pageTracker._trackPageview();

var otherTracker = _gat._getTracker(”UA-22222-1?);
otherTracker._setCookiePath(“/directory2/”);
otherTracker._trackPageview();

What do you think?

John says:

Yes, that is exactly the approach I would use — force GA to keep separate cookies for each account. I’m just getting ready to post a follow-up on that topic, and noticed that your comment got caught by the wordpress spam plugin we use. (Sorry)

Richard says:

Hi,

I am suffering a similar issue which I would appreciate some help with if possible! I have 100 or so sites (location based) and up until now all of them have used seperate GA tracking. I would like to keep this but also add an extra page tracker that could be used for all pages on all sites. The code I have thought of using is along the lines of:

try {
var pageTracker = _gat._getTracker(“UA-####-1″);
pageTracker._trackPageview();
var otherTracker = _gat._getTracker(“UA-####-2″);
otherTracker._setDomainName(“none”);
otherTracker._setAllowLinker(true);
otherTracker._trackPageview();
} catch(err) {}

where UA-####-2 is the cross domain tracker.

Is this going to work? Is there anything else I need to do? I read somewhere that I may need to tag each and every cross domain link with a similar onclick event, but I can’t believe that is necessary?

Richard says:

Hi,

I posted in the previous thread to this, but as the discussion has moved on somewhat since then, I think my issue is probably more relevant here:

Hi,

I am suffering a similar issue which I would appreciate some help with if possible! I have 100 or so sites (location based) and up until now all of them have used seperate GA tracking. I would like to keep this but also add an extra page tracker that could be used for all pages on all sites. The sites heavily interlink, so conflicts in code are a big issue with implementation. The code I have thought of using is along the lines of:

try {
var pageTracker = _gat._getTracker(”UA-####-1?);
pageTracker._trackPageview();
var otherTracker = _gat._getTracker(”UA-####-2?);
otherTracker._setDomainName(”none”);
otherTracker._setAllowLinker(true);
otherTracker._trackPageview();
} catch(err) {}

where UA-####-2 is the cross domain tracker.

Is this going to work? Will I have the issue of the cookies? Is there anything else I need to do? I read somewhere that I may need to tag each and every cross domain link with a similar onclick event, but I can’t believe that is necessary? :O

John Henson says:

No, it won’t work.

Would a visitor typically move from siteX.com to siteY.com in order to accomplish their goals? Your goals?

Do the individual sites themselves have multiple subdomains?

Richard says:

(sorry to have this discusiion in two places)

“Would a visitor typically move from siteX.com to siteY.com in order to accomplish their goals? Your goals?”

Yes and Yes

“Do the individual sites themselves have multiple subdomains?”

No.

Steve says:

John,

Can you answer Richards Question.?

If his post from March 18th, 2009 at 8:28 am wont work, then what will?

John says:

Steve, This may do what Richard wants, but without seeing the site and the existing setup I really can’t be sure.

try {
var pageTracker = _gat._getTracker(”UA-####-1?);
pageTracker._setDomainName(”none”);
pageTracker._setAllowLinker(true);
pageTracker._trackPageview();
var otherTracker = _gat._getTracker(”UA-####-2?);
otherTracker._setDomainName(”none”);
otherTracker._setAllowLinker(true);
otherTracker._trackPageview();
} catch(err) {}

With this implementation you would need to call the _link method whenever moving from one site to the other. This method would use the same cookies for both accounts and may cause a slight change in the data from what he was using before.

Normally I don’t recommend setDomainName(“none”); but rather, i prefer to handle the domain of the cookie explicitly. In Richard’s case, I’m not sure it matters. Again, I’d have to see the site to know the best way to handle his goals.

Sorry that wasn’t of more help.

John

Lindsay says:

I have a client who has 4 urls pointing to a 5th url. Each has a GA account that are numbered consecutively, ex: UA-7xxx175-2, UA-7xxx175-3, UA-7xxx175-4, etc. GA is reporting approximately the same numbr of visits coming from the same referral sources, yet the referral source has a link to only one of the urls. Is there a way to fix this duplication error in reporting?

John says:

Hi Lindsay

I’m not sure I understand the question, but I’d probably not be able to answer it without looking at the sites and the pages and seeing what was happening inside the GA reports.

Sorry,

John

John Doe says:

Hello! I need to track traffic from different sources (SEO and context) on my site. 2 different seo companies are working with site. One deals with SEO, other works with context. So the statistics must be different.
I read here http://www.google.com/support/googleanalytics/bin/answer.py?hl=ru&answer=72298 that I can’t install 2 codes on my webpage, but it’s not almost clear, what does the author of this answer mean.

The Google Analytics won’t work if I install 2 identical tracking codes (f.e UA-111111-11 and UA-111111-11) on different parts of the site (f.e before and after ) or I install 2 tracking codes from my administrative account (account@gmail.com) from different profiles? (f.e, I create several accounts in my administrative account – acc1, acc2, acc3 and create the profile of my site there and get the code from there)

And if I will use 2 different administrative accounts, (f.e account@gmail.com and account1@gmail.com) and create the tracking codes there and install 2 different codes on the site – will I be able to track the Google Analytics statistics or not?

John says:

Do you want to track exactly the same pages of the site to two different accounts? And the Data would be exactly the same in both accounts? Yes, you can do this.

Just exactly duplicate your tracking code, but use a different UA-xxxxxx-y number (either the number for a new profile in the same account or the number for a new account that you create for this purpose.) and it will track to both accounts. You may need to change “pageTracker” to something else in the second set of code, for example, “secondTracker” for certain things to work properly, depending on your particular implementation.

Do not try to put the same UA-xxxxx-y number in both sets of code. That will not provide you with anything of value.

Mike says:

Hello,

I have a main domain with a calculation application (www.domain.com/calculate.aspx) and a number of subdomains (example.domain.com). Each subdomain has an iframe on it with a link to http://www.domain.com/calculate.aspx.

I want to measure for each subdomain separately the visits to that subdomain and also the visits to http://www.domain.com/calculate.aspx from that particular subdomain. i want to be able to determine the referrer to the subdomain that leads to the thankyou page on http://www.domain.com/calculate.aspx (the main domain).

What is the best way to this in GA?

Mike says:

I posted a reply and it disappeared. Why?

Mike says:

nevermind that last reply… i should be more patient…

John says:

Sometimes comments are caught by the built-in spam filter, when they shouldn’t be as well. We try to check the comments and publish the ones that are false positives, but we sometimes miss them, or just don’t get around to it as frequently as we should.

If you’re still not seeing your comment, just let us know and we’ll try to get it published.

John

Robbin says:

Mike, just due to the way you wrote it, it had to be manually approved. we don’t get many like that, and I do try to do it every day…. Robbin

John says:

Mike,

I don’t know if there is a “Best” way.

One way is to use

pageTracker._setDomainName(“domain.com”);

On all of your subdomains, tracking them all to the same GA profile.

Then set up a GA Goal for calculate.aspx.

Now you can tell where people who completed the goal *Originally* came from.

To tell which *Subdomain* they were on when they clicked, you can make each subdomain carry a different query parameter when it links to calculate.aspx

EXAMPLE:

on blue.domain.com Link to calculate.aspx?from=blue
on red.domain.com Link to calculate.aspx?from=red
on green.domain.com Link to calculate.aspx?from=green

That might not be the only way to do it, but it may be the most straightforward.

Mike says:

John,

Thanks for the advice. Seems to be working!

The thankyou page in the calculation is the fifth page in the calculation proces so i have to look into a way to give that page a queryparameter also (when visitors dive into the calculation it is the same for all the subdomains so i have to differentiate all the pages on the calculation to get a funnel for all the separate subdomains).

Thanks again!

grtz Mike
Eindhoven, The Netherlands

Christopher says:

I know this is an old article, but thought this might help.
_gaq.push(
['_setAccount', 'UA-XXXXX-1'],
['_trackPageview'],
['b._setAccount', 'UA-XXXXX-2'],
['b._trackPageview']
);

This was specified by google in there Api docs. http://code.google.com/apis/analytics/docs/tracking/asyncUsageGuide.html#MultipleCommands

searchengineman says:

Information on setting up 2 Google Analytics Accounts is extremely spotty at best, Try doing a search on Google. I don’t think anyone has ever written a comprehensive manual (How to), best practices or scenarios or How to on this issue?

You want link bait Lunametrics,
I can’t wait to read the article!
or I’ll write Rand Fishkin to write the article
Just kidding!

Searchengineman

I would like to know if I can translate this post http://www.lunametrics.com/blog/2009/02/26/pitfalls-tracking-multiple-accounts-ga/ to use in classes, lectures and events, always linking to you.

Thanks!
Lisane Andrade
@lisaneandrade

Stephen says:

I have a question about tracking the tracking code placed on my site. I can’t find the account it is attached to. I have tried signing in to a couple of google accounts that I created and still do not see any info. I have hired an SEO company and it may be possible that they put their own code in there. I can get into my site to see the code. How do I find out which google account it is leading back to? Thanks!!

Robbin Steif Robbin Steif says:

I am not sure there is a way. Even if you give the GA team the UA number, they say, “Sorry, you’re SOL.” Well, I guess they say it in nicer ways.

Why don’t you ask that SEO company? And if they say yes, you can decide if that’s the way to go (they have to measure, you may want them to have access to your own code, though.) And if they say no, you can always delete it and wait until someone complains… I know it isn’t the most elegant solution, but there aren’t great ways….

@Stephen -

Take the user account number (UA-123456) and search for it on http://spyonweb.com . It won’t show you information about the account itself, but you will be able to see if that same UA is being used on other sites. That might help you hunt down the owner.

Randall Glick says:

@Stephen – contacting google will work. Give them the account number and ask them to contact the admiistrative user of that account and have them contact you as the site owner. Google rep will usually include information on what you have to do to prove you have owenrship of that site (entails uploading an analytics.txt doc to the root of the site) and they will add your email address as an admin to the old account … of course you can always remove the old code and wait for whomever to contact you when they find out they no longer are receiving data, but that is a tactic that could lose several days data.

Mauro says:

I’m using multiple accounts on same pages in this way (website “sub1.domain.com”):
_gaq.push(
['_setAccount', 'UA-XXXXX-1'],
['_trackPageview'],
['b._setAccount', 'UA-XXXXX-2'],
['b._setDomainName', '.domain.com'],
['b._trackPageview']
);

In account ‘UA-XXXXX-1′ I created a profile A with NO filters
In account ‘UA-XXXXX-2′ I created a profile B filtered to include only hostname “sub1.domain.com”

I expect finding the same numbers in both profiles (visits, pageviews, …) but the profile B show always a difference of about 2% (less) for most numbers.

Why this difference?