Universal Analytics cross domain tracking with multiple trackers - google-analytics

So i have Universal Analytics code with multiple trackers:
<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-x', 'auto');
ga('create', 'UA-yyyyyyyy-y', 'auto', {'name': 'second'});
ga('send', 'pageview');
ga('second.send', 'pageview');
</script>
How do i create Cross Domain tracking since UA-yyyyyyyy-y profile is used to gather info from 2 separete domains. With one tracker it is pretty simple:
<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-yyyyyyyy-y', 'auto', {'allowLinker': true});
ga('linker:autoLink', ['other-domain.com'] );
ga('send', 'pageview');
</script>
But what do i do wen i have 2 trackers, how do i set up cross domain tracking for this Universal Analytics profile: UA-yyyyyyyy-y? If you answer my question you will also answer a part of this question:
http://stackoverflow.com/questions/20126897/google-analytics-cross-domain-tracking-with-multiple-trackers

In your example with just a single tracker, you're missing the call to require the linker plugin. Without that it won't work. Perhaps that is the source of your issue.
Regardless, in analytics.js you can call any method on any tracker by simply prefixing the method name with the tracker name. You'll notice your first example already does this in the line ga('second.send', 'pageview').
So, to implement auto-linking on both trackers you'd do something like this:
ga('create', 'UA-yyyyyyyy-y', 'auto', {allowLinker: true});
ga('require', 'linker');
ga('linker:autoLink', ['other-domain.com'] );
ga('send', 'pageview');
ga('create', 'UA-yyyyyyyy-y', 'auto', {name: 'second', allowLinker: true});
ga('second.require', 'linker');
ga('second.linker:autoLink', ['other-domain.com'] );
ga('second.send', 'pageview');
Notice the second. prefix on all the method calls in the second block which corresponds to the name "second" that I gave the tracker.
For more information on the auto-linker plugin, check out this resource:
https://developers.google.com/analytics/devguides/collection/analyticsjs/cross-domain#autolink
And for more information on the various methods and method signatures, here is the guide:
https://developers.google.com/analytics/devguides/collection/analyticsjs/method-reference

Related

How to format the userId in Google Analytics script?

for my static HTML webside I embedded this recommended script code to every page of the side.
<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','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-96597161-1', 'auto');
ga('send', 'pageview');
ga('set', 'userId', {{USERID}});
The question is:
how to format my known Google analytics userId into this place {{USERID}}?
Is it With brackets?, with quotes?
Thanks for your help.
The analytics.js fields reference lists UserID as format type "text", which means you pass it in like you would any other string value in Javascript (i.e. in as quoted string).
In fact the same page has examples:
// Set the user ID when creating the tracker.
ga('create', 'UA-XXXX-Y', {'userId': 'as8eknlll'});
// Alternatively, you may set the user ID via the `set` method.
ga('set', 'userId', 'as8eknlll');

Google analytics not tracking enhanced ecommerce Data

i manage several hotels on analytics, actually have like 400, and we are updating the ecommerce data to enhanced ecommerce.
when i updated the scripts to e ecommerce on 100 hotels, no one was working, so i ran a test and i found that the isogram analytics code wasnt implemented, fixed that and now 70/100 hotels are getting ecommerce data.
idk if is matter of time to get the data on the last 30 hotels but here is the code, if anyone can see anything wrong, thanks.
<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', 'viewcode', 'auto', {'allowLinker': true});
// Load the plugin.
ga('require', 'linker');
// Define which domains to autoLink.
ga('linker:autoLink',['websites']);
ga('send', 'pageview');
ga('require', 'ec');
ga('set', '&cu', 'MXN');
ga('ec:addProduct', {
'id': '{SkuCode}',
'name': '{ProductName}',
'category': '{Category}',
'price': '{UnitPrice}',
'quantity': {Quantity}
});
ga('ec:setAction', 'purchase', {
id: '{NoReservation}',
revenue: '{Total}',
tax: '{Tax}'
});
ga('send', 'event');
</script>
The analytics code that you are using it looks right, however in order to assure that analytics code is pushed from the all the hotels websites I recommend you to follow the following steps:
1) Check that hotels domains name are correctly in the "linker" parameter
2) Verify that those websites dont't have another GA analytics code that overwrite your code. In order to avoid conflicts I recommend you to rename the "ga" global object to "myga" or something like that. Example:
<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','myga');
myga('create', 'viewcode', 'auto', {'allowLinker': true});
// Load the plugin.
myga('require', 'linker');
// Define which domains to autoLink.
myga('linker:autoLink',['websites']);
myga('send', 'pageview');
...
You can check when a hotel is pushing events if you are using the GA Real-time in the GA dashboard.

Google Analytics pageviews tracking were not working

(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', 'Domain'); // Replace with your property ID.
ga('send', 'pageview','URL');
You're problem is this line:
ga('create', 'Tracking ID', 'Domain'); // Replace with your property ID.
It should have your GA property Id in it which will begin with UA. Something like this:
ga('create', 'UA-12345678-1', 'auto'); // Replace with your property ID.
You can find the property id under the Home section of Google Analytics. Or alternatively look at Admin->Property->Tracking Info-Tracking Code.

Track campaigns with the help of javascript

I have issue to track campaign not with the help of url
http://domain.com/page?utm_campaign=xxx&utm_source=xxx&utm_medium=zzz
but javascript call.
According to the information given here developers.google.com and my inpage google analytics universal 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-zzz', 'domain.com');
ga('send', 'pageview');
</script>
I've tried to send inforation about campaign in many different ways, but all of them were unsuccessfull. I haven't found campaighn data in Analytics reports.
///
ga('_setCampNameKey', 'xxx'); ga('_setCampSourceKey', 'yyy'); ga('_setCampMediumKey', 'zzz');
///
ga('send', '_setCampNameKey', 'xxx'); ga('send', '_setCampSourceKey', 'yyy'); ga('send', '_setCampMediumKey', 'zzz');
///
ga('push', '_setCampNameKey', 'xxx'); ga('push', '_setCampSourceKey', 'yyy'); ga('push', '_setCampMediumKey', 'zzz');
///
ga('set', '_setCampNameKey', 'xxx'); ga('set', '_setCampSourceKey', 'yyy'); ga('set', '_setCampMediumKey', 'zzz');
///
ga('set', 'CampNameKey', 'xxx'); ga('set', 'CampSourceKey', 'yyy'); ga('set', 'CampMediumKey', 'zzz');
///
ga('set', 'campNameKey', 'xxx'); ga('set', 'campSourceKey', 'yyy'); ga('set', 'campMediumKey', 'zzz');
What is the right way to track campaign info?
I struggled to find the answer to this, too, so even though this question is super old, I wanted to leave this here for others to find.
The analytics.js replacement for _setCampNameKey (and the other campaign tracking parameters) can be found here:
https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#campaignName
And this page has a full example of how to implement them:
http://randomproblems.com/how-to-setoverride-campaign-variables-in-google-analytics-universal-with-js/
gv0zd's answer is correct except that the Campaign parameters have to be set before sending the pageview. If you send them after (as in gv0zd's example), it does not work.
This is the solving of the problem
<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-zzz', 'domain.com');
ga('send', 'pageview');
///////
ga('set', 'campaignName', 'XXX');
ga('set', 'campaignSource', 'YYY');
ga('set', 'campaignMedium', 'ZZZ');
</script>

Multi google codes in one page

We have this code on the 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-40584814-1', 'webistename.com');
ga('send', 'pageview');
</script>
How can I add another account to it? Can I add something like this?
Can I add something like 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-40584814-1', 'webistename.com');
**ga('create', 'UA-472147-1', 'webistename.com');**
ga('send', 'pageview');
</script>
I tried that and I can't see the stats on the new account. How can I achieve this? I know I could invite someone via an email but I want to add a completely new account.
Thanks!
Since you're using Universal Analytics (not the original Async version), you have to pass it within the create statement via the options object:
ga('create', 'UA-XXXXXX-X');
ga('create', 'UA-XXXXXX-Y', 'auto', {
'name': 'foo'
});
// later on...
ga('send', 'pageview'); // sends to account XXXXXX-X
ga('foo.send', 'pageview'); // sends to account XXXXXX-Y
The documentation
Asynchronous tracking code my friend ;)
https://developers.google.com/analytics/devguides/collection/gajs/?hl=pl#MultipleCommands

Resources