Track Events in Matomo Using Existing GTM dataLayer Events and Variables
The Matomo Tag Manager (MTM) can use events which are pushed to an existing Google Tag Manager (GTM) dataLayer to track events in Matomo.
A prerequisite is that the event data is pushed to the GTM dayaLayer prior to MTM initialising. Matomo cannot detect changes made to the GTM dataLayer that occur after the initialisation of the Matomo tracking script.
Suppose you have an existing event in GTM that you would like to track in Matomo. The event is the successful completion of an inquiry form. This event is pushed to the GTM dataLayer and appears like this in the console:
Along with the purchase_inquiry
event that was pushed to the dataLayer, specific information including the aircraft manufacturer and model is also available in the form of variables. We can use this additional data to enrich our event in Matomo.
Create a Trigger
In the Matomo Tag Manager, create a Trigger which will fire when the event purchase_enquiry
as seen in the GTM dataLayer:
-
Select Trigger -> Create New Trigger and choose the ‘Custom Event’ Trigger…
-
We’ll name the Trigger « Purchase Inquiry » and set the Event Name field to the name of the event as seen in the GTM dataLayer…
Create a Variable
Next we will create a Variable to capture the aircraft model in order to pass it with the event as the event name:
-
Select Variables -> Create New Variable and choose the ‘Data-Layer’ variable…
-
We’ll name the Variable ‘Model’ and set the « Data Layer Variable Name » field to the name of the
model
variable as seen in the GTM dataLayer…
Create a Tag
Now, create a Tag to fire an event when the Trigger is activated:
-
Select Tags -> Create New Tag and choose the ‘Matomo Analytics’ Tag…
-
In the Tag configuration settings choose Tracking type: Event. Then set the event name to the Model Variable we created previously and set the Trigger to the ‘Purchase Inquiry’ created above…
-
Publish the changes you made in this guide to the Matomo Tag Manager container.
The result
After publishing your changes to the container the Event will be visible in Overview -> Visits Log:
Once reports have been processed the Event will also be included in Behaviour -> Events: