• Resolved vital14

    (@vital14)


    Hi,

    I’m using the WordPress Popular Posts plugin and want to exclude specific pages (like Privacy Policy) from being tracked in the statistics.

    I tried using filters like wpp_should_track and wpp_pre_update_views, but the pages are still being counted. I also cleared all caches and checked for conflicts with other plugins, but nothing helped.

    Is there a proper way to completely prevent certain pages from being logged in WPP statistics?

    Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Hector Cabrera

    (@hcabrera)

    Hey @vital14,

    Those filter hooks should work AFAIK so please show me how you’re using them so I can have a look.

    Thread Starter vital14

    (@vital14)

    1. wpp_should_track

    function exclude_page_from_tracking($should_track, $post_id) { $excluded_pages = array(4857); // Example page ID to exclude

    if (in_array($post_id, $excluded_pages)) { return false; } return $should_track; } add_filter(‘wpp_should_track’, ‘exclude_page_from_tracking’, 10, 2);


    2. wpp_pre_update_views

    function prevent_wpp_views_update($views, $id) { $excluded_pages = array(4857);

    if (in_array($id, $excluded_pages)) { return 0; } return $views; }

    add_filter(‘wpp_pre_update_views’, ‘prevent_wpp_views_update’, 10, 2);

    I am adding the code using the Code Snippets plugin.!!!!!

    Plugin Author Hector Cabrera

    (@hcabrera)

    Hey @vital14, thanks for sharing your code.

    I’ll correct myself here, my previous comment wasn’t correct:

    • wpp_should_track is not a valid filter hook, it doesn’t exist. Not sure where you got that from 😛
    • wpp_pre_update_views is an action hook, not a filter hook. That code you have there was never going to work in the first place.

    Delete those two code snippets, then try this one out instead:

    /**
    * Excludes specific post/page IDs from WPP's views tracker.
    *
    * @param array $trackable_post_types An array of trackable post types
    * @return array $trackable_post_types An array of trackable post types
    */
    function wpp_exclude_items_from_tracking($trackable_post_types) {
    $excluded_IDs = array(4857);
    $post_ID = get_queried_object_id();

    if ( $post_ID && in_array($post_ID, $excluded_IDs) ) {
    $trackable_post_types = ['donottrack'];
    }

    return $trackable_post_types;
    }
    add_filter('wpp_trackable_post_types', 'wpp_exclude_items_from_tracking', 10);
    Thread Starter vital14

    (@vital14)

    super, it works!!!

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

The topic ‘How to Exclude Specific Pages from WordPress Popular Posts Statistics?’ is closed to new replies.