My first post here.
How can I force Cloudflare not to cache Matomo? I searched these and other forums and only found this:
Here’s the code I was using:
// Required variables
$matomoSiteId = 1; // Site ID
$matomoUrl = "https://analytics.mydomain.com"; // Your matomo URL
$matomoToken = "removed"; // Your authentication token
// Optional variable
$matomoPageTitle = ""; // The title of the page
// Load object
// Matomo object
$matomoTracker = new MatomoTracker((int)$matomoSiteId, $matomoUrl);
// Set authentication token
// Track page view
Thanks for your help.
Assuming you do the serverside tracking inside the page code itself the only thing you can do is to not do any caching on the pages. An alternative way of serverside tracking is requesting a seperate “page” that does the server side tracking and exclude that URL from caching in cloudflare.
Thanks for replying.
The above code I have pasted in the header template (so it’s on all pages).
Based on what you stated, if I tell Cloudflare to ignore
PiwikTracker.php URLs paths. Would that solve the issue? Or is it more complex than adding ignore-cache page rules?
If the page is cached by Cloudflare… then your server doesn’t even know the page has loaded.
That’s exactly the point in having a CDN!!
You simply cannot have both the benefits of PHP server side tracking AND the benefits of a CDN like Cloudflare.
Do server side tracking on your server, or client side with Cloudflare.
IMO there’s no reliable alternative here.
Except for Cloudflare Analytics (that’s essentially based upon Cloudflare’s logs) but that’s another thing.