Using analytics API


I’m trying to gather all events generated by a specific userId, and I have set up my piwik javascript code to use the setUserId and trackEvent functions. Then, I’m trying to get all events generated today for user whose id is 27736339, and if found this API call to be the closer one to what I need:;eventAction==publication;events>0&token_auth=XXXXXXXXXXXXXXXXXXXXXXXXXX

This returns all events by selected user but…

  1. I also get all pageview, goals, and any other kind of actions, while I would only want to get the “event” actions, that is those rows with event. Is there any way I can get only those?

  2. Even for those I get too much information:

<serverTimePretty>Vie 27 Mar 16:00:54</serverTimePretty>

I actually only need, eventCategory, eventName, eventAction and timestamp. Is there any way to choose beforehand which columns I need for each report? I understand that I can parse the contents of the XML file returned (or whatever other format I use) and skip the information I don’t need, but I’m worried if I have to get the events of a high traffic site, then this extra information will increase the load of the server and affect solution performance.

  1. If I remove the userId segment, then I get all events from all users. Is there any way that I can get the userID of each event?

In other words, what I would like to have is a report returning all events data (eventName, eventAction, eventCategory, timestamp, userId) from a given period/date, and be able to filter that report by userID if needed (but also be able to request all).

Thanks in advance.

Hi there

  1. there is no way to filter out and keep only events. You have to do it manually in your script.

  2. to remove any specific column you can use &hideColumns parameter

Hi Matt,

Thanks for reply.

I have tried to user the hideColumns and showColums parameters, but I couldnt make it work cause the colums i want to hide are not in the first level of the XML file. That is, in the Live.getLastVisitsDetails result I can hide/show idSite, visitorID, visitIp, actionDetails columns, but I cannot control the columns inside the rows within the section, that is, I cannot hide/show url, pageId, serverTimePretty,generationTime, etc.

Maybe I’m just trying to get something the API is not built for, so let me explain what I want to do, cause maybe there are other ways to do it:

Basically I want to store every event with a given eventCategory in a separated table, which would contain the following fields: eventCategory,eventAction,eventName,timestamp,userId,visitorId (tat table will be actually a mongodb collection, but I don’t think that is important).

So my original idea was letting piwik do its job, and then use the API to extract that information. The information should not be extracted in real time, updating data once every hour would be enough. Sadly, I cannot find a way to extract all events from last hour in a way I have all those fields (I’m specially missing the userId field).

Then I thought about modifying the piwik.php file, so I can just get the events at request time, that is something I can do, but it forces me to parse every request querystring to determine if it is an event, and which event category it is, and then save to mongodb if it’s the one I want to track, what would affect performance. Also, I have found all required fields in the event tracking urls.

Well, while this second idea may work, it would be better to be able to extract data via the API, than “hooking” into the piwik.php file (what would lead to extra maintenance work when upgrading piwik).

Is there any way to get all those events with those fields via de API? May there be another way to do this that I haven’t think about? Is there any other way to hook into the tracking request response process that would save me from parsing the URL, cause it is already parsed?

Thanks in advance,

PS: Edited cause I found the visitorID in the request URL (I was asking where it was, it is _id parameter)

After some reading on the “Piwik in Depth” section, and some investigation, I’ve found the way to extract that information directly from the database (some joins among piwik_log_visit, piwik_log_action and piwik_log_link_visit_action tables did it).

I’ve also learnt that probaly I can create a plugin and link to some event (probably this one Events - Matomo Analytics (formerly Piwik Analytics) - Developer Docs - v3)

Probably the best way to do what I wanted it is hooking that event, in case $trackerAction and $visitAction parameters include all I need, otherwise I’d have to query the database what would not be a good idea at tracking log time.

This is the horrible query that made what I was looking for, in case some other may find it helpful:

SELECT Q2.server_time,, V.user_id from
SELECT  Q.server_time,Q.idvisit, from
SELECT  server_time, idaction_name, idvisit FROM piwik_analytics.piwik_log_link_visit_action 
where idaction_event_category=706974 and idaction_event_action=706973 AND server_time>'2015-03-30 17:00:00')
LEFT OUTER JOIN piwik_analytics.piwik_log_action A on Q.idaction_name=A.idaction
Q2 LEFT OUTER JOIN piwik_analytics.piwik_log_visit V ON Q2.idvisit=V.idvisit

706974 and 706973 are the idaction values in the piwik_log_action table that matches the eventCategory and eventAction I want to filter by. Of course the date should be modified too.

By the way, in Piwik’s Extensibility Points: DevelopInDepth - Matomo Analytics (formerly Piwik Analytics) - Developer Docs - v3 there is a broken link to “Events” section, it should be pointing to Events: Develop - Matomo Analytics (formerly Piwik Analytics) - Developer Docs - v3 but currently points to (please notice the missing “s” at the end og “guides”)

Thanks for the ping about 404 error we will fix it in 404 link · Issue #91 · matomo-org/developer-documentation · GitHub