Evan Genest's Learning Log

These are notes to myself. If you discover them and find them useful I would love to hear from you. Most of these are related to travel I did, books I read, or tech notes for Matomo and the LAMP stack.


Browse my topics here

The Data Object

web analyticsmatomo

The object

In Matomo, the data layer is a Javascript object named _mtm.

This object is used to store and push data for tracking purposes, similar to how other analytics platforms (like Google Tag Manager) utilize a data layer.

By pushing information into the _mtm object, you can pass various data points to Matomo for tracking user interactions, events, and custom variables.

Here is an example of the code you would use to interact with the _mtm object in Matomo:

_mtm.push({ 'event': 'customEventName', 'customVariable': 'customValue' });

Matomo Tag Manager automatically syncs this _mtm object with the gtm data layer object. However if you do not want this to happen, you can turn it off. In the admin settings of Matomo there is a checkbox to do that.

The structure of the MTM Object

I tried to see the object by opening the browser >> devtools >> console. It showed me that _mtm contains this:

[
{
"mtm.startTime": 1730805033367,
"event": "mtm.Start"
},
{
"mtm.startTime": 1730805033368,
"event": "mtm.Start"
}
]

When I asked the console to show _mtm, it returned the following, which looks weird to me because

I honestly don't know the answer. I can say that I got it fro a page that has TWO containers. Maybe that Matomo puts the object in an array and that allows there to be multiple containers? I do know that we get a few emails from folks who organizer their tags by making 2, 3, even 7 containers per page. Maybe an array is how Matomo stores those.

What are examples of allowed values?

Here again is a typical script you might use:

_mtm.push({ 'event': 'customEventName', 'customVariable': 'customValue' });

The allowed values for properties like 'event' and custom properties such as 'customVariable' can be strings, numbers, or even complex objects depending on what you want to track.

  1. Event Tracking ('event' key):

_mtm.push({ 'event': 'click' });
_mtm.push({ 'event': 'newsletterSignup' });
  1. Custom Variables or Dimensions ('customVariable', 'customDimension', etc.):
_mtm.push({
'event': 'productView',
'productID': '12345',
'productCategory': 'Electronics',
'orderValue': 299.99,
'isSale': true
});

_mtm.push({
'event': 'pageScroll',
'scrollDepth': 50,
'pageSection': 'Reviews'
});