Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a reliable and robust page view counter in a web application?

I want to count the visits on a web page, and this page represents an element of my model, just like the Stack Overflow question page views.

How to do this in a reliable (one visit, one pageview, without repetitions) and robust (thinking on performance, not just a new table attribute 'visits_count')

like image 885
Cipriani Avatar asked Mar 01 '23 00:03

Cipriani


1 Answers

You can't.

  • Multiple people can visit your site from the same IP (makes ip storage useless)
  • Multiple people can visit your site from the same PC
  • Multiple people can visit your site from the same browser (makes cookies useless)

The closest you can get is to store the visitors IP in combination with a cookie to not count those in the future. Here is a tradeoff, if they clear the cookie, they are a new visitor. If you only store the IP, you count whole proxies as one visitor.

Another option is to use user accounts and track exactly which user viewed what page, but this is not really a good option for public sites.

like image 111
TomHastjarjanto Avatar answered Apr 26 '23 21:04

TomHastjarjanto