Blog

Use a tagging server URL as the analytics endpoint for self-hosted Matomo

Matomo accepts a custom tracker URL. Pointing it at sGTM gives you the same first-party benefits Matomo deserves.

Matomo (formerly Piwik) is a popular self-hosted analytics tool, especially for EU teams who want to keep all data on their own infrastructure. Routing Matomo hits through your sGTM tagging server gives you the same ad-blocker resistance as for GA4, with the added benefit of a single tagging endpoint for everything.

Configure Matomo to use the custom URL

In your Matomo tracker code, override the trackerUrl:

var _paq = window._paq || [];
_paq.push(['setTrackerUrl', 'https://data.example.com/matomo']);
_paq.push(['setSiteId', '1']);
_paq.push(['trackPageView']);

Matomo will now POST hits to data.example.com/matomo instead of your Matomo server URL.

In sGTM, add a Custom Client for Matomo

There is no built-in Matomo client in the sGTM gallery. Write a Custom Client that listens on /matomo, parses the request, and re-emits it for tags to consume.

const path = getRequestPath();
if (path !== '/matomo') return;
const body = getRequestBody();
const params = parseUrl('?' + body).searchParams;
claimRequest();
runContainer({
  event_name: params.action_name || 'matomo_hit',
  url: params.url,
  user_id: params.uid
});
returnResponse();

Forward to your Matomo server

Add a Custom Tag that forwards the original request to your actual Matomo installation. This is essentially a proxy with the addition that any other tags in your sGTM container can also fire on the same event.

sendHttpRequest('https://matomo.example.com/matomo.php', {
  method: 'POST',
  body: getEventData('original_body'),
  headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
});

When this is worth doing

If you self-host Matomo specifically because you do not want third-party analytics, putting an extra hop in front of it is consistent with that goal. Your Matomo server never receives requests directly from browsers; the tagging server filters, anonymises, and forwards.

If you run Matomo on a managed Matomo Cloud, the custom tracker URL pattern still works but the data residency benefit is smaller; the Matomo Cloud provider already handles the requests through their own infrastructure.

As of 2026 SprTags has discontinued its native Matomo product, but the sGTM-as-proxy pattern works for any Matomo deployment.