开发者

Using two separate accounts IDs for tracking

I have tracking code A on the main site www.example.com and tracking code B on www.example.com/blog which is a wordpress.com based blog (the site itself is plain PHP). Not surprisingly, traffic from the blog is not shown on the main site and visa versa.

I would like to use tracking code A on the blog as well to create a "roll-up" profile while maintaining the profile I currently have with tracking code B.

I thought that the right way to do it is 开发者_如何转开发using the following code:

<script>
  var _gaq = _gaq || [];
    _gaq.push(['_setAccount', 'UA-XXXXXX-1']);
    _gaq.push(['_trackPageview']);
    _gaq.push(['t2._setAccount', 'UA-XXXXXX-2']);
    _gaq.push(['t2._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);
    })();

but I read here: http://www.google.com/support/forum/p/Google%20Analytics/thread?tid=640080c650f67bd1&hl=en

that it causes a multiplication in visitor numbers and such.

What is the correct way to do this? Should I explicitly specify the domain and use the _setAllowLinker() method as described in the linked post above despite the fact that it's the same domain?

Any help will be much appreciated.

Thanks, Alexander

P.S

I read Google Analytics - async tracking with two accounts but I still don't have a definite answer.


The easiest way to achieve the results you're looking for is to use a single account/profile ID site wide and use profile filters to create a 'Blog Traffic Only' profile.

Sitewide you would call:

<script>
  var _gaq = _gaq || [];
    _gaq.push(['_setAccount', 'UA-XXXXXX-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);
    })();

Then, log in to Google Analytics, select your account (if you have more than one), add a new profile (for an existing domain) under the UA-XXXXXX-1 profile number, and call label it 'Blog Traffic'.

Once you create the profile, click to 'Edit' the profile you just created. Scroll to 'Filters Applied to Profile' and click 'Add Filter'. Google Analytics provides a pre-defined filter for traffic to a subdirectory (include only traffic to the subdirectories that are equal to '^/blog.*' or just '/blog').

Now, you'll have a profile that includes all traffic to your site and a second profile that includes traffic only to the blog subdirectory.

More information on using data filters: http://www.google.com/support/analytics/bin/answer.py?answer=55496

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜