0
votes

I recently updated one of my web site's Google Analytics tracking codes to the latest (asynchronous) version. Ever since doing so, it's not tracking links correctly. All links are coming through as being a referral rather than having the Analytics utm paramters (i.e. keyword, source, campaign, etc.) that I specified in the incoming links.

I also added the Google Custom Search Engine onto the site. Here's a sample (using fake account number, etc.) of what code is right before the closing head tag on the page (the Analytics and CSE codes):

 <script type="text/javascript">

   var _gaq = _gaq || [];
   _gaq.push(['_setAccount', 'UA-XXXXXXXXX-X']);
   _gaq.push(['_setDomainName', 'sitedomain.com']);
   _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);
   })();

 </script>
 <script type="text/javascript">
   (function() {
     var cx = '0000000000000000:aksjfhkjw';
     var gcse = document.createElement('script'); gcse.type = 'text/javascript'; gcse.async = true;
     gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
         '//www.google.com/cse/cse.js?cx=' + cx;
     var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(gcse, s);
   })();
 </script>

Is there anything wrong with the above? For example, was I supposed to modify the regular Analytics script in any way since I have the cse on the same page?

Thanks for any help!

1

1 Answers

0
votes

I dont think your code looks right.

Here is what I am using for the Google Analytics code:

    <script type="text/javascript">

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

    </script>

I dont have the site search on our domain but this is certainly enough to get the data into GA. It may be that your _gaq.push(['_setDomainName', 'sitedomain.com']); is being read as a referral. Give it a try and let me know.