Linking secondary Google AdSense domain to Analytics

I have recently started exploring the new Google Analytics interface and realized how powerful the AdSense integration into Analytics was.  I wanted to integrate AdSense and Analytics on all my properties.

I had no problems setting up the primary domain, but noticed any secondary domain would not report the correct revenue.  It seems it a fraction of the total, but per site the actual percentage was pretty much the same.  After making a post on the Analytics support form and digging around I finally have found a solution that works.  It turns out I was only seeing the earnings for the first ad unit on the page.

This thread here fixed the issue for me.  I hesitated to even try this solution, as the post is from 2009.  After running out of options I implemented the fix they suggested and it worked great. Let me explain the issue and fix in more detail.

When you setup secondary domains in Analytics you are instructed to add this code to the top of the page:

<script type="text/javascript">
window.google_analytics_uacct = "UA-XXXXXXX-XX";

What this does is tell AdSense what your Analytics profile is in order to properly report the data. It appears that the variable window.google_analytics_uacct is only applied to the first AdSense ad unit on the page, and after that it is reset.

The fix is to modify your every AdSense ad unit code on the page by adding the window.google_analytics_uacct = “UA-XXXXXXX-XX” code at the top. Here is an example of my ad unit:

<script type="text/javascript"><!--
window.google_analytics_uacct = "UA-XXXXXXX-XX";
google_ad_client = "ca-pub-XXXXXXXXXXXXXXXX";
google_ad_slot = "XXXXXXXXXX";
google_ad_width = 300;
google_ad_height = 250;
<script type="text/javascript"

I’ve only tested this for a couple days, but everything seems to be working just fine.

I hope this helps anyone who is having issues as well.

Be Sociable, Share!
  1. #1 by Vijay on November 13, 2012 - 12:52 pm

    Is this fix still valid for multiple domains running adsense?

  2. #2 by steve on November 16, 2012 - 10:48 am

    Yes I have recently used this and it still works.

  3. #3 by stella on August 14, 2013 - 10:41 pm

    If I have 4 ads and I need to add this code 4 times. Will this slow the website speed? Thanks

Comments are closed.