Google analytics events not showing up - google-analytics

New to google analytics so bear with me. I added the event tracking to my code, but when i check in the reporting behavior event tab it's blank. Here is my 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-XXXXXXXXX', 'auto');
ga('send', 'pageview');
</script>
here is an example of my a tag
<a href="http://example.com/" target="_blank" class="app-logo" ga('send', 'event', 'Link', 'Click', 'example.com');>

In google-analytics, for the correct website, look on the "realtime/events" page and see if events are appearing there (they should appear here within a few seconds, after being triggered on your website).
If not, you might have added a filter, to filter out events generated by traffic from your own IP. You can find this filter under "admin" and then "all filters". If so, remove it (or temporarily change the IP-address, so it doesn't match). After that, generate a few events on your website and look again on the google-analytics page, under realtime traffic / events page.
If they work under realtime, it should also work in non-realtime (but it might take 24-48 hours to appear there!)

Not sure if this just a typo in your example, but you are missing the event handler in your link:
The event handler ("onclick") is the bit that specifies which action shall trigger the javascript code. If you just dump the event call in the HTML it will not even be recognized as JS.

Related

When adding google tag manager snippet, do I need to remove google analytics tracking code totally?

My only confusion is:
Full code before Adding google tag manager as below ()
(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-65833292-1', 'auto');
ga('send', 'pageview');
Now, for google tag manager code to be added, do I need to add the google tag manager script in addition of the above code or should I remove the tracking code of analytics and add ONLY GTM snippet?
Ideally, you will need to remove all GA (on-page) tracking code including the standard snippet so that you only have the GTM snippet. Everything will be taken care of from within GTM (pageviews, events, other hits). Although leaving the GA code on the page does not cause any errors, it will skew your data.

Google Analytics beacon sent but Analytics shows nothing

I installed Google Analytics (UA) and added tracking code to a html page.
I ran html page from the browser file:///C:/test.html and debugged using google debugger, it ran successfully and shows sent beacon - but Analytics does not show the numbers. I waited for a day but still does not work.
**It works fine if I place the file in c:\Inetpub\wwwwroot and run as http://localhost/test.html
-------------------Code in test.html page-------
<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-******-*', 'auto',{'storage': 'none'});
ga('set', 'checkProtocolTask', null);
ga('send', 'pageview');
</script>
Can anyone tell me if google analytics works in my case.
What you want to do should definitely work, but you'll have to modify a few other things you're sending to prevent the hit from being dropped by Google Analytics.
Basically what's happening now is your hit is invalid. As you can see here using the Hit Builder tool.
I think you should be able to get around this by using the page field instead of the location field (which is auto-populated by analytics.js when you create the tracker), like so:
ga('set', 'location', null);
ga('set', 'page', '/test.html');
ga('send', 'pageview');
I've never tried this without also setting the location field, so it's possible Google Analytics will still complain that no hostname is present (Note: I tested this with Google Tag Assistant and it did complain, but it didn't say anything about the hit being invalid, so it will probably work fine.)
If using page instead of location doesn't work, you can always just modify location and give it a fake hostname, and that will definitely work.
ga(function(tracker) {
var oldLocation = tracker.get('location');
var newLocation = oldLocation.replace('file:///C:', 'http://fakehostname.com');
tracker.set('location', newLocation);
})
ga('send', 'pageview');
In either case, you won't need to unset the checkProtocolTask because you're now not using the file protocol.
Since it sounds like hostname doesn't matter in your case, giving it a fake value should have no impact on your reports.

Google analytics not showing traffic despite GTM firing

I'm using Angulartics to implement events and tracking on my site.
See: https://github.com/luisfarzati/angulartics
We're currently injecting the analytics tracking code with GTM. If we don't inject the snippet, there's no traffic visible in Analytics.
See snippet:
<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-XXXXXXXXX', 'auto');
</script>
The events are sent and everything seems to work in GTM. We don't need to use
ga('create', 'UA-XXXXXXXXX', 'auto') in the injected code because the UA ID is already set in GTM, so there is some magic Google is doing with linking up GTM with analytics.
Basically, without (//www.google-analytics.com/)analytics.js loaded, we see no traffic.
I thought this would work, but clearly it doesn't.
Can anyone help me out with this?
Thanks

Does not display track record in Google Analytics

I have installed plugin WP Post to PDF to convert a current post in pdf. but now i dont know how many person use this feature on my site. so i want to track of pdf download from my site http://careertest.guru99.com/
Thats why i have added onclick event on this link as below
onclick="_gaq.push(['_trackEvent','Download','Click',this.href])";
and also added below code in plugin
<html>
<head>
<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','http://www.google-analytics.com/analytics.js','ga');
ga('create', 'XX-YYYYYYY-Z', 'auto');
ga('send', 'pageview');
</script>
</head>
</html>
So when a user click on Download PDF, a PDF will be downloaded but in Google Analytics it does not display any effect. Means in google analytics it does not display how many people Downloaded PDF and from which post.
Please help me how can i know this.
Thank you
Aside from the JS syntax errors, if you are using Universal Analytics, then you will need to use the "ga" object (currently you are using the older _gaq object). To send the event through the onclick handler, your Google Analytics code should look something like this
ga('send', 'event', 'download', 'PDF', $(this).href);
Also note that your quotes should be consistent. Use the single, straight quotes.
Hope this helps.

Track Multiple Domains with analytics.js

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.

Resources