How to add page views

Enonic version: 7.12.2
OS: Linux

I’m trying to add a page views counter.
Can you please tell me what is the best way to do that?

Hi Nikolay,

For a simple counter I would probably use lib-repo and lib-node to to create a repository where I store the path of the visited page and a counter. Then I would increment the count in a response processor.

:warning: Do not store the counter on your content! You will get trouble with the publishing flow if you let users change your content.

For a little bit more advanced analytics I recommend Fathom Analytics ($14/month). It is a GDPR-friendly alternative to Google Analytics. I’ve created an app on Enonic Market to use it in XP.

I would not recommend using “free” 3rd party frontend services to solve this. Most likely they will be selling your users personal information.

Good luck with your app!

– Tom Arild

1 Like

I would generally be careful about storing this kind of “log data” in XP. Any change to an XP node is currently versioned, and versions are only cleaned by vacuuming. Also, what will you do when an item is moved or deleted etc.

If you still want to store the data in XP, a more flexible approach may be is storing one node per access log - and use aggregations to calculate stats. This is essentially how most analytics solutions work. After a certain time, ensure you delete / compact the log entries. This will take ups some more indexing space vs updating a node, but generally be more useful.