Google Analytics with two property ID's: double counting page views?

1.7k views Asked by At

I've always used one Javascript GA tracking script on my page, for www.example.com version of my website. It used the property ID UA-XXXXXX-1. However, I read somewhere that pages viewed on your example.com domain (without www.) won't get tracked properly this way. So I added a second property, without the www. It had the property ID UA-XXXXXX-14.

Now, I'm seeing a significant rise in my page views (more than double, actually) for the stats of my UA-XXXXXX-1 property, but not in my sessions. Does this mean that Google Analytics is tracking page views twice? And if so, how is this possible, since I'm just looking at the stats for UA-XXXXXX-1?

EDIT: This is the code I'm using:

<script type="text/javascript">
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-XXXXXX-1', 'auto');
  ga('send', 'pageview');

</script>
<script type="text/javascript">
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-XXXXXX-14', 'auto');
  ga('send', 'pageview');

</script>
1

There are 1 answers

4
Eike Pierstorff On BEST ANSWER

However, I read somewhere that pages viewed on your example.com domain (without www.) won't get tracked properly this way.

This is wrong. GA in its default configuration will track properly, even if www.example.com is technically a subdomain of example.com. Plus changing the domain in your account configuration will not actually affect data collection.

Does this mean that Google Analytics is tracking page views twice?

Yes, probably. However this is not related to tracking with to properties unless there is a problem with your configuration. Most likely you are accidentaly tracking twice to the same property.

If I had to take a wild guess I'd say you are doing this:

ga('create', 'UA-XXXXXX-2', 'auto');  
ga('create', 'UA-XXXXXX-1', 'auto');  
ga('send', 'pageview');  
ga('send', 'pageview'); 

when you should be doing this:

ga('create', 'UA-XXXXXX-1', 'auto');  
ga('send', 'pageview');  
ga('create', 'UA-XXXXXX-2', 'auto');  
ga('send', 'pageview'); 

i.e. to send the pageview before you create your second tracker (because the second one will overwrite the first).

Alternatively you could use named trackers:

 ga('create', ''UA-XXXXXX-1', 'auto', {'name': 'trackerOne'});
  ga('create', ''UA-XXXXXX-2', 'auto', {'name': 'trackerTwo'});
  ga('trackerOne.send', 'pageview'); 
  ga('trackerTwo.send', 'pageview'); 

Since the tracker objects are called by name you can be sure that your calls always go to the correct tracker, no matter in which order the code is called in your page.

However if that is the problem you should not see data in your second account. In that case you need to share your actual tracking code.