0

Hi I'm trying to set GA to track as events (pageviews would work too) the opening of some pdf files I have on my page.

This is the code I include in every 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','//www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-15438479-1', 'discinesia.it');
ga('send', 'pageview');

</script>
<script>
$("a[href$='pdf']").click(function(){
_gaq.push(['_trackEvent', $(this).attr('href') ]);
});
</script>

Now, when I see real time event tracking, or even past events tracking (I included this 3 days ago) it doesn't report of any event. If I try and change trackEvent with trackPageview, it doesn't work anyway.

If it's of some use, the environment I work into is ASP.NET and the ga code is included in the bottom of the page. Obviously the standard report works correctly.

I really don't know what to do, please help me.

Thanks in advance.

0

1 Answer 1

1

You are mixing Analytics versions, that's not going to work (has also been discussed here).

Correct syntax for event tracking in Universal Analytics is

ga('send', 'event', 'category', 'action', 'label', value);

where label and value are optional (if you use value it should be an integer). The Google Documentation on this is actually rather good.

More generally if you have ga() in your tracking code you cannot use _gaq.push() to call an Analytics method.

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.