Multiple Google Analytics Tracking Codes on one Page
published Nov 11, 2011
Say I want to make it so that Leanpub authors can get Google Analytics information about visits to their page while still sending the info to our Leanpub analytics account. This is pretty easy to do, but finding out how took me a bit of googling.
Your google analytics script for a normal, single tracking code looks something like this:
That’s all fine and dandy, but what if you want to have two codes in there?
Turns out it’s pretty simple. You add another set of _gaq.push lines, right after the current ones and before (function() {. Something like this:
The account2 part can be anything you want. In fact, you can stick in a bunch of them if you want, resulting in something like this: