Your recommendation for live traffic software

I've found that google is not capturing everything as it should. Not sure if my plugins are affecting that but my traffic count doesn't make sense. Could be googles new rules that have come out in recent years but I feel with all my articles there should be more traffic.
 
Google Analytics is pretty much all I use these days.
I did have a client who wanted a page counter in his WordPress, but beyond increasing the page count, that's about all it could do. There is no real information as to where the traffic comes from.

If you're unsure if Google Analytics is tracking correctly, you could run a small PHP script in the footer of your site and have it dump visits to a text file. Then using Shell, you can use a "tail -n filename.txt" and see every time a page is loaded.

I've not personally found the count from Google Analytics to be off, but you may try a shell script.

Here's a simple function; feel free to expand.

Add the following to your functions.php file in your child-theme:

PHP:
function log_page_visits() {
    $current_url = $_SERVER['REQUEST_URI'];
    $user_ip = $_SERVER['REMOTE_ADDR'];
    $log_file = WP_CONTENT_DIR . '/wp-uploads/page_visits.log';
    $log_info = date('Y-m-d H:i:s') . " | URL: " . $current_url . PHP_EOL;
    file_put_contents($log_file, $log_info, FILE_APPEND | LOCK_EX);
}

Then add this to the footer of your template to trigger the function call:

PHP:
log_page_visits();

This will get the URL path and the IP address of the user and log it to the /wp-uploads/ folder. You can then use the shell to tail the command and measure in real-time. The reason I have it going to the wp-uploads folder is that this folder should be non-executable or viewable to normal users.
 
Top