{"id":124,"date":"2007-10-25T21:34:50","date_gmt":"2007-10-25T18:34:50","guid":{"rendered":"https:\/\/www.optimiced.com\/en\/2007\/10\/25\/two-or-more-google-analytics-in-one-page\/"},"modified":"2007-11-08T16:00:29","modified_gmt":"2007-11-08T14:00:29","slug":"two-or-more-google-analytics-in-one-page","status":"publish","type":"post","link":"https:\/\/www.optimiced.com\/en\/2007\/10\/25\/two-or-more-google-analytics-in-one-page\/","title":{"rendered":"Two or more Google Analytics accounts in one page: How-to"},"content":{"rendered":"<p>Yes, it is possible.<\/p>\n<p>No, it won&#8217;t work with a simple &#8220;copy-paste&#8221; of the two Google Analytics codes.<\/p>\n<p>Read on, if you want to know the solution which I discovered by experimenting! :-)<\/p>\n<p>* * *<\/p>\n<p>Not a long ago I had to play a lot with GoogleAnalytics. I had also the idea of creating one GoogleAnalytics profile for the whole domain, and separate profiles for some of the sections in the website. Thus the statistics for the whole website and its sections could be tracked in an easier way, like if you were watching the statistics for separate websites, while having at the same time an overall look at the traffic for the whole domain. (I believe there are other means of achieving the same goal with GA, but for me the method above was the easiest to implement.)<\/p>\n<p>So, I&#8217;ve created separate profiles in Google Analytics (one profile for the whole website and several others for the site sections), copied the HTML codes from GoogleAnalytics on each page, and waited for the results. 24 hours later I discovered that:<\/p>\n<p>1) The first (for the whole domain) GoogleAnalytics profile works and gathers data <em>(the code for it was always first in the html code in the pages)<\/em>.<br \/>\n2) The GA profiles for each section do not work (they show zero traffic), notwithstanding the fact that Google Analytics claims that the GA code is inserted correctly and works <em>(the code for each site section was always after the general profile code)<\/em>.<\/p>\n<p>The things at this moment looked like this:<\/p>\n<pre><code>&lt;!-- GoogleAnalytics code for the whole domain --&gt;\r\n&lt;script src=\"http:\/\/www.google-analytics.com\/urchin.js\" type=\"text\/javascript\"&gt;\r\n&lt;\/script&gt;\r\n&lt;script type=\"text\/javascript\"&gt;\r\n_uacct = \"UA-XXXXXXX-X\";\r\nurchinTracker();\r\n&lt;\/script&gt;\r\n&lt;!-- GoogleAnalytics code for a specific site section --&gt;\r\n&lt;script src=\"http:\/\/www.google-analytics.com\/urchin.js\" type=\"text\/javascript\"&gt;\r\n&lt;\/script&gt;\r\n&lt;script type=\"text\/javascript\"&gt;\r\n_uacct = \"UA-XXXXXXX-X\";\r\nurchinTracker();\r\n&lt;\/script&gt;<\/code><\/pre>\n<p>Copy-pasting the GA codes one after the other didn&#8217;t work&#8230; After some research and googling around, I&#8217;ve found the <a href=\"http:\/\/groups.google.com\/group\/analytics-help-basics\/browse_thread\/thread\/3e2ccb1622d0c6d0\/bc23b655ad023a92?lnk=gst&#038;q=_uff&amp;amp;amp;amp;amp;amp;rnum=1#bc23b655ad023a92&#038;utm_id=bl\">following solution<\/a>:<\/p>\n<p><!--more--><\/p>\n<p>First, insert the HTML code for the first Google Analytics profile. Then add: <\/p>\n<pre><code>_uff = false; \/\/ Reset for second account<\/code><\/pre>\n<p>And after that, add the code for the next profile. If you must have more than 2 profiles in one page, simply repeat.<\/p>\n<p>In my case, when I needed two Google Analytics profiles in one page, the whole code looked like this:<\/p>\n<pre><code>&lt;!-- GoogleAnalytics code --&gt;\r\n&lt;script src=\"http:\/\/www.google-analytics.com\/urchin.js\" type=\"text\/javascript\"&gt;\r\n&lt;\/script&gt;\r\n&lt;script type=\"text\/javascript\"&gt;\r\n_uacct = \"UA-XXXXXXX-X\"; \/\/ GoogleAnalytics code for the whole domain\r\n(typeof(urchinTracker) == \"function\") urchinTracker();\r\n_uff = false; \/\/ Reset for second account\r\n_uacct = \"UA-XXXXXXX-X\"; \/\/ GoogleAnalytics code for a specific site section\r\nif (typeof(urchinTracker) == \"function\") urchinTracker();\r\n&lt;\/script&gt;<\/code><\/pre>\n<p>There is also a simplified version of the above code. You might have noticed that I used: <code>if (typeof(urchinTracker) == \"function\") urchinTracker();<\/code> (instead of <code>urchinTracker();<\/code>) &#8212; the reason was because it was recommended to do so <em>(some kinds of ad-blocking software block the loading of the <code>urchin.js<\/code> file, and then <code>urchinTracker<\/code> becomes an undefined function in JavaScript and throws an error, so first a check is made, and only if <code>urchinTracker<\/code> exists, it is called)<\/em>.<\/p>\n<p>&#8230;So let&#8217;s go back to out shorter version of the above example. Here it is:<\/p>\n<pre><code>&lt;!-- GoogleAnalytics code --&gt;\r\n&lt;script src=\"http:\/\/www.google-analytics.com\/urchin.js\" type=\"text\/javascript\"&gt;\r\n&lt;\/script&gt;\r\n&lt;script type=\"text\/javascript\"&gt;\r\n_uacct = \"UA-XXXXXXX-X\"; \/\/ GoogleAnalytics code for the whole domain\r\nurchinTracker();\r\n_uff = 0; \/\/ Reset for second account \r\n_uacct = \"UA-XXXXXXX-X\"; \/\/ GoogleAnalytics code for a specific site section\r\nurchinTracker();\r\n&lt;\/script&gt;<\/code><\/pre>\n<p>Both (longer and shorter version) do exactly the same thing, just the first variant is believed to be more bulletproof than the second one:)<\/p>\n<p>I&#8217;ve tested everything, now all Google Analytics counters work normally, all profiles gather data and now I have detailed statistics for the whole domain and separate GA profiles for the sections in the website.<\/p>\n<p>Hope these short <em>GoogleAnalytics tips &#038; tricks<\/em> will be useful for other enthusiasts, too, decided to &#8216;hack&#8217; into the code of GA for their specific needs:)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Yes, it is possible. No, it won&#8217;t work with a simple &#8220;copy-paste&#8221; of the two Google Analytics codes. Read on, if you want to know the solution which I discovered by experimenting! :-) * * * Not a long ago I had to play a lot with GoogleAnalytics. I had also the idea of creating&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[36,16],"tags":[],"class_list":["post-124","post","type-post","status-publish","format-standard","hentry","category-web","category-webdesign"],"_links":{"self":[{"href":"https:\/\/www.optimiced.com\/en\/wp-json\/wp\/v2\/posts\/124","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.optimiced.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.optimiced.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.optimiced.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.optimiced.com\/en\/wp-json\/wp\/v2\/comments?post=124"}],"version-history":[{"count":1,"href":"https:\/\/www.optimiced.com\/en\/wp-json\/wp\/v2\/posts\/124\/revisions"}],"predecessor-version":[{"id":1508,"href":"https:\/\/www.optimiced.com\/en\/wp-json\/wp\/v2\/posts\/124\/revisions\/1508"}],"wp:attachment":[{"href":"https:\/\/www.optimiced.com\/en\/wp-json\/wp\/v2\/media?parent=124"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.optimiced.com\/en\/wp-json\/wp\/v2\/categories?post=124"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.optimiced.com\/en\/wp-json\/wp\/v2\/tags?post=124"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}