How to integrate Matomo tracking in Server-side Google Tag Manager (SGTM)
Integrating Matomo with Server-side Google Tag Manager (SGTM) allows you to gain more control over your analytics setup, ensuring data is collected securely and with improved accuracy. By routing tracking data through your own server, you can enhance user privacy, reduce ad blockers’ impact, and maintain better data integrity compared to client-side setups.
This guide walks you through the process of configuring Matomo tracking within SGTM—from setting up the server container client to forwarding data properly to your Matomo instance.
Step 1: Add Matomo Server-side Client template in your Google Server-side container
- Download our client template.
- Log in to Google Tag Manager.
- Open your server-side container.
- Go to Templates.
- In Client Templates, click New.
- Click the ⋯ three-dot icon in the upper right corner and select Import.
- Upload the template you’ve downloaded in step 1.
- Click Save.
- Navigate to Clients.
- Click New.
- Select Matomo Server-side Client for GTM from the list of available templates.
- Enter your Matomo JavaScript URL and Matomo Domain URL.
- Click Submit.
- Click Publish
Step 2: Copy the Google Server Container URL.
- Log in to Google Tag Manager
- Open your server-side container.
- Click Admin section.
- Click Container Settings.
- Copy the Server container URL.
Step 3: Integrate Matomo JavaScript tracking code via Server-side Google Tag Manager (SGTM)
- Navigate to Matomo settings
> Measurables > Tracking Code.
- Select the website to track and copy the code snippet to the clipboard or paste to a text editor to modify the script as needed.
- Replace the Matomo JS URL domain with the Google Server Conatiner URl copied in step 2.
E.g. Replaceg.src='https://cdn.matomo.cloud/testdomain.matomo.cloud/matomo.js
withhttps://{YOUR_SGTM_SERVER_CONTAINER_DOMAIN_NAME}/matomo.js
. - Replace the Matomo tracking domain with the Google Server Conatiner URl copied in step 2.
E.g. Replacevar u="https://3testdomain.matomo.cloud/";
withvar u="https://{YOUR_SGTM_SERVER_CONTAINER_DOMAIN_NAME}/";
. - Embed the updated tracking code in your website.
By integrating Matomo with Server-side Google Tag Manager, you not only gain tighter control over your analytics pipeline but you can also boost tracking reliability and user privacy. Following the steps above ensures that Matomo tracking requests are routed securely through your own infrastructure, offering a robust alternative to traditional client-side tracking methods.