• Resolved MaxByer

    (@maxbyer)


    What would make this plugin awesome is a way to exclude my own visits from the count. For example, similar plugins allow you to add a cookie so you are not counted even when logged out. Perhaps I am just missing that setting?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Mostafa Soufi

    (@mostafas1990)

    Hi,

    Good news: yes, WP Statistics can exclude your own visits. You will find the options under Statistics > Settings > Exclusions.

    There are two ways to do it, depending on whether you are logged in:

    1. While you are logged in – In the Filtering & Exceptions section at the top, tick “Exclude” next to your role (for example Administrator). Any visit from a logged-in user with that role is then skipped.
    2. While you are logged out – Add your own IP address to the “Excluded IP Address List” on the same page. This is the closest match to what you described and does not rely on you being logged in. You can add a single IP or a range, one per line. To find your current IP, search “what is my IP” on Google.

    One caveat with the IP method: many home and office connections use a dynamic IP that changes from time to time, so if your visits reappear, recheck your IP and update the list (or add the wider range your provider uses).

    To be transparent: WP Statistics does not currently have the cookie based “exclude this browser” toggle that some other plugins offer. The IP exclusion above is the built-in equivalent for excluding yourself while logged out.

    Tip: if you enable “Record Exclusions” on the same page, you can see excluded hits and the reason, which is a quick way to confirm it is working.

    Hope that helps. Let me know if anything is unclear.

    Best

      Thread Starter MaxByer

      (@maxbyer)

      Unfortunately my IP changes very often so your plugin IP exclude solutions is no help, Im using Independent Analytics which offers exclude browser cookie, however when you do get a similar solution you can update us.

      Plugin Author Mostafa Soufi

      (@mostafas1990)

      Hi MaxByer,

      Thanks for the honest feedback, and I understand the dynamic IP problem. I wanted to follow up, because WP Statistics can actually do the cookie-based exclusion you were after. It is not a one-click setting yet, so here is how to set it up.

      WP Statistics has an exclusion filter you can hook into. Add this small snippet (via your theme’s functions.php or a code-snippets plugin):

      php
      // 1) Exclude any visitor who has the opt-out cookie (works logged out, any IP)
      add_filter('wp_statistics_exclusion', function ($exclude, $visitorProfile) {
          if (!empty($_COOKIE['wp_statistics_optout'])) {
              return ['exclusion_match' => true, 'exclusion_reason' => 'Self opt-out (cookie)'];
          }
          return $exclude;
      }, 10, 2);
      
      // 2) Set that cookie when you visit yoursite.com/?wpstatistics_optout=1
      add_action('init', function () {
          if (isset($_GET['wpstatistics_optout'])) {
              setcookie('wp_statistics_optout', '1', time() + YEAR_IN_SECONDS, '/');
          }
      });
      

      Then, in each browser you want excluded, visit your site once with ?wpstatistics_optout=1 on the end of the URL (for example https://yoursite.com/?wpstatistics_optout=1). From then on that browser is excluded from your stats, even when logged out and even if your IP changes, which is exactly the behavior you were after.

      To confirm it is working, turn on Record Exclusions under Statistics → Settings → Exclusions, and you will see the excluded hits logged as “Self opt-out (cookie)”.

      We are also looking at making this a built-in option so it does not need any code. Thanks for pushing on it, and you are welcome back any time.

      Best

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

    You must be logged in to reply to this topic.