Public total visits count for a website with a high traffic

I have a website with about 300 000 page views per day. I have a requirement to show total views count on most of pages. Of course, I can’t get data from piwik on each page view, so I have an intermediate data store, like a cache, storing url-count values. But I still need to keep it rather actual (1 hour delay, for example).

My solution was rather simple: every 5 minutes cron runs a script, which gathers data about page visited during that interval using Live.getLastVisitsDetails method. It adds urls to queue. Queue handler calls VisitsSummary.getVisits to get total count and writes it to intermediate data store.

Now, the problem - VisitsSummary.getVisits works really slow. Queue grows extremely fast and counters on the site are out of date.
Is it real to get it working using piwik? How can I optimise this process? I mean, maybe its possible to get multiple counters in one query? I know its possible to make multiple API requests using one HTTP request, but logically it won’t help.

I think my question is redundant. Really, its quite simple - how can I speed up VisitsSummary.getVisits request for a custom segment (specific url)?

HI there,

Set your segment as “Pre-process by cron” in the top right of the Segment Editor, when creating your segment.

Then make sure you setup: How to Set up Auto-Archiving of Your Reports - Analytics Platform - Matomo

The API call should then be very fast as the data will be pre-processed!

Of course, I have cron job set up.

Can you please clear one thing? For example, I have a segment “page url contains /post/”. Does it pre-process only queries requesting whole segment, or a specific post (/post/1/) too? As I understand, just for the whole segment, so it won’t help getting stats for a specific post?

Maybe I should create a segment for every page then? :stuck_out_tongue: