Looking for a view counter plugin without tracking

Hey all,

I’m looking for a ClassicPress plugin that counts how many times a post has been viewed (logged in users excluded), without any sort of tracking that would require opt-in messages. Just a very simple view counter, but that can also show me in the post overview how many times each post has been viewed in total.

I currently use Statify, but that plugin doesn’t really have the features I’m looking for, plus it also deletes stuff after a set period of days (I currently set it to a couple billion days). For me, it’s missing the feature that shows me a total view count per post in the “all posts” view. I would also like to be able to have an option in my front end to show something like the 5 most-read posts as part of such a plugin.

Anyone can recommend me something with these features?

I don’t know of a reliable plugin that does what you want. But I do something similar on a site of my own by adding some code to the mu-plugins folder and adding a small JavaScript library called js-cookie. How comfortable are you adding code snippets, modifying your theme’s functions.php file, and using FTP?

I could make this into a plugin, but I doubt I’ll have the time for at least another couple of weeks.

Ha! This piqued my interest, so I couldn’t resist doing it now! It’s pretty much set-it-and-forget it, but (a) it only works on posts and (b) there’s a shortcode to display the five most popular posts. It’s simply [popular_posts]

If you want to change the formatting that the shortcode produces, just edit the postviews.php file.

kts-post-views.zip (3.3 KB)

I’m perfectly fine with editing my functions.php and stuff like that.

Your plugin sounds interesting, but does it use cookies? That’s what I would like to avoid (because of GDPR reasons) xD

Cookies are the only way to do this. Otherwise, you’ll be recording a view every time someone refreshes the page or goes back to a previous page. Cookies make sure you can set a time before another view by the same user is counted (typically 24hrs).

Not all cookies are bad. (They are, for example, the only way of telling that someone is logged in.) This one stores no data about the user on your site. The sole purpose of it is to identify the fact that the user visited a particular post (and when) if they ever return to that post.

Thanks for the response! And the super quick plugin! :smiley:

I’m aware that cookies can be really useful, but unfortunately I live in cookie consent hell and I try to avoid that as much as possible :sweat_smile: It’s become a pest here in Europe…

Edit: Is there anything I need to do to make the plugin work? I’ve tested it with another browser, but the view count does not seem to update, nor do I see view counts being added to the cp_postmeta table (at least that’s how I gather the plugin works from looking at the code) :thinking:

I live in cookie consent hell too, (I am from Italy) and I can understand your concerns. Be aware however that if the cookie falls in the functional cookie category you can set it, and there is no need to request consent for it (you can mention that you use functional cookies in your privacy policy but the consent for these is implied since the site feature do not work without them).
The cookie used for a counter since it does not store identifying info on the people visiting the site and it’s not used to track marketing preferences can totally fall under the structural cookies the site needs to function.

As mentioned in my previous reply, it doesn’t seem to be working.

Upon investigation, I found this issue:

Uncaught TypeError: Cannot read properties of null (reading 'id')
    at HTMLDocument.<anonymous> (count.js?ver=cp_XXXXXXX:8:50)

How can I fix this?

Edit: Found the issue, my template used <div> instead of <article> for the post id class. However, the database still doesn’t seem to be updating with the view counts :thinking:

On to the next error, which appears in Chrome the first time I load an article, but not in Edge. Reloading in Chrome removes the error (and sets the cookie), but the database is still not updated with view counts.

count.js?ver=cp_XXXXXXX:25 Uncaught ReferenceError: VIEWS is not defined
    at HTMLDocument.<anonymous> (count.js?ver=cp_XXXXXXX:25:9)

I’ll take a look tomorrow. Your theme should really be using the article tag, though. Sure, you could modify my code to target a specific div instead, but missing the article tag means your posts aren’t as semantic as they should be. You should actually be more bothered about this than the cookie issue, because semantics are important for accessibility reasons.

A quick word on counts: if you’re viewing a post while logged in as an administrator, they won’t go up (because obviously that’s not a real view). You could modify the code if you want, but then the numbers will be unreliable.

EDIT: @ElisabettaCarrara is right on the legal point too. This type of cookie falls under “legitimate interest” under the GDPR, and you don’t need anyone’s consent to use it (though you should inform users that you use it).

Yeah, I’m aware of that and that’s good :slight_smile: I tested it with several different browsers (ones where I’m not logged in), and that’s where it didn’t work.

As for the template, I was also surprised that it didn’t use <article> tags and I modified it.

It turned out I had omitted to copy a function from my own site. I’ve added that now. I’ve also modified the code so that it will work regardless of whether a theme is using the article tag or not (just in case anyone else wants to use it or your theme gets updated and reverts the article tag to a div).

kts-post-views.zip (3.3 KB)

It works! :tada:

Thank you so much! :slight_smile:

Great! My pleasure!

The old (5.1.1) version of WordPress Popular Posts works with CP and does exactly that - displays the most popular posts in the sidebar. The example you can see on our site www.PressHill.com.

Cookies are OK but if you want real page views you need to save each visit as post_meta and update on each init of page load. Gist at View: Count the views when someone refreshes or views page. WP

BAsically you save metadata and then get metadata to display count. Practical usage at: Ownership Notice Levels | Gun Alternative

The code I provided does indeed save to metadata!