I know this is not the only question out there, but I still couldn’t find a hint on what’s wrong.
The javascript:
$(function()
{
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-[FILTERED]-1']);
_gaq.push(['_trackPageview']);
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);
$('a[href$=pdf]').each( function() { $(this).attr('target', '_blank'); });
$('a[href$=pdf]').on('click', function() { _gaq.push(['_trackEvent', 'Link', 'Click', $(this).attr('href'), 1]); });
});
SO, when inspecting the generated source code (through the webdevelopment toolbar in FF), the javascript libraries are inserted in the following order:
- ga
- jquery
- the page js with the content seen above (1:1)
I don’t get any errors in firebug, page tracking is working fine and inserting debug output after the .push also works, so no “ghost stop”.
I tried to click some pdf files every day for 3 days, and there is nothing in GA registered.
Any ideas?
edit
I tried to debug it with ga_debug.js. Firebug shows the requested images for _trackPageview, but not for _trackEvent. So I tried the following:
$('a[href$=pdf]').each( function()
{
$(this).attr('target', '_blank');
$(this).attr('onClick', "javascript:_gaq.push(['_trackEvent', 'Link', 'Click', $(this).attr('href'), 1]);");
});
Now the images is requested, but according to firebug, loads forever and won’t complete.
Problem solved, apparently you cannot oursource the
_gaqpart into a file and include it. Adding it directly into the html template works.