Considering some external service such as Jetpack or Google Analytics is option, but there may be scenarios where you may want to handle this just by yourself and have everything more under control.. Since it's very common to utilize some caching mechanism to improve your performance, implementing counter directly on PHP level wouldn't work as counter would be incremeneted due to the caching. Better solution would be to use WordPress way of triggering AJAX requests and increment pageview counters anytime page is loaded, no matter if served from cache or not.. When we start to think on bigger scale though, we find tradional WP AJAX implementation quite resources heavy as well. This plugin uses more complicated method to increase counters, but it's very lightweight. In nuthsell, counters are stored 'outside of WordPress ecosystem into some storage such as Memcached or Redis. Then there's implemented re-occuring cron task on WordPress level, which checks for new counters and store its values as postmeta for each respective post.. Plugin utilizes PhpFastCache library which allows to store data into many types of back-ends. This feature allows you to choose any back-end depending on your hosting provider.. This plugin comes preconfigured with file-based storage, which should work on any hosting environment, but for higher traffic sites you may want to consider in-memory storage such as MemcacheD...
Read more