简体   繁体   English

如何在Piwik中跟踪JavaScript事件?

[英]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 我想跟踪用户何时在输入框中按Enter,用户可能想多次按Enter,在Piwik文档中有要使用的信息

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 或将_paq.push放在我的跟踪代码段中(其他_paq.push旁边),并且仅在我的事件中使用trackEvent,在Piwik Book中有可用的信息

piwikTracker.setCustomVariable

which one can I use to track javascript events? 我可以使用哪一个跟踪javascript事件?

Yes, the documentation seems confusing but, in fact, there are two ways of defining a Piwik tracker: 是的,文档似乎令人困惑,但实际上,定义Piwik跟踪器有两种方法:

So, to sum up, the main difference between using _paq.push() or yourTracker.trackEvent() is how you define the tracker. 因此,总而言之,使用_paq.push()或yourTracker.trackEvent()之间的主要区别是如何定义跟踪器。

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. 就个人而言,我将使用第二个选项,因为它没有公开明确的全局变量(_paq),从而减少了有人尝试从控制台跟踪不需要的内容的机会。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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