Google Analytics pageviews tracking were not working - google-analytics

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

Related

Google Analytics Custom Dimensions Not Feeding Through

I have setup custom dimensions as follows
My source code shows as this:
<script>
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
ga('create', 'UA-XXXXXXX-1', 'auto');
ga('send', 'pageview');
ga('set', 'dimension1', 'Manager');
ga('set', 'dimension2', 'Recruitment');
ga('set', 'dimension3', 'Leave');
</script>
It's been in place for 24 hours. However when I go to my Google Analytics account > Home > Behaviour > Site Content > All Pages, and then add any of the custom dimensions I've created, no data is brought back.
Am I doing something terribly wrong or does everything look ok?
Swap it so that it is this way:
<script>
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
ga('create', 'UA-XXXXXXX-1', 'auto');
ga('set', 'dimension1', 'Manager');
ga('set', 'dimension2', 'Recruitment');
ga('set', 'dimension3', 'Leave');
ga('send', 'pageview');
</script>
This is because the "hit" doesn't get sent with ga set. The ga send is the only hit there.

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.

Universal Analytics cross domain tracking with multiple trackers

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

Google Analytics Event Tracking onClick Code

I'm trying to set up event tracking on my web site but can't get it working correctly.
My 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-420xxxxxxx', 'mywebsite.org');
ga('send', 'pageview');
</script>
My event tracking code:
Purchase Details
You are mixing classic code with universal code. It will not work. You need to replace this:
_gaq.push(['_trackEvent', 'Button', 'Click', 'Purchase Details',, false]);
With this:
ga('send', 'event', 'Button', 'Click', 'Purchase Details');
GAJS reference for Events: https://developers.google.com/analytics/devguides/collection/analyticsjs/events#implementation
Event hits can be sent using the send command. According to new analytics.js
Syntax:
ga('send', 'event', [eventCategory], [eventAction], [eventLabel], [eventValue], [fieldsObject]);
For example if you want to track purchase event
ga('send', 'event', 'Button', 'Click', 'Purchase Details');
Here:-
eventCategory is Button. It is required field and its Value Type is text
eventAction is Click. It is required field and its Value Type is text
eventLabel is Purchase Details. It is optional field and its Value Type is text
eventValue is null. It is optional field and its Value Type is integer
it looks like you're using the new analytics.js instead of ga.js, so you'll want to use the proper event tracking method set:
ga('send', 'event', 'category', 'action');

Resources