Two analytics on one page - google-analytics

How can i put two GA codes on a site. I have this code:
(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-55738390-2', 'auto');
ga('create', 'UA-55738390-3', 'auto');
ga('send', 'pageview');
But the 2nd analytics code is not working. How can i fix this?

Your second tracker is overriding the first. It's not per se a problem to have multiple trackers per website, but you need multiple pageview (or other interaction) calls as well. Best way to do this is to use named trackers:
ga('create', 'UA-XXXX-Y', 'auto', 'tracker1');
ga('tracker1.send', 'pageview');
ga('create', 'UA-XXXX-Y', 'auto', 'tracker2');
ga('tracker2.send', 'pageview');
That way you can make interactions calls to specific trackers by prefixing the tracker name to the send method call.

Related

Appending google Analytics tracking code to existing GA code

i have the following GA code added to my website
<script>
(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-67265472-1', 'auto');
ga('send', 'pageview');
</script>
I created a different property to filter my own ip address from being tracked in Google analytics. The only difference in the tracking code is the below
ga('create', 'UA-67265472-2', 'auto');
Can i simply append this code to the end of the existing GA code or would i need to copy the entire new tracking code into the webpage.
Thanks in advance for your replies
You do not need to include the part that loads the analytics.js file multile times.
However if you simply call create with a different account id a second time you will overwrite the existing tracker and all call will be logged to the second account id.
If you need multiple trackers per page you need to create a named tracker, and send a second pageview call (and events etc.) there:
ga('create', 'UA-67265472-2', 'auto' , 'myTrackerName');
ga('myTrackerName.send', 'pageview');
You can this after your existing code:
<script>
(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');
// default tracker
ga('create', 'UA-67265472-1', 'auto');
ga('send', 'pageview');
// custom name
ga('create', 'UA-67265472-2', 'auto' , 'myTrackerName');
ga('myTrackerName.send', 'pageview');
</script>
To add to the contribution of Eike Pierstorff. When using multiple trackers, it is recommended to start using Google Tag Manager. This will make tracking with multiple trackers much easier.
Especially when you want to track events, custom dimensions, virtual pageviews, ecommerce, etc.

Two Google Analtyics profiles in same same tracking script not working

We have two profiles that we are tracking for the same site and only one account is working.
Getting the following error in the second GA profile, but I've confirmed code is correct:
Property http://www.ourwebsite.com is not receiving hits. Either your
site is not receiving any sessions or it is not tagged correctly.
Is there anything wrong with this?
Here's the following code I'm using:
<script>
(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-########-1', 'auto');
ga('create', 'UA-########-1', 'auto', {'name': 'newTracker'});
ga('send', 'pageview');
ga('newTracker.send', 'pageview');
</script>

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

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>
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.

google analytics data is not showing up - Tracking not installed

I have a problem with google analytics for web.
I installed the analytics as following just before the closing head tag.
<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-xxxx23-1', 'auto');
ga('create', 'UA-xxxx56-2', 'auto');
ga('send', 'pageview');
</script>
It is weird because on one UA code (the one that is uncommented) no data is coming through ans the status of the tracking code is "tracker is not installed".
While the other property on another account the data is coming in correctly and the status is "Receiving data".
Any idea what this problem might be?
Turns out it was a time issue. The settings took around a day to kick in. The weird thing was that no realtime data was coming through. But now it works. If anyone has the same problem, just be patient.
If you are using multiple tracking ID then you have to pass the name field as the fourth argument in the create command.
ga('create', 'UA-XXXXX-Y', 'auto', 'myTracker');
And then you have to prefix the command name with the tracker name, followed by a dot.
ga('myTracker.send', 'pageview');
finally your code will look like this with double tracker
(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','https://www.google-
analytics.com/analytics.js','ga');
ga('create', 'UA-xxxxxxxx-1', 'auto');
ga('create', 'UA-xxxxxxxx-1', 'auto', 'clientTracker');
ga('send', 'pageview');
ga('clientTracker.send', 'pageview');

Use Hastag # in Google Analytics New analytics.js tracking code

I am using the new Google Analytics code (below) and need it to be able to track # URLs. I can do it in the old tracking code but am unshure of how to do it in this new code. Ideally I would love to be able to stick the tracking code into the header of all pages without modification and have it grab the # from the URL. Any help would be greatly appreciated. I have check out this page https://developers.google.com/analytics/devguides/collection/analyticsjs/pages but am still unsure of exactly how to do what I want.
(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-2433430-6', 'mydomain.org');
ga('require', 'linkid', 'linkid.js');
ga('send', 'pageview');
ga('create', 'UA-XXXX-Y', {'allowAnchor': false});
from here : https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#allowAnchor

Resources