Install Multiple Tracking Codes for Google Analytics on a Drupal Site

At the Strong, we have 6 separate Drupal sites in a Multisite installation. Before that, we had 3 websites. We have been using Google Analytics for the past few years to track data, especially since the inception of the American Journal of Play in July 2008 and ICHEG in March 2009. Each site had its own profile and tracking code.

Now that we have 6 websites, maintaining 6 profiles in Google Analytics is a bit cumbersome. What if we want to see total visitation for all sites? We have to manually add the 6 values together.

In an ideal world, we should have one master profile, and 6 sub-profiles.

One tracking code can be used in this way and is in fact recommended by Google. You can set up filters in different profiles to display the domain name, and then filter only that domain in a sub-profile. But we would have to start over with a new tracking code, and we have a few years of historical data that we don't want to lose.

What about using two tracking codes? Although it's not recommended (see also this post and this one), it is possible..

There is a post explaining how to do it here, and it appears there are no major problems. But there's no instructions for the new asynchronous Javascript code...

Multiple Tracking Codes with Asynchronous GA Code

The new Google code uses a function called _gaq.push() to queue requests sent to Google. So, essentially, you just need to queue up two blocks of code. Here's the code I found that works:

var _gaq = _gaq || [];

_gaq.push(["_setAccount", "UA-XXXXXXX-1"]);
_gaq.push(["_setDomainName", "none"]);
_gaq.push(["_setAllowLinker", true]);

_gaq.push(["_setAccount", "UA-XXXXXXX-2"]);
_gaq.push(["_setDomainName", "none"]);
_gaq.push(["_setAllowLinker", true]);

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

_gaq.push(["_setAccount", "UA-XXXXXXX-1"]); sets the account to the first profile. _setDomainName and _setAllowLinker are suggested to add in this post and are the asynchronous equivalents of that post's code.

These 3 lines are queued but are not sent to Google just yet. _gaq.push(["_trackPageview"]); sends the request, and clears the queue. That's why we can start with _setAccount again and queue up settings. Then the final _trackPageview sends the second bit of code.

Multiple Tracking Codes in Drupal with Google Analytics Module

If you're using Google Analytics with Drupal, you're probably using the Google Analytics module. So, how do we add this code in the settings?

Note: These instructions are for Google Analytics 6.x-3.0.

First, go to Administer -> Site Configuration -> Google Analytics.

Advanced settings

All the way at the bottom, expand Advanced settings.

Custom Javascript code

Then expand Custom Javascript code.

Code snippet (before) and (after)

So, what to add? What's not clear here is that the Google Analytics module automatically adds two lines of _gaq.push() calls to the tracking code, and doesn't allow you to edit them. So, the information put in Code snippet (before) and Code snippet (after) would be output like so on the page:

_gaq.push(["_setAccount", "UA-XXXXXXX-1"]);
 * code snippet before
 * code snippet after

Where UA-XXXXXXX-1 is your first account profile ID, and the value of Web Property ID that you filled out at the top of the settings form.

So to recreate the multiple tracking code in Drupal, we would fill the before and after like so:


_gaq.push(["_setDomainName", "none"]);
_gaq.push(["_setAllowLinker", true]);


_gaq.push(["_setAccount", "UA-XXXXXXX-2"]);
_gaq.push(["_setDomainName", "none"]);
_gaq.push(["_setAllowLinker', true]);

Where UA-XXXXXXX-2 is the second account profile ID. So the Settings form would appear like so:

Correct settings

And there you have it! I've confirmed that this works for our sites.

In theory, you could put 3 tracking codes if you wanted; just repeat the four lines in the "After" snippet again with the third profile ID for _setAccount, but I wouldn't recommend that.

Hope this helps someone out there!


Andy's picture

Yes, quite helpful! Thanks very much.

Visit here's picture

I recently came across your Internet Slang blog and have been reading along. I thought I would leave my first comment. I don’t know what to say except that I have enjoyed reading. Nice blog, I will keep visiting this blog very often. Visit here

Unique Hoodia's picture

Thanks for taking this opportunity to discuss this; I appreciate with this and if you have some more information please share it with me about Dermal Piercing.
visit here

metal carport kits's picture

Investigating in Yahoo I finally uncovered this site. Looking at this data so I'm euphoric to pass on that I have a breathtakingly respectable uncanny feeling I found fundamentally what I required. Thank Emergency Dentist. visit here's picture

I know this is kinda off topic but I was wondering which blog platform are you using for this website? I'm getting fed up of Wordpress because I've had issues with hackers and I'm looking at alternatives for another platform.'s picture

Most people will never allow its children so that you can toil hard for their higher instruction programs plus deny these folks recognition. It can be wrong to try this as your parent. The most wonderful thing you is capable of doing is to organize for an effective graduation ceremony for your personal child.

metal carport kits's picture

These sorts' rentals are typically readily set at contrivances that surely are focused through fine-looking shores offering totally clear waters, probability the Pacific Ocean. Lodgings packs you completed several fine centres there. Thank Metal Carports.

Pocket Knife Guides's picture

I'm looking forward for your next post, I will try to get the hang of it!

wallens's picture

Nice to read your article! I am looking forward to sharing your adventures and experiences.
cheat pou
hill climb racing cheat

Quonset Hut's picture

certainly like what you are stating and the way in which you say it. You make it entertaining and you still care for to keep it sensible. I can not wait to read much more from you. This is actually a tremendous site.

official website's picture

Resulting from our present day living standard we're also creating trap for the next generating; that is the pollution we're also also entering into to eradicate forest to set-up forest with concrete. Plus;

wallens's picture

Thank you for such a well written article. It’s full of insightful information and entertaining descriptions. Your point of view is the best among many.
health news

Official website's picture

A fantastic web page about Online Advertising campaign always comes-up using new and exciting information and even though analyzing I have think this webpage is absolutely have all those fantastic which can be qualified a webpage to become fantastic one.
Official website

Unique Hoodia's picture

Additionally all you give to us is update and genuinely informative, an obligation of appreciation is in place with respect to advertising.'s picture

Once we tend to apprehend, fashion are sometimes terribly tough which you can follow. In a strong trade when one colouring, material and also pattern are sometimes insanely hot one minute and wholly out right after, there's minimal doubt this maintaining isn't an straight send task. To not ever worry, we're here that may help you type by all the latest fashion news flash and fads and continue to keep you making an attempt stylish.

wallens's picture

Thanks for another wonderful post. Where else could anybody get that type of info in such an ideal way of writing?
buy twitter followers uk

james's picture

Some truly wonderful work on behalf of the owner of this internet site , perfectly great articles . clash of clans hack | hill climb racing

official website's picture

This content you could have published includes huge concept came into existence effective. Hi, very first I've got to declare Tinnitus articles with this weblog have become useful to see.

Unique Hoodia's picture

I think the way you create has a yearning for having so much vitality and you have set it in a way that everyone can get it. Must respect the uncommon posts you have formed here about Godaddy Promo Code article.'s picture

When you are within design, you could very well can find this everyone in the world enjoys Design Week enjoy it is Year. You're visiting comprehend why they should holiday over their own base looking for ways to some front-row Harley hold and ogling from the extremely decisions.

buy facebook fans's picture

I am very impressed with the information you are posting here. Thanks for sharing and tell us extra about new releases. Thanks for taking the time to share about Social Media Agency and this valuable analysis with everyone buy facebook fans's picture

Fashion allows us to know quite a lot around your someone, exactly how that they enable, that people place its attire around concert suggests any person they are actually each working day. Possibly even folks who claim to not ever ever learn about see happy exactly how that people feel having said that show an account concerning who they are really as perfectly as whatever we play the role of.

Click Here's picture

Thanks for sharing nice information about Tinnitus article with us. i like your post and all you share with us is update and quite informative, thanks for sharing. Click Here

Click Here's picture

This is really a great read for me. Thank you for publishing articles having a great insight stimulates me to check more often for new write about Acne No More Review. Visit Website

Click here's picture

Good data, thank you to McDougal. It's incomprehensible if you ask me now, in general, the meaning and performance is frustrating. Thanks again for nice information about Ben 10 Ultimate Alien and best of luck. Click here

Click here's picture

You have opened my eyes to varying views on this topic with interesting and solid content.
The new Zune browser is surprisingly good, but not as good as the iPod’s. Click here

Click here's picture

Think about adjusting your own believed process and giving others who may read this the benefit of the doubt. find more information

<a href="">Visit here</a>'s picture

I just couldn’t depart your site prior to suggesting that I extremely enjoyed the bluehost coupon standard information an individual provide for your visitors? Is gonna be back frequently in order to inspect new posts hey there, your site is cheap. Visit here

<a href="">Visit here</a>'s picture

Hitting some of those will probably center on in which piece Previous Institution New Body, as well as yet another group of “neighbors” should come into view, enabling you to understand close to researching by comparable artists, tunes, or perhaps users.

<a href="">Visit here</a>'s picture

Your amazing insightful information entails much to me and especially to my peers. Thanks Tinnitus Miracle; from all of us.
Tinnitus Miracle Scam

Yeast Infection's picture

I just found ones Candidiasis blog site and have absolutely been reading along. When i believed I might get away from the primary opinion. When i don’t determine what to state other than that we have got relished reading. Good blog site, I am going to hold viewing this site usually.
Yeast Infection

Acne No More's picture

I wish to say that this post is amazing about Acne No More, nice written and include approximately all important info. Glad to found this post. I would like to see more posts like this. Salute. Acne No More

Fat Loss Factor review's picture

I discovered the information really valuable about Fat loss Element. Thank you intended for discussing this excellent info. I seemed to be on the lookout for this kind of essential info considering that very long time.
Fat Loss Factor review

Unique Hoodia's picture

I beginning late headed before long your online journal about Unique Hoodia and have been looking at along. I thought I would leave my first remark. I don't see what to say aside from that I have had a surprising time asking about. Better than ordinary site. I will continue taking off to this online journal frequently. Unique Hoodia

Click Here's picture

Your amazing insightful information entails much to me and especially to my peers. Thanks a ton; from all of us.'s picture

Remaining happy is a desire of each one person. People plan different times where people gather so that you can celebrate its lives plus share its life experiences utilizing their friends. Together with the plentiful cases of stressful events,

Click Here's picture

Thanks for writing engaging and interesting material.Found this on MSN and I’m happy I did. Well written article.

christmas desktop backgrounds's picture

You completed a number of nice points there. I did a search on the issue and found nearly all people will have the same opinion with your blog.

Click Here's picture

hi!,I like your writing so much! share we keep up a correspondence extra approximately your post on AOL? I require a specialist on this space to solve my problem. May be that is you! Looking ahead to peer you.Click here

visit here's picture

I ran across your site last week and started to follow your posts consistently. I haven’t commented on any kind of blog site just yet but I was considering to start soon. It’s truly exciting to actually contribute to an article even if it’s only a blog. I really don’t know exactly what to write other than I really loved reading through a couple of of your articles. Great articles for sure. I will keep visiting your blog regularly. I learned a lot from you. Thanks!

wallensasd's picture

Superbly written article, if only all bloggers offered the same content as you, the internet would be a far better place..
buying followers on instagram

wallensasd's picture

Admiring the time and effort you put into your blog and detailed information you offer!..
buy instagram comments

how to get lots of followers on instagram's picture

Wonderful illustrated information. I thank you about that. No doubt it will be very useful for my future projects. Would like to see some other posts on the same subject!

get youtube subscribers's picture

This is a great inspiring article.I am pretty much pleased with your good work.You put really very helpful information...

youtube bots

learn more's picture

No doubt this is an excellent post I got a lot of knowledge after reading good luck. Theme of blog is excellent there is almost everything to read, Brilliant post.

wjones's picture

Thanks Andy, I'm glad it was helpful! I was hoping to fill some gaps on on the Interwebs.

Attila Hooper's picture

Yep, the code works on my multisite. Just waiting for google to aggregate the data.

Thx Wes

Oprah Day's picture

Wow. That's the result i couldn't even expect. Surprised it is as easy. Thanks.

Julius Rainey, Jr.'s picture

I know that this is an old blog based on the Google Analytics module 6.x-3.0. The current Drupal site I have is using Google Analytics module 7.x -1.2. Can someone help me understand/how to track two different websites with a multi-site installation?

daniel's picture

I never knew about main profile and sub profiles of website. But is it safe?


Add new comment