javascript - Why is this analytics event tracking code not working? -


my website offers downloads of various apps windows, mac, , linux platforms. want count number of times each individual software package downloaded. believe accomplished in google analytics setting event tracking code.

i have javascript code @ top of page:

  (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;i have m.parentnode.insertbefore(a,m)     })(window,document,'script','//www.google-analytics.com/analytics.js','ga');    ga('create', 'ua-xxxxxxxx-1', 'auto');   ga('send', 'pageview');    // necessary download tracking code work.     var _gaq = _gaq || [];   _gaq.push(['_setaccount', 'ua-xxxxxxxx-1']);   _gaq.push(['_trackpageview']); 

downloads selected via dropdown menu, points javascript code gets right package download, , triggers analytics tracking event.

the code attached each downloadable app looks this:

if (packagechoice === "app1") {     _gaq.push(['_trackevent', 'downloads', 'app1 name']);     window.open("/download/app1.exe"); } else if (packagechoice === "app2") {     _gaq.push(['_trackevent', 'downloads', 'app2 name']);     window.open("/download/app2.pkg"); } 

however, have not registered single download in google analytics/behaviour/events.

what missing?

you mixing _gaq.push (which old ga.js) , ga.send analytics.js using.

instead of:

_gaq.push(['_trackevent', 'downloads', 'app2 name']); 

try:

ga('send' , 'event', 'downloads', 'app2 name'); 

documentation:


Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -