Search code examples
matomo

How to remove the reloaded pages in matomo segment?


when using matomo, the reloaded pages are taken into account to count the actions and visits. Is there a way to remove this from the reports (with segment for exemple), without having to change the javascript tags ? Thanks for your help,


Solution

  • While there is no built-in way to remove page reloads from your analytics, there are a few approaches that will allow you to separate analytics from reloads from the others.

    The easiest to implement would be to add a parameter to your URL in case your page is reloaded. This can be done with PerformanceNavigationTiming.type. Here's an example:

    const observer = new PerformanceObserver((list) => {
      list.getEntries().forEach((entry) => {
        if (entry.type === "reload") {
            var url = new URL(window.location.href);
            url.searchParams.set('reload', 'true');
            window.history.replaceState({}, '', url);
        }
      });
    });
    
    observer.observe({ type: "navigation", buffered: true });
    

    Then, you create a segment that does not take into account traffic from these URLs.

    Another way of doing this would be to only take into account traffic where Pageviews is less or equal to 1. But this is not optimal, because you wouldn't be able to track people that simply accessed your website multiple times.

    Which approach you choose will depend on what exactly you want, but, to be blunt, no, there is no built-in way to do that.