Best way to track custom events?


#1

Hi, I’m getting familiar with Piwik and how to use it for custom tracking. What I want to do is basically track “usages” or custom log messages:

[ul]
[li] in the tracked pages source code, I’d be calling something like (on demand, even multiple times in single page view)


[/li]_paq.push(["myCategory", "myParameter1", "myParameter2"])

[li] piwik automatically saves these logs to DB
[/li][li] in Piwik, I’d have PHP plugin to process and display these data
[/li][/ul]

What is the best way to achieve this? I know Piwik has custom variables but they seem to me too limited for my usecase so I’m trying to find a way how to achieve this using custom PHP plugin. I was trying to find some tutorials/documentation but it shows basic PHP plugin without this custom tracking. When I tried to call the _paq.push as above, I’m getting


Uncaught TypeError: Cannot call method 'apply' of undefined

Right now I have 2 possible solutions:
[ul]
[li] With custom variables, I would probably have to create a “wrapper” JavaScript object that would check custom variables to avoid overriding and if needed it would call _paq.push([‘trackPageView’]); . I’m only worried about possible high network communication as it is not very efficient
[/li][li] Create independent JS logger that would push data to some piwik-independent endpoint. This endpoint would save them to e.g. DB and Piwik PHP plugin would simply read them from DB display them
[/li][/ul]

Neither of them looks like ideal to me…


(Matthieu Aubry) #2

can you explain better what you are trying to do?


#3

Well my goal is to track “custom events”, where each event can have several parameters (not yet known in this moment). I found issue #479 which is about custom events and it seems to work fine for me at this moment but it still has limited number of parameters (category, action, label, value). It could be enough and hopefully will be but what if I would want to track “real” custom event (meaning not known to Piwik)? Something like


  _paq.push(["myVeryOwnEvent", "myParameter1", "myParameter2"])  

Is this possible with the JavaScript tracker API?


(Matthieu Aubry) #4

You may use trackEvent with any number of custom variables.


Post object instead of string when using trackEvent