Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I have multiple sites in my Google Analytics, and under the content section, adsense revenue per page is only visible for one of the sites. The rest of the sites in my Google analytics do not display what page the AdSense revenue came from.

Is this a known bug? Has anyone had this? Or do I need to configure something else?

Here is how I currently do this.

It is constructed as part of a php string, but the idea is the same. See the first 2 lines of this function. And the rest of the function displays traditional analytics snippet.

  $str = '';
    if($production === true)
    {
        $str.= '<script type="text/javascript">'."\n";

        $str.= 'window.google_analytics_uacct = "UA-9425856-20";'."\n";

        $str.= 'var _gaq = _gaq || [];'."\n";
        $str.= '_gaq.push(["_setAccount", "UA-9425856-20"]);'."\n";
        $str.= '_gaq.push(["_trackPageview"]);'."\n";

        $str.= '(function() {'."\n";
        $str.= ' var ga = document.createElement("script"); ga.type = "text/javascript"; ga.async = true;'."\n";
        $str.= ' ga.src = ("https:" == document.location.protocol ? "https://ssl" : "http://www") + ".google-analytics.com/ga.js";'."\n";
        $str.= ' var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(ga, s);'."\n";
        $str.= '})();'."\n";

        $str.= '</script>'."\n";
    }
    echo $str;
share|improve this question

migrated from stackoverflow.com Mar 4 '11 at 3:39

This question came from our site for professional and enthusiast programmers.

    
Does anyone know if this works. I am having trouble getting my adsense to register on all my analytic accounts. –  user6617 Apr 6 '11 at 11:04
    
@Adam I tried to implement the answer below, but it still does not work for me unfortunately. Anyone else? :) –  Genadinik Apr 17 '11 at 4:16
add comment

1 Answer 1

You need to add an additional snippet of code to your non-primary domains:

<script type="text/javascript">
 window.google_analytics_uacct = "UA-XXXXXX-X";
</script>

It needs to be placed above the other GA and AdSense code. The "UA-XXXXXX-X" should be replaced with the same GA account number used in the GA code.

share|improve this answer
    
@Ewan Unfortunately that didn't work. –  Genadinik Apr 17 '11 at 4:56
    
Can you post an example of the code you're using? –  Ewan Heming Apr 17 '11 at 12:38
    
@Ewan I just posted the snipped that is in my code. Thank you for following up :) –  Genadinik Apr 17 '11 at 16:45
    
Try splitting up your code and putting the window.google_analytics_uacct bit just below the opening <body> tag. Then put the GA tracking code right at the bottom of the page next to the closing </body> tag. I know that GA suggests putting it in the head section but it is possible to put at the bottom as well and is sometimes needed for the AdSense tracking to work. –  Ewan Heming Apr 18 '11 at 1:59
    
Did this change make any difference? –  Ewan Heming Apr 19 '11 at 20:28
show 6 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.