Digiex View Ping 1.0.0 Download - Free Real Page View Tracking Add-on for XenForo 2.3

Nimrod

Dev Ops
Joined
Jun 1, 2007
Messages
1,511
Ever looked at your server logs and wondered how many of those page views were actually people? Most of them aren't. Search engines, AI scrapers, SEO tools and a load of bots that pretend to be a normal browser all fetch your pages, so counting requests tells you very little. Google Analytics doesn't really help either, because loads of people block it.

The thing most bots don't do is run the page and show it. So this add-on puts a tiny script on every page that, once the page is actually on someone's screen, makes one extra request to /misc/v with the page and where they came from. That lands in your access log like everything else. Count those and you're counting pages people really looked at. We use it on Digiex for exactly that.

No cookies, nothing stored in the database, nothing sent to anyone else. It all stays in your own logs.

Free, change it however you like.

Download Digiex-ViewPing-1.0.0.zip


WHAT IT DOES

Adds a few lines of script before the end of every public page. When the page is shown (a page Chrome prerenders that nobody opens doesn't count), it requests:

/misc/v?p=/the/page/&r=where-they-came-from

and gets an empty response back. That's all it does. It doesn't show up in Current visitors, and if a browser blocks it the page works as normal.


INSTALL

XenForo 2.3 only, PHP 8.0 or newer.

Admin CP -> Add-ons -> Install/upgrade from archive, and upload the zip. Or copy the upload folder into your XenForo root and install it from the add-ons list, or from the command line:

php cmd.php xf:addon-install Digiex/ViewPing

It works straight away. To check, open your forum with the browser's developer tools on the Network tab and look for a v?p=... request with status 204.


WORTH DOING: LET THE WEB SERVER ANSWER IT

Out of the box XenForo answers the ping itself. It's quick, it doesn't build a page or run any of the usual checks, but it still starts PHP once more for every page view. If you can edit your web server config, have it answer instead so PHP never sees it. It still gets logged either way.

nginx, in your forum's server block, above the location that passes requests to XenForo:

Code:
location = /misc/v {
    add_header Cache-Control "no-store" always;
    return 204;
}

Apache, in XenForo's .htaccess, just after RewriteEngine On:

Code:
RewriteRule ^misc/v$ - [R=204,L]

If your forum lives in a folder, add that to the path. This needs "Use full friendly URLs" turned on. Without it the ping goes through index.php and XenForo answers it, which is fine too.

If you have a CDN or cache in front, make sure it isn't caching /misc/v. The response says no-store, which most of them respect.


READING THE NUMBERS

There are no reports built in. The data is in a log you already have, so read it however you like. A few to get started with on a normal nginx or Apache log:

Real page views:
Code:
grep -c 'GET /misc/v?' access.log

Everything that asked for a page, without the ping, styles, scripts and images. The gap between this and the one above is roughly your bots:
Code:
grep '"GET ' access.log | grep -v 'GET /misc/v?' | grep -vcE '\.(css|js|png|jpe?g|gif|webp|svg|ico|woff2?|zip|mp4)(\?| )|/css\.php'

Your 30 most viewed pages:
Code:
grep -o 'GET /misc/v?p=[^& ]*' access.log | cut -d= -f2 | sed 's/%2F/\//g' | sort | uniq -c | sort -rn | head -30

Which sites people came from (a blank line is people who typed the address in or used a bookmark):
Code:
grep -o 'GET /misc/v?[^ ]*&r=[^ ]*' access.log | sed 's/.*&r=//; s/%3A/:/g; s/%2F/\//g' | cut -d/ -f3 | sort | uniq -c | sort -rn | head -30

GoAccess or AWStats work as well if you filter them down to the /misc/v lines.


WORTH KNOWING

It isn't proof of a human. A few crawlers do run JavaScript and they'll fire it too. It's a far better count than raw requests, just not a perfect one.

People with JavaScript off or a blocker that stops it won't be counted.

The script goes in PAGE_CONTAINER, so it's in every style. Only public pages are counted, not the Admin CP.

Uninstalling removes the script. If you added the web server rule, take that out yourself, though it does no harm on its own.

There's more detail in the README.md inside the zip. Questions or improvements, post them here.
 

Attachments

About Digiex

Digiex is a technology and gaming forum, founded in 2004 by InsaneNutter and Nimrod. Digiex has served the internet community with breaking news, detailed guides, exclusive downloads and a popular discussion forum. A small, friendly community of like‑minded people has developed over the years. People are encouraged to register and participate in on‑going discussions.

Get Social

Back
Top Bottom