• Resolved genauder

    (@genauder)


    Hello,

    is it possible to exclude certain pages and posts from the statistic? Perhabs with the Pro version?

    Best regards

    Sven

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author Rogier Lankhorst

    (@rogierlankhorst)

    You can use a filter in the wp-config.php:
    https://burst-statistics.com/how-to-exclude-pages-from-tracking-in-burst/

    let me know if you have any questions!

    Thread Starter genauder

    (@genauder)

    Thank you very much! Actually I want to exclude the front page which is obviously classified as “/” by Burst Statistics. So I guess the “str_contains” is probably not the right approach?

    Plugin Author Rogier Lankhorst

    (@rogierlankhorst)

    $sanitized_data[‘page_url’] contains the page slug, $url contains the entire URL. So you can either compare $url with your domain, or check

    if (empty( $sanitized_data[‘page_url’]) {}

    Which is what I would do I think.

    Thread Starter genauder

    (@genauder)

    Thank you for the suggestion. When doing it that way unfortunately the site is not working anymore and visitors get HTTP error 500.

    function set_referrer_to_spammer( $sanitized_data ) {
    $url = $sanitized_data['host'] . $sanitized_data['page_url'];
    if (empty($sanitized_data['page_url']) {
    //we use a trick, by setting the referrer to spammer, this page won't get tracked.
    $sanitized_data['referrer'] = 'spammer';
    }
    return $sanitized_data;
    }
    add_filter( 'burst_before_track_hit', 'set_referrer_to_spammer' );

    Is this correct?

    Plugin Author Rogier Lankhorst

    (@rogierlankhorst)

    You’re missing one closing parenthesis, this should work:

    function set_referrer_to_spammer( $sanitized_data ) {
                $url = $sanitized_data['host'] . $sanitized_data['page_url'];
                if (empty($sanitized_data['page_url']) ) {
                    //we use a trick, by setting the referrer to spammer, this page won't get tracked.
                    $sanitized_data['referrer'] = 'spammer';
                }
                return $sanitized_data;
            }
            add_filter( 'burst_before_track_hit', 'set_referrer_to_spammer' );
    Thread Starter genauder

    (@genauder)

    Thank you, it seems to work!

    Plugin Author Rogier Lankhorst

    (@rogierlankhorst)

    Great to hear! If you run into any issues, let me know!

    If you appreciated the support, it would be great if you can leave a review here:

    https://ww.wp.xz.cn/support/plugin/burst-statistics/reviews/#new-post

    Thanks!

    Rogier

    Thread Starter genauder

    (@genauder)

    Hello, unfortunately the start page is still being recorded by Burst Statistics. This is the code in wp-config.php:

    function set_referrer_to_spammer( $sanitized_data ) {
    $url = $sanitized_data['host'] . $sanitized_data['page_url'];
    if (empty($sanitized_data['page_url']) ) {
    //we use a trick, by setting the referrer to spammer, this page won't get tracked.
    $sanitized_data['referrer'] = 'spammer';
    }
    return $sanitized_data;
    }
    add_filter( 'burst_before_track_hit', 'set_referrer_to_spammer' );

    Is anything wrong with that? Thank you!

    Plugin Author Rogier Lankhorst

    (@rogierlankhorst)

    I just ran the code, I made a mistake. When you visit the domain, the page_url is ‘/’, not empty. So it should be:

    function set_referrer_to_spammer($sanitized_data)
    {
        $url = $sanitized_data['host'] . $sanitized_data['page_url'];
        if ($sanitized_data['page_url'] === '/' ) {
            error_log('mark as spam: ' . $url);
            error_log("slug: " . $sanitized_data['page_url']);
            //we use a trick, by setting the referrer to spammer, this page won't get tracked.
            $sanitized_data['referrer'] = 'spammer';
        } else {
            error_log('Not marked as spam: ' . $url);
            error_log("slug: " . $sanitized_data['page_url']);
        }
        return $sanitized_data;
    }
    add_filter('burst_before_track_hit', 'set_referrer_to_spammer');

    This will add some logging statements. You can then see in the debug.log

    – if the code runs
    – which URLS and slugs get marked as spam, and which not.

    If you still have issues, can you post the resulting debug log here? Then we can see what is happening.

    If all is running as it should, you can remove the lines with error_log again.

    Thread Starter genauder

    (@genauder)

    I will test this and get back to you, thanks again.

Viewing 10 replies - 1 through 10 (of 10 total)

The topic ‘Exclude pages and posts’ is closed to new replies.