Exclude recurring user by matomo ID

Is it possible to exclude a recurring user (for example by ID).

I couldn’t find it how it could work, but I can’t believe this isn’t possible. Matomo already notices that a specific user revisits the page multiple times. So the connection between the user and the data in matomo is already there.

How can I remove this user now from my statistics?

We have a static IP and this traffic is not saved already, but users in the homeoffice don’t have a static IP, so it’s not really an option to block it by IP.
I know I could use the cookie, but I think this is more work for me to set up individually.

Thanks!

1 Like

Do you use MTM or classical JavaScript tracking?

Classic JS tracking.

So just a code like this could work:

<!-- Matomo -->
<script type="text/javascript">
  var _paq = window._paq = window._paq || [];
  if(userId !== 'the ID to exclude') {
    _paq.push(['trackPageView']);
    _paq.push(['enableLinkTracking']);
    (function() {
      var u="//{$MATOMO_URL}/";
      _paq.push(['setTrackerUrl', u+'matomo.php']);
      _paq.push(['setSiteId', {$IDSITE}]);
      var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
      g.type='text/javascript'; g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
    })();
  }
</script>
<!-- End Matomo Code -->

Great! I will try that, thanks!
Any suggestion for multiple IDs? Multiple if’s? Or better to loop through an array?

function track(id) {
  var ids=['id1', 'id2', 'id3'];
  for(var i = 0; i < ids.length; id++) {
    if(id == ids[i]) {
      return false;
    }
  return true;
  }
}

var _paq = window._paq = window._paq || [];
if(track(userId)) {
  _paq.push(['trackPageView']);
  _paq.push(['enableLinkTracking']);
  (function() {
    var u="//{$MATOMO_URL}/";
    _paq.push(['setTrackerUrl', u+'matomo.php']);
    _paq.push(['setSiteId', {$IDSITE}]);
    var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
    g.type='text/javascript'; g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
  })();
}

Thank you. I did some testing now. It seems like tracking in general does not work anymore now.

I tried the single ID method and your latest.

I checked everything. When I comment out the if statement and only leave the part inbetween it tracks as it should.

Do you see any error in the console?

Well, should have checked that. userId is not defined.
I try the first one again and look for errors there

In both cases userId is not defined

userId is the one of your current user!

Not sure what you mean.

The variable is not defined. I entered my ID. But it seems like the matomo script has no connection to this variable.

Somewhere, if you track the user ID, you should have it.
Then put the user ID there…

What are you talking about?

There was some spams in the discussion…
@jonalange do you want to remove user ID (ie user who are connected to your app) or visitors that receive a visitor ID by Matomo?

Visitors. When I visit the page I get an ID which I can see in the matomo backend.

I want to remove a visitor from the statistics with that ID.

Sorry, I though you wanted to exclude some user that you could identify by its ID.
The only solution I see is using segments in Matomo:
(combine AND operators and filter on visitorID)

If you wants to exclude permanently some users, use the Adminitration>Privacy>GDPR tool:

But you’ll have to do this each time…

How can you know some users have to be removed?

I asked my co workers to click though the page in a specific order. By this I could detect who they are in matomo and got their ID.

See:

Well, yes. I already know that article. But the only option here is cookies as I said in my post because my co workers don’t have a static IP. And because the cookie thing is too much work to do for each of them (remote desktop, login to matomo, get the cookie) I would like to “block” them by their matomo ID what my question is all about.

As the visitor ID can change (if your colleague uses another browser or browses in private mode, and also probably randomly after some time), this would be difficult to manage client side…
Also visitor ID is an internal ID of Matomo, not designed to be used client side I think…

If you know the users you want to exclude, I think you can just send them to the link provided by the Administration>Privacy>Users opt-out feature (just copy/paste the link), and this should work without any effort!