Matomo, formerly known as Piwik, is an (open-source) web analytics tool that allows users to track website visitors and analyze their behavior. Unlike other tools like Google Analytics, Matomo offers complete control over the collected data because it can be hosted on the user’s own server (on-premise version). Matomo Ecommerce works slightly differently than GA4, for example, with the ability to track product categories. I’ll explain how that works in this blog post!
Want to read more about Matomo?
Curious why Matomo is a valuable addition to GA4? I previously wrote this blog post about it. Want to read more about implementing Matomo or learn about the differences between Matomo and other analytics tools? You can find all our Matomo blog posts here .
Implementation Matomo Ecommerce tracking
When implementing Matomo Ecommerce tracking, a key feature is the ability to track product categories in detail. This allows for more detailed analysis at various category levels. The setEcommerceView function offers flexibility with the categoryName parameter, which can be passed either as a single string or as an array of up to five categories.
String vs. array: when to use which?
A string is a sequence of characters, such as letters, numbers, and symbols, that together form a textual value. In this case, the word: Books
An array is a structured collection of elements of the same type (for example, numbers or strings) that are ordered and can be accessed via an index. Essentially, a string is a special type of array, namely an array of characters. In other words, if you want to use more than one category, it becomes an array.
It is important to use the correct syntax for different scenarios:
For one category only
When tracking one category, use a simple string:

For multiple categories
For products that fall into multiple categories, use an array (number of categories within these characters [ ]):

Note: It’s a common mistake to use an array for a single category (such as ["Boeken"]). This can cause your categories to malfunction in your report. Only use an array when you’re actually using multiple categories. If you don’t use an array [ ], it won’t work either.
Category structure in your reporting
In Matomo, all product categories are combined into a single overview under Ecommerce > Products > Product Category. This differs from GA4, where each category is indicated in a data layer with: item_category, item_category1, etc.
Here’s a challenge: you can’t immediately see what level each category represents in your hierarchy.
The challenge
If you categorize a product as:

Then in Matomo you will see all three categories at the same level in the report, without any direct indication of their hierarchical relationship.

The solution: numbered prefix
An effective strategy is to add a numbered prefix to each category. The advantages of this are:
- You maintain the hierarchical structure in your reporting
- You can easily filter on specific levels
- It makes data analysis and segmentation more powerful
Sample script:

This way, Matomo will have more structure in the different (product) categories.

Practical implementation via GTM
When implementing Matomo through Google Tag Manager, you can use variables to dynamically create categories. Below is an example script for a variable that retrieves dynamic categories. This function dynamically builds an array for multiple categories or returns a single string if there is only one category.
It’s important to create the variable, for example, {{DLV - Category Level 1}}in GTM. To create this, we recommend using a data layer via development.

Optimize analysis and reporting
With the numbered prefixes you can now create advanced segments in Matomo:
- Filter for all level 1 categories with
^1: - Compare conversion rates between main categories
- Analyze how deep into your category structure users navigate before making a purchase
Conclusion
The way you implement categories in Matomo Ecommerce directly impacts the quality and usability of your reporting. By consciously choosing between strings and arrays, and using a numbered prefix system, you create a structured and insightful dataset that enables complex analyses or provides greater insight into the hierarchy of categories.
While it’s not mandatory, consider carefully beforehand how you want to see your category data displayed in Matomo or dashboards to create the right analyses. Need support setting up Matomo? Feel free to contact us; our specialists are happy to help!