the users screen includes the column 'visits'. It lists the number of visits but I would like to know how it is calculated?
1 Answer
how it is calculated?
It isn't, WordPress itself doesn't track user visits.
The column you're referring to will have been added by a plugin. If you're hosting your site on WordPress.com then this will be Jetpack Stats.
Otherwise you'll need to ask the plugin vendor how this is done, or possibly even your theme vendor if its responsible, as each vendor uses a different mechanism. WordPress itself offers no system for tracking or saving this data so a one size fits all answer is not possible.
Note however that:
- a lot of visitor counting plugins store counts in the database, making them extremely unreliable due to race conditions, leading to undercounting. They also don't distinguish unique visitors, or track when they visited.
- most visitor counting plugins don't deal with caching or CDNs either
- the best solution is always going to be code that integrates with dedicated visitor analytics software, be that software on your server or a 3rd party analytics.
- this is because to store this data reliably you have to store and handle things in particular ways or they'll be unreliable.
- There are lots of hidden tradeoffs that aren't mentioned when storing and using visitor counts. E.g. how quickly do you want the count to update vs how fast and how cachable you want your pages to be, etc