Two Google Analytics Accounts, One Website

Google Analytics LogoImagine you have two Google Analytics accounts, and you don’t wish to share profiles. Recently we came across this situation. We also learnt having two copies of the Google Analytics code on a page will not work. Eventually we stumbled onto a simple solution with the code below:

<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 firstTracker = _gat._getTracker("UA-XXXXX-1x");
    firstTracker._initData();
    firstTracker._trackPageview();
    var secondTracker = _gat._getTracker("UA-XXXXX-2x");
    secondTracker._initData();
    secondTracker._trackPageview();
</script>

Make sure your firstTracker and secondTracker are in a separate <script> tag from the the first part (with the document.write). Replace UA-XXXXX-1x and UA-XXXXX-2x with the two accounts to have data sent to. Voila, a simple solution–hope we saved you some time!

Print This Post Print This Post
Sunday, December 13th, 2009 at 20:38
No comments yet.

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>