Storing external reports in Piwik


Hi all,

I read about the possibility to display external data in Piwik reports - this is already great, but I’m wondering if anyone has tried to store these external data reports in the Piwik database?
It seems not so nice to have to connect to the other database every time I want to see the report… The report data I want to display is less dynamic than page visits, something really only worth storing once a day (e.g. total number of registered users on the website, or total content items) - that’s why I don’t want to push it via the tracking script.

I hope this doesn’t sound too silly, I’m new to Piwik, but I’d be grateful if you could share your thoughts - does this sound crazy, or is it worth working on? Are there perhaps some API methods that could be easily adapted for this?


(Matthieu Aubry) #2

Can you explain in more detail what you are trying to achieve?

This use case is typical of what we want to achieve with Piwik 2.0 so your input is appreciated.


Hi matt,
Thanks for replying! Good to hear that this idea is not just the product of my crazy brain! :slight_smile: Here is my situation and what I would like to achieve:

I have got:

  • a Drupal site for which statistics need to be gathered and displayed in nice charts to users (Piwik module is integrated)
  • a Piwik installation on the same server (but eventually could be on another)

I need:

  • site tracking stats, basically the default Piwik tracking statistics
  • user data stats (e.g. how many registered users there are on the site in total, how that number has evolved over days/months, etc.)

This question is about this second type of stats.
I’d like to generate these reports via Piwik - the data is already collected in my site’s database and I only need daily granularity tops, so I figured that it is kind of pointless to collect this extra info via tracking script on each page hit. I checked out the Example plugins and found I could easily create a report by directly querying an external (i.e. my site’s) database.
So far so good - but the report that I get is not stored. Every time I request the report on my site’s interface, it calls to Piwik for the report generation, Piwik has to connect to my site’s database, get and analyse the data, and then send back the report (long story short: performance overhead!). I would like to take this a step further and not just generate the report in Piwik, but also store it in the Piwik database.

So let’s say that I want to keep track of the total number of registered users on my site - the scenario I would like to achieve goes like this:

  • I let the site take care of the user data as usual
  • once a day cron triggers a custom Piwik plugin that connects to the site’s database and runs a query to find out how many registered users there are today (basically “select count(*) from users” )
  • Piwik stores this info in its archive just as it does for the default tracking reports
  • when the report is requested, Piwik can just query its own archive and hand me the report

It would be great if I could carry all my statistics data and analysis outside my site - so Piwik runs in its own quiet space, keeps all the report data, and assumes all of the stats-related performance load. Plus I love the fact that Piwik can store archived reports, so no space is wasted. Well, all in all Piwik looks like just the solution I need to keep all my stats data under control. What I can’t figure out is how to put this external report data into the Piwik archive. As far as I’ve got, the archiving methods seem to deal only with the data first stored in the raw log tables, and I’m not sure if I need that step (and indeed whether that would work out at all).

If you could nudge me in the right direction here, that would be great!
And if I have left out something else you’d like to know (in spite of the wild verbosity), please do ask!


Hi hanaha ,
I’ve a similar situation as yours .
I want to store some data in Piwik database and then pull the report from the data that i stored.

Didi you find a solution to this ?

Thanks and Regards,

(Matthieu Aubry) #5

I want to store some data in Piwik database and then pull the report from the data that i stored.

For this we recommend using Custom Events : Event Tracking - Analytics Platform - Matomo
and Custom Variables: Using Custom Variables in Piwik (Tutorial) - Analytics Platform - Matomo

then to get the data out, you can use the reporting API: Reporting API Reference: API Reference - Matomo Analytics (formerly Piwik Analytics) - Developer Docs - v3
or the Widgetise features: Embedding Piwik Reports in Other Websites or Apps - Analytics Platform - Matomo