Matomo Visits does not match Cloudflare visit count

We’re using Cloudflare to cache our websites and Cloudflare shows over 900k visits monthly while Matomo only shows around 200k which is alot of difference. Our Matomo JS tracking code is added in the site via the following code:

And is not embedded directly in the page. We already tried adding the following:

_paq.push([“disableCookies”]);

Which theoretically should boost traffic since basic data on the visits will be logged even before they approve the cookie consent but still no change in traffic. Alot of traffic data is lost because Motomo is only tracking very little traffic data. Also did a test and see if I am seen as a visitor in the real time log but my visit is not being recorded. Used different browsers and my mobile phone but it won’t show my visit. Also used VPN, cleared my browser cache just so it would show that I am in a different location around the world but still won’t track me. We want Matomo to work in a way that it’s showing almost the same data as Cloudflare. Please help.

I think you missed adding the code maybe?

Regarding your issue, I saw something similar on a non-Cloudflare CDN, and the issue was related to the CDN not passing the original server IP and thus Matomo was not seeing real users, was only seeing bots users.

On the other hand, it is possible that Cloudflare shows 900k and amongst those there are bots etc and in Matomo you see the real users even though the difference in numbers is quite big.

I’d check real time in your server log that you are getting the log with the user visiting the website, and what is it seen as in the log.

Also I’d check on a timeframe the server log vs Matomo and see if I have a similar number of hits in terms of bots/users found in the server log side-by-side with Matomo.

And is not embedded directly in the page. We already tried adding the following:
_paq.push([“disableCookies”]);
If you disable cookies, I’d expect you won’t see much data in Matomo about the user.

Also as far as I know, if you have a cookie consent pop up or box, if users don’t click that, that user might not be tracked by Matomo – at least that’s what happens in GA4 from what I can tell.

Let us know how you go and maybe share the JS code you mentioned. Please remove any private information like website, site ID, etc where needed.

Here’s what we have in the actual HTML page.

<script type="text/plain" src="/Config/load-matomo.js"></script>

And here’s what’s in the js file.

var _paq = window._paq = window._paq || [];
  /* tracker methods like "setCustomDimension" should be called before "trackPageView" */
  _paq.push(['disableCookies']);
  _paq.push(['trackPageView']);
  _paq.push(['enableLinkTracking']);
  (function() {
    var u="https://www.mysite.com/piwik/";
    _paq.push(['setTrackerUrl', u+'matomo.php']);
    _paq.push(['setSiteId', '1']);
    var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
    g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
  })();

I actually tried visiting the site myself. cleared all cache and clicked the “Accept Cookies” consent and went to different pages in the site but it did not record my visit. There were no visit logs at the time I was doing the test so it should have picked up my visit.