Name Spaced Accounts Not working Under Universal Analytics - google-analytics

I would like to migrate to universal analytics.js, however when I try to implement multiple accounts in the analytics.js snippet, the default account works great and shows up in Real Time, however the subsequent account never shows up on Real Time and traffic drops off to 0.
Currently I'm using ga.js to track multiple accounts in the single snippet. Here is the format I am using for that:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(
['_setAccount', 'UA-XXXXXXXX-2X'],
['_setDomainName', 'example.com'],
['_addIgnoredRef', 'example.com'],
['_trackPageview'],
['b._setAccount', 'UA-YYYYYYYY-2Y'],
['b._setDomainName', 'example.com'],
['b._addIgnoredRef', 'example.com'],
['b._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>
Below is the snippet I have been trying to make work with analytics.js
<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-XXXXXXXX-2X', 'example.com');
ga('send', 'pageview');
ga('create', 'UA-YYYYYYYY-2Y', {'name': 'rollup'});
ga('rollup.send', 'pageview');
</script>
The "rollup" name space never registers on the rollup account in real time. The UA-XXXXXXXX-2X code registers just fine in Real Time.
I have run Google Analytics Debugger and it appears to be creating both accounts and sending just fine with no errors only info that looks appropriate:
Running command: ga(create, UA-YYYYYYYY-2Y, [object Object])
Creating new tracker: rollup
Running command: ga(rollup.send, pageview)
Could anyone offer some guidance on what might be the problem with my analytics.js snippet?

Here is the Google Universal Analytics Code that merges two Profiles and even sends demographic data.
Just replace - UA-XXXXXX-Y with UA-XXXXXX-X with your GA tracking IDs.
and replace EXAMPLE.com with the website domain and all set to go.
FYI - OldSite - you can replace it with whatever you like - its just used separate profile for the GA to send captured data. so you can use SecondProfile, IloveCodes or whatever.
This script additionally sends demographics and other data - how cool is that?
Enjoy!
And Yes thanks to all the guys out there who helped me reaching out to this answer.
<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-XXXXXX-Y', 'EXAMPLE.com');
ga('create', 'UA-XXXXX-X', {'name':'Oldsite'});
ga('send', 'displayfeatures');
ga('Oldsite.send', 'displayfeatures');
ga('send', 'pageview');
ga('Oldsite.send', 'pageview');
</script>

If you are also experiencing this, ensure that all the accounts you are attempting to track have already been upgraded to Universal Analytics via the GA Admin menu. A face palm moment for me, but perhaps this reminder will help anyone else who may be experiencing the same issue.

Related

Migrating _setDomainName from Classic to Universal Google Analytics

I'm trying to figure out how to correctly migrate from Google's Classic Analytics to Universal Analytics, specifically regarding the _setDomainName property of Classic Analytics.
The site I'm doing this for has several sub-domains, and the current format of the Classic tracking code is what I've been using for years on all sub-domains of this site, as well as in the main (www) URL:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'TRACKING ID']);
_gaq.push(['_setDomainName', 'sitename.com']);
_gaq.push(['_trackPageview']);
(function () {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = 'https://ssl.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
The Universal tracking code has a default format of:
<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', 'TRACKING ID', 'auto');
ga('send', 'pageview');
</script>
I was reading somewhere that to handle the migration of the _setDomainName property I should replace the the following line in the Universal code:
ga('create', 'TRACKING ID', 'auto');
with
ga('create', 'TRACKING ID', 'auto', {'legacyCookieDomain': 'sitename.com'});
However, I came across something else that said to replace:
ga('create', 'TRACKING ID', 'auto');
with
ga('create', 'TRACKING ID', {
cookieDomain: 'sitename.com',
legacyCookieDomain: 'sitename.com'
});
I've seen other people saying that the Universal code doesn't require any code modifications to handle this.
Does anyone know for sure what I should do here? Thanks in advance for any help!
This
ga('create', 'TRACKING ID', 'auto', {'legacyCookieDomain': 'sitename.com'});
should work best for you if your intention is to continue tracking pre-migration visitors. It uses the "auto" cookie domain so that you can track across other subdomains, like whatever.sitename.com, and the "legacyCookieDomain" parameter which supports cookies that come from ga.js or urchin.js.
[Source: https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#legacyCookieDomain]
Setting the cookieDomain paremeter with a value of "sitename.com" is the same thing as setting the whole parameter to "auto".

Prevent /p/__utm.gif caused by Google Analytics

I am receiving a 404 error from my Google Analytics tracking code. The following is the code I am currently using in the footer of my page:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-X']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'ssl' : 'www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
The 404 error appears to be caused by: /p/__utm.gif
I was using the same JS code from this question: Google Analytics and the __utm.gif file. However, that didn't work with my last report from Goolge.
Is there other way to do it?
You are using an older tracking snippet from GA. You should update to the latest version as it should solve your problem. You should also ensure that this tracking code is on all of your pages on your site. The latest code snippet looks more like the following:
<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-XXXXXXX-X', 'auto');
ga('send', 'pageview');
</script>
You can get a formatted snippet for your site by:
logging into GA (Google Analytics)
Going to the admin UI by selecting the "Admin" tab at the top of the interface
If you have multiple accounts, ensure you have the correct account selected on the left (Account) column of this screen
Select the site you need the snippet for in the center (Property) column.
Select "Tracking Info" and then "Tracking Code" from the middle column.
The column should animate to the left and a new bit should appear that contains your tracking code formatted and completed for your site.
Copy and paste this into every page on your site.

Multiple accounts on Universal Analytics

I got a website builder app where users can create their own sites.
Each customer points his domain to the app's ip which has its own UA code to collect data and show page views statistics in the back office. In addition, if customer got his own Google Analytics account he may indicate it and start tracking data.
The current frontend ga.js code looks like this:
<script type="text/javascript">
var _gaq = _gaq || [];
/* app UA code */
_gaq.push(['x._setAccount', 'UA-XXXXXXX']);
_gaq.push(['x._setDomainName', 'customersdomain.com']);
_gaq.push(['x._setAllowLinker', true]);
_gaq.push(['x._trackPageview']);
/* customer's UA code */
_gaq.push(['_setAccount', 'UA-YYYYYY']);
_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>
Now I need to migrate to Universal Analytics but I am not sure what code should I use. I've done plenty of searches but I am still doubting. Would the following code work?
<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-XXXXXXX', 'customersdomain.com');
ga('create', 'UA-YYYYYYY', 'customersdomain.com');
ga('send', 'pageview');
</script>
You need a named tracker. You can set this up in the configuration object that can be passed as the third parameter instead of a cookie domain (in that case the cookieDomain setting goes into the configuration object). Plus you need two send pageview calls, one for each tracker.
<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-XXXXXXX', {
'name' : 'mycustomtracker',
'cookieDomain' : 'customersdomain.com'
});
ga('create', 'UA-YYYYYYY', 'customersdomain.com');
ga('mycustomtracker.send', 'pageview');
ga('send', 'pageview');
</script>

How to install and verify asynchronous Google Analytics tracking code?

In my property's Tracking Code section I see this message:
Status: Tracking Not Installed Last checked: Oct ...
The Google Analytics tracking code has not been detected on your website's home
page. For Analytics to function, you or your web administrator must
add the code to each page of your website.
The tracking code shown to be copy/pasted is this:
<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-XXXXXXx', 'example.com');
ga('send', 'pageview');
</script>
There's a learn more button and when I click it it takes me to here which shows the asynchronous code, which is something like this:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-Y']);
_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>
Is this the current/latest version of the GA code? Why is the dashboard (i.e. the Tracking Code section) is not showing this by default? Is there a way to customize the Google Analytics to show this code in the Tracking Code section, prepared for my property (website)?
What you are seeing first is the latest version of Google Analytics known as Universal Analytics. As per Google recommendation , use that for all your new analytics properties. This is identified by the analytics.js library in the tracking code
The second one is an earlier version of Google Analytics based on ga.js library.
Use the first version of tracking code given by GA and follow this tutorial based on analytics.js to debug your code.

Google Analytics Tracking GA.js vs Analytics.js

I'm trying to use this code to track an event in Google Analytics
_trackEvent(category, action, opt_label, opt_value, opt_noninteraction)
This seems to be meant to be use with the GA.js Analytics "package", however I'm using the Analytics.js
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');
Is there a way I can do even tracking with this code only ?
Or do I have to use
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-X']);
_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);
})();
Do I need both of these codes?
Or is there some different way using only Analytics.js
Thanks in advance
**EDIT:
Indeed I probably didn't explain what I want, it might not even possible.
I want to work with Funnels on Events, and I want to use _trackEvent (that's what I thought it would do) to mark a user as having Entered the Funnel, if the event is send then we will have the normal funnel.
So if 10 users enter the page and 1 clicks on the button, I would have 10 events on the Funnel with 1 success
analytics.js will report to GA same as the old code, but it has different syntax, so you can't use _trackEvent.
Here is a link to the basic on-page syntax with analytics.js, and here is a link for event tracking with analytics.js
<!-- Google Analytics -->
<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-Y'); // GA account ID goes here
ga('send', {
'hitType': 'event', // Required.
'eventCategory': 'category', // Required.
'eventAction': 'action', // Required.
'eventLabel': 'opt_label',
'eventValue': opt_value,
'nonInteraction': opt_noninteraction
});
</script>
<!-- End Google Analytics -->

Resources