• Resolved fkane

    (@fkane)


    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();
    }
    }
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Amir

    (@amirfallah)

    Hi @fkane

    Thank you for opening this thread.

    In Client Side Tracking, you can manage the check times and the sending of online requests from the user’s side using the wp_statistics_reset_user_online_time and wp_statistics_js_check_time_interval filters.

    The link below provides complete explanations and sample codes required for this.
    Customizing User Online Status Intervals

    I hope this can be helpful to you. If you have any questions, please let us know so we can guide you.
    Regards,

    Thread Starter fkane

    (@fkane)

    Thanks, that pointed me in the right direction.

    Looks like the client-side tracking still calls UserOnline::record under the hood, so I just had to set wp_statistics_reset_user_online_time to be slightly more than my own interval hitting that function, and set wp_statistics_js_check_time_interval to something huge to disable WP Statistics’ own client side tracking that was fighting with mine.

    Plugin Support Amir

    (@amirfallah)

    We are glad that your problem has been resolved. If you need any assistance, please let us know.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Keeping long sessions active with client-side tracking’ is closed to new replies.