简体   繁体   中英

How to track javascript event in Piwik?

I want to track when user press enter in input box, the user may want to press enter multiple times, In Piwik documentation there is info to use

trackEvent(category, action, [name], [value])

but example say to use:

_paq.push(['trackEvent', 'Documentary', 'Play', 'Thrive']);

should I use both or one of them, if so which one?

function keypress(e) {
  if (e.which == 13) {
    trackEvent("Events", "enter");
    _paq.push(['trackEvent', 'Events', 'enter']);
  }
}

or put _paq.push in my tracking snippet (next to other _paq.push) and only use trackEvent in my event, in Piwik Book there is info to use

piwikTracker.setCustomVariable

which one can I use to track javascript events?

Yes, the documentation seems confusing but, in fact, there are two ways of defining a Piwik tracker:

So, to sum up, the main difference between using _paq.push() or yourTracker.trackEvent() is how you define the tracker.

Personally, I would use the second option as it doesn't expose a clear global variable (_paq), reducing the chance of someone trying to track undesired things from the console.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM