Keeping long sessions active with client-side tracking
-
Hi, my use-case is an online radio station, where I am using WP Statistics to keep track of how many active listeners we have at any time. This is required for preparing our reports for paying music royalties.
Under earlier versions with server-side tracking, I managed this by periodically hitting a URL handler on our site that called UserOnline::record() while our audio player is playing (code below if it’s relevant). This way, sessions did not expire from users just leaving the page open for long periods of time with the audio player going.
With the new client-side user tracking, is this working as intended? It seems like the new behavior is for the client to hit WPStatistics itself every minute for as long as the window or tab is open… is that correct? Or, is there still a timeout for sessions I need to find a new way to bypass?
Is there a way for me to *stop* the session if they stop listening, but leave the page or tab up?
I’ve observed what seems to be a sharp reduction in active sessions since rolling out user-side tracking, so I’m not entirely sure what’s driving that or what to do about it.
Thanks.
<?php
/*
Plugin Name: Keep Session Alive
*/
add_action('parse_request', 'url_handler');
function url_handler() {
if($_SERVER["REQUEST_URI"] == '/keepalive') {
if (class_exists('WP_STATISTICS\UserOnline')) {
WP_STATISTICS\UserOnline::record();
echo "Keepalive recorded";
}
exit();
}
}
- The topic ‘Keeping long sessions active with client-side tracking’ is closed to new replies.