Google Analtyics Event Tracking for File Downloads Not Working - google-analytics

I am trying to setup event tracking for file downloads in Google Analytics. After some research I added the following code to the link that needs to be tracked:
<a onclick="_gaq.push(['_trackEvent','Download','PDF',this.href]);" href="http://www.link.com/file.pdf" target="_blank">Link Text</a>
The following code is on the page for Google Analytics:
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-9999999-1");
pageTracker._trackPageview();
} catch(err) {}
</script>
This has been active for over 48 hours but I'm not getting events in GA. It says that "13 of your visits sent events" but displays no other information. Any ideas?

It looks like you're mixing two different APIs for Google Analytics.
The first snippet you posted is for the ASYNC tracking but you have used the (now legacy) traditional tracking in the second snippet.
To get it working change your page tracking code to look like this, the other code looks OK.
<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 ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
More details here:
https://developers.google.com/analytics/devguides/collection/gajs/asyncTracking

If you are Migrating to Async Tracking, the following link can guide you - https://developers.google.com/analytics/devguides/collection/gajs/asyncMigrationExamples

Related

how to check which version of Google Analytic code is working?

I am working on a website, and i want to do record event event on the website. for that i have searched on Google and found Event Tracking. but i how to check whether i am using ga.js or analytic.js and which is better to use and why.
My google Analytic code is:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', '[TRACKING_ID]']);
_gaq.push(['_setDomainName',document.domain]);
_gaq.push(['_setAllowLinker',true]);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'stats.g.doubleclick.net/dc.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
please help me.
Universal Analytics does not use the .push syntax. Instead, it has a function ga().
You apear to not be using universal analtyics you should check this link on how to work with Event Tracking: Event Tracking - Web Tracking (ga.js)
This link should help you understand the diffrence: About Universal Analtyics

google analytics setup, not tracking

I'm trying to implement google analytics on a page but it refuses to track anything.
the public domain is on www.publicdomain.com, when entering the page its redirected to: www.publicdomain.com/sub1/sub2/index.php
this website is hosted on another domain:
www.privatedomain.com/publicdomain/sub1/sub2/index.php
This is the GA code I'm using inside the body tag of the index.php file:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-9999999-9']);
_gaq.push(['_setDomainName', 'publicdomain.com']);
_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>
Any ideas of what could be wrong?
Here are some things to check:
Are you using the correct UA number? (i.e. not 999999-99)
Are the GA cookies being created? (__utm[abcz])
Is the __utm.gif request being sent back to Google? If not, is your browser blocking it? (i.e. is Do Not Track enabled?)

Google Analytics Tracker not working in ASP.NET website

I've got a client with about 6 websites that are all the same framework in VB.NET. I've tried to add Google Analytics Tracker inside each of them with no success. I've many clients with WordPress website or with my custom CMS (in JavaServer Faces) that are working perfectly. I'm pretty sure I'm doing something wront in VB.NET which I almost never use.
Here is the code in VB.NET I'm currently using :
<head>
...
<!-- Google Analytics -->
<asp:ContentPlaceHolder ID="GoogleAnalyticsTracker" runat="server">
<script type="text/javascript">
alert('ga-start');
var _gaq = _gaq || [];
_gaq.push(['_setAccount', '<%= m_sIDGoogle %>']);
_gaq.push(['_setDomainName', 'none']);
_gaq.push(['_setAllowLinker', true]);
_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);
alert('ga-stop');
}
)();
</script>
</asp:ContentPlaceHolder>
</head>
Note : I've tried just before the </body> too, as described in Google Analytics.
Here is the rendered result :
<script type="text/javascript">
alert('ga-start');
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA–29119317–1']);
_gaq.push(['_setDomainName', 'none']);
_gaq.push(['_setAllowLinker', true]);
_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);
alert('ga-stop');
}
)();
</script>
Also note that the two alert('') are working, Firebug tell me that the ga.js is loaded too.
After all that, nothing is tracked in Google Analytics. Someone have an idea of what I'm doing wrong?
You can also visit the test website : http://mouk-mouk.amiesterre.com
Finally fixed, I don't know why, but the codes were wrong :
UA–29119317–1 > UA-29119317-1
UA–29119317–1 > UA-29119317-1
Visually we see nothing in Courier New...

Uncaught ReferenceError: _gaq is not defined (Google Analytics)

The following message appears when viewing a site page in the chrome debug log.
Uncaught ReferenceError: _gaq is not defined
The page itself is supposed to track an object using the onload event handler and fire a _trackEvent for Google Analytics.
My best guess is that perhaps the ga.js file doesn't load in time and therefore the onload _trackEvent triggered is not caught. the async snippet is being used before the </body> close and the object is positioned in the middle <body>.
(some other posts have referenced jQuery position too but, this might be a red herring)
any assistance greatly appreciated.
From https://developers.google.com/analytics/devguides/collection/gajs/ this code replaces your existing "traditional snippet" with the "latest, asynchronous version, you should remove the existing tracking snippet first."
<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 ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
To see your events come in (to know if this is working) look for "Events" under the "Real-Time" menu option on the left side of the "Reporting" page.
Regarding the position of the async snippet, the GA help page says -
Paste this snippet into your website template page so that it appears
before the closing </head> tag.
My first thought was that JS should be loaded at the bottom of the page to improve page speed. However, the GA async tracking snippet should be loaded in the head, as it will not load the ga.js immediately, and it won't block page execution.(It does this by dynamically adding the script tag to the DOM, which puts it at the back of the queue.)
If, for some reason, you can't move the async snippet to the head, you can define _gaq yourself, like this-
<button onclick="var _gaq = _gaq || []; _gaq.push(['_trackEvent', 'button3', 'clicked'])"/><button>
Had the same problem. You have to define the _gaq array. Just add this after your Google Analytics script in the header:
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXX-X']);
_gaq.push(['_trackPageview']);
You can use the last version of analytics.js instead of ga.js
ga.js is a legacy library. If you are starting a new implementation we
recommend you use the latest version of this library, analytics.js.
For exisiting implementations, learn how to migrate from ga.js to
analytics.js.
Here is an example:
ga('send', {
hitType: 'event',
eventCategory: 'Video',
eventAction: 'play',
eventLabel: 'cats.mp4'
});
Change the Tracking Code to:
<script type="text/javascript">
var gaq;
var _gaq = gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-X']);
_gaq.push(['_setDomainName', 'yourdomain.com']);
_gaq.push(['_setAllowLinker', true]);
_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>

jQuery to track Google analytics events not working

I'm trying to use google anayltics events but so far without any success..
What I'm doing is loading 5 pages using jQuery load function
and I want to track the "Next button" for each load. but looks like i'm doing something wrong..
This is the next button event code:
$('.NextButton').click(function () {
_gaq.push(['_trackEvent', 'fz_main_page', 'clicked']);
installation.load_page({ inner_page: next_page, comid: data.comid, outerid: data.outerid, single_app: "1" });
});
Analytics Code:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-25162785-2']);
_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>
What am I doing wrong?
It's possible that the installation.load_page function is preventing the trackEvent from firing. Try wrapping your load function in a setTimeout:
setTimeout('installation.load_page({ inner_page: next_page, comid: data.comid, outerid: data.outerid, single_app: "1" })', 100);
Install the Google Analytics Debugger. Look in the console (control, shift, j) for the event tracking processing.
If you don't see all of your events tracking there, then something else is up with the tracking code.

Resources