How to track Google Tag Manager Events in Matomo
If you are tracking events in Google Tag Manager (GTM), you can send the event data to Matomo to analyse visitor interactions on your website. This allows capturing and reporting on relevant events without needing to duplicate your tracking setup in both tag manager systems. For more advanced use cases, explore the GTM data layer integration.
This guide explains how to track Google Tag Manager Events in Matomo. The example configurations do not require additional setup within Matomo Tag Manager. All you need is an active Matomo instance with the MTM container code added to your website.
Set up Link Click tracking in Google Tag Manager
In this configuration, the Matomo tag sends event data to Matomo when visitors click on a specific link. While the GTM data layer may store event data, GTM relies explicitly on the information defined in the tag to send data to Matomo.
- In Google Tag Manager, go to your workspace and add the Matomo Analytics Tag from the community gallery.
- For the tag to send event data to your Matomo instance, enter your Instance URL, Matomo Site ID, and the Analytics domains (the website you are tracking).
- Select Event Tracking as the Tag Action.
- Define the Event as you want it to appear in your Matomo Behaviour > Events reports.
- For this example, the Event is defined as:
Event Category: GTM Link Clicks
Event Action: Click Links
Event Name:{{Click Text}}
to display the link’s text and distinguish between the different links clicked. - Next, add the Click Trigger named Just Links.
- Test and publish your Google Tag Manager container.
- When successfully set up, clicks on all links recorded in Google Tag Manager will be sent to Matomo for reporting.
Add Trigger Conditions (optional)
To further refine the event data to include only specific links clicked, you could modify the Click – Just Links Trigger in GTM to only fire on defined conditions.
- In the trigger configuration, select the Some Link Clicks option to indicate when the trigger should fire. This displays the fields to define the conditions, e.g., only send events where
Click Text
containsorder
. The Click Text variable is an auto-event variable in GTM.
- Test and publish your Google Tag Manager container.
- When successfully set up, GTM will send data to Matomo only for those Link Click events that match the trigger condition, e.g., clicks on links containing the word
order
.
Set up Button Click tracking in Google Tag Manager
Button click event tracking in GTM allows you to monitor user interactions like clicks on a Sign Up button and send the data to Matomo. By defining trigger conditions, such as the button’s CSS selector or unique identifier, you can capture key details like the button text or ID in Matomo.
- In Google Tag Manager, go to your workspace and add the Matomo Analytics Tag from the community gallery.
- For the tag to send event data to your Matomo instance, enter your Instance URL, Matomo Site ID, and the Analytics domains (the website you are tracking).
- Select Event Tracking as the Tag Action.
- Define the Event as you want it to appear in your Matomo Behaviour > Events reports.
- For this example, the Event is defined as:
Event Category: Registrations
Event Action: Click Button
Event Name: Sign Up -
Next, add the Click Trigger named All Elements.
-
Define the trigger conditions using the button’s CSS selector or other unique identifier specific to the button, e.g.,
Click ID
containssignup
. Use GTM’s built-in variables to capture relevant data.
- Save your changes and test your setup before publishing the live GTM container.
Test and Publish
Test your Google Tag Manager container to ensure that clicks on specified buttons or links are being recorded in GTM and sent to Matomo for reporting. You can check the following in your GTM workspace to validate your testing:
- Enable Preview Mode in GTM and navigate to your website. Click the target button or link and verify that the GTM triggers fire and sends the expected data.
- Check the variables (e.g., Click ID, Click Text) are correctly capturing the relevant data.
- Ensure the Matomo tag is properly configured with the required tracking details (e.g., Matomo instance details, event name, category, or other event data).
- Open your browser’s Developer Tools > Network tab to confirm a request is made to your Matomo instance and it includes the correct event parameters (e.g., action name, category).
- Log in to your Matomo instance to check your testing actions are displaying in the Visits in real-time report.
- Once testing is successful, publish the changes in GTM to make the tracking live.
These steps ensure that both GTM and Matomo are functioning as expected to track button and link click events.