I am just looking for some help setting up a single view of all the sites we have. I can find lots of help for the old analytics tracking code but not for the new universal analytics.
I've got 5 sites each with their own tracking code in place but i'd like to create a roll up account that allows me to look at an overview of all the sites in a single view. Just wondering what i need to add to the code to do this?
It's currently;
<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-XXXX', 'auto');
ga('require', 'linkid', 'linkid.js');
ga('require', 'displayfeatures');
ga('send', 'pageview');
</script>
And I would just like to know what i need to add in to be able to include the numbers in a roll up account too? I think it's possible to simply edit this code with the UA of the roll up account but I'm not sure of the correct way to format this.
Any help would be appreciated,
Thanks
Roxi
It works rather like it did with asynchronous analytics, only you pass the name of the tracker in the (optional) configuration object:
ga('create', 'UA-XXXXX-X', {
'name': 'firstTracker',
});
ga('create', 'UA-XXXXX-Y', {
'name': 'secondTracker',
});
ga('firstTracker.send', 'pageview');
ga('secondTracker.send', 'pageview');
Any other options (e.g cookie domain, which is the third parameter if you don't use a configuration object) are set as key-value pairs in the configuration object. You find this in the documentation under Advanced Configuration.
Related
This is a two part question:
1) Is my new Google Analytics tracking code correct?
2) With the new code, I noticed a HUGE drop in reported sessions. Is this because the tracking code is more accurate or because my tracking code is wrong.
My Domains (example):
www.domain.org
abc.domain.org
cde.domain.org
www.domain.info
abc.domain.info
cde.domain.info
My OLD Google Analytics Tracking 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');
ga('create', 'UA-99999999-9', 'domain.org');
ga('send', 'pageview');
</script>
My NEW Google Analytics Tracking 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');
ga('create', 'UA-99999999-1', 'auto', {'allowLinker': true});
ga('require', 'linker');
ga('linker:autoLink', [/^domain\.(org|info)$/]);
</script>
Note: I see my second script doesn't have "ga('send', 'pageview');" could that be the reason for the HUGE drop in reported sessions?
Thanks in advance
Answer to your second question, a huge YES! If you don't have a pageview, then you don't have a way to indicate the start of a session.
Your setup looks correct - just might want to check to see if the auto-link domains accepts regex as I have a feeling it doesn't, ie.:
ga('linker:autoLink', [domain.org, domain.info]);
You might have to list them all out.
Don't forget to add your different domains to the referral exclusion list.
New code is better.
You have drop in number of sessions because now your sessions count in a right way.
Now if user jump from domain.org to domain.info it will be 1 session.
With old code it will be 2 sessions.
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.
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.
We have a site that has the same content but available under two domains. Is this is the right code to put on each page to split the domains in google analytics so we can see view the activity under each domain?
<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-1234-1' {'cookieDomain': 'domain1.com.au'});
ga('create', 'UA-1234-2' {'cookieDomain': 'domain2.co.nz'});
ga('send', 'pageview');
</script>
Thanks
According to https://developers.google.com/analytics/devguides/collection/analyticsjs/advanced (part Working with Multiple Tracking Objects) you should create a named tracker for the second property, like:
ga('create', 'UA-XXXX-Y', {'cookieDomain': 'domain1.com'});
ga('create', 'UA-12345-6', {'name': 'newTracker', 'cookieDomain': 'domain2.com'}); // New tracker.
and then send the page view for each tracker:
ga('send', 'pageview'); // Send page view for default tracker UA-XXXX-Y
ga('newTracker.send', 'pageview'); // Send page view for new tracker.
There's also other way how to track the same website with 2 domains by using just one property (UA-1234-1) and creating 2 views with each will include traffic only from given domain names (use predefined filter "Exclude/Include only traffic from the domains")
UPDATE
Thinking again about my answer, I must admit that even the original solution in answer
ga('create', 'UA-1234-1' {'cookieDomain': 'domain1.com.au'});
ga('create', 'UA-1234-2' {'cookieDomain': 'domain2.co.nz'});
will work, because if you try to create tracker 'UA-1234-1' on domain domain2.co.nz cookie will not be set (and vice versa creating 'UA-1234-2' on domain domain1.com.au). My solution is technically OK, but then you must take care about sending all pageviews, event trackings and other informations twice - for default tracker and also for named tracker.
Sorry if this is little confusing.
I am trying to embed a GA code in my website that is based on the new Universal Analytics method.
What I am trying to achieve is to send data to multiple properties from one page.
So I have checked the official GA documentation on the new universal GA code and specifically the section about "Working with multiple tracking objects".
https://developers.google.com/analytics/devguides/collection/analyticsjs/advanced#multipletrackers
But so far without success.
I have one domain for the standard website www.website.de
and another one for the mobile website de.website.mobi.
My GA code for my standard website looks like this:
(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-12345678-1');
ga('create', 'UA-12345678-2', {'name': 'newTracker'});
ga('send', 'pageview');
ga('newTracker.send', 'pageview');
In the GA real time section I can see that the property UA-12345678-1 is getting real time results but the the second property isn't getting results at all.
Does anybody know the reason? Am I mistunderstanding the GA documenation.
To clarify: On my mobile website I would like to embed the following 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-12345678-1');
ga('create', 'UA-12345678-3', {'name': 'newTracker'});
ga('send', 'pageview');
ga('newTracker.send', 'pageview');
So, I have three properties:
UA-12345678-2 for the standard website,
UA-12345678-3 for the mobile website
and UA-12345678-1 as an aggregation of both giving me the opportunity to see the results of standard website and mobile website summed up. At least that is what I am trying to achieve.
Any ideas are welcome.
What you have should work. I went and tested this myself, and sure enough, it didn't work. Next, I tried removing the spaces between the objects, as I've seen in the past that this has cause the code to not show up in GA. I'm not sure why, but by removing the spaces from all of the parameters and objects, I was able to get data to show up in real-time reports.
I tried adding the spaces back to the parameters and objects, but was unable to get the data to NOT show up again. Regardless of what I did, data kept coming through.
I would try this:
(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-12345678-1');
ga('create','UA-12345678-3',{'name':'newTracker'});
ga('send','pageview');
ga('newTracker.send','pageview');
I don't know if this helps, but I had been running into a wall for a solid two hours with the Universal Analytics and my named tracking object. Here's a code example for clarification that I had a hard time finding:
ga('create', 'UA-12345678-1', {
'cookieDomain': 'example.com',
'legacyCookieDomain': 'example.com',
'allowLinker': false}
);
ga('send', 'pageview');
ga('set', 'location', '/path/to/object/');
ga('create', 'UA-12345678-2', {
'cookieDomain': 'example.com',
'legacyCookieDomain': 'example.com',
'allowLinker': false,
'name': 'exampledomain'}
);
ga('exampledomain.send', 'pageview');
ga('exampledomain.set', 'location', '/path/to/object/');
Spaces had absolutely NOTHING to do with it. The problem I was running into was that I had a hyphen in my 'exampledomain' and it didn't work. Do not trust any odd characters in the string for the 'name' of any other tracking object!
Also, notice the 'name' key should be inside the opt_configObject. I say this because I found that documentation nowhere.