Matomo Analytics: Storefront and Tracking
Matomo Analytics for Sylius - what is tracked in the storefront, the registered Twig hooks and Twig functions, conversion of order amounts and notes for custom themes
Matomo Analytics: Storefront and Tracking
This documentation always describes the latest published version.
What is tracked
| Event | Where | Matomo call | Toggle |
|---|---|---|---|
| Page view | every storefront page | trackPageView |
main switch of the channel |
| Product view | product page | setEcommerceView with SKU, name and main category |
e-commerce and Track product views |
| Completed order | thank-you page after checkout | addEcommerceItem per line item, then trackEcommerceOrder |
e-commerce and Track completed orders |
| Outbound links and downloads | every storefront page | enableLinkTracking |
Track outbound links and downloads |
| Time on page | every storefront page | enableHeartBeatTimer |
Enable the heartbeat timer |
Product views
The call contains the product code (SKU), the name and the name of the main category. The plugin deliberately reports no price here: no variant is selected on the product page yet, and a wrong default price would be worse than none.
Orders
On the thank-you page the plugin reports every line item with SKU, name, category, price and quantity, and then the order with order number, grand total, subtotal, tax, shipping and discount.
Sylius stores amounts as integers in the smallest unit (cents). The plugin converts them to the major unit based on the number of fraction digits of the order currency, not by a blanket division by 100. For currencies without fraction digits such as JPY the amount therefore stays unchanged. The discount is always reported as a positive number.
All numbers and texts in the generated JavaScript are emitted with json_encode. This guarantees a dot as the decimal separator even if the server runs under a German locale.
What is not tracked
Adding to the cart and quantity changes in the cart are not recorded. The Sylius add-to-cart form is a live component that can change the cart without a page change, and a server-rendered Twig hook cannot see that. The order total is recorded reliably once on the thank-you page instead.
Twig hooks
The plugin registers these hooks itself. The three storefront hooks override no core template, they append additional content. Only the admin hook deliberately replaces the Sylius admin's page title block on the plugin page (priority 100) to show the version:
| Hook | Name | Template | Content |
|---|---|---|---|
sylius_shop.base#javascripts |
mmd_matomo_tracking_code |
shop/tracking_code.html.twig |
Tracking script on every page, with Klaro gating also the consent bridge |
sylius_shop.product.show.content |
mmd_matomo_product_view |
shop/ecommerce/product_view.html.twig |
Product view |
sylius_shop.order.thank_you.content |
mmd_matomo_order_tracking |
shop/ecommerce/order_tracking.html.twig |
Order tracking |
sylius_admin.channel_settings.index.content.header.title_block |
title |
admin/title_block/title.html.twig |
Admin page title with the plugin version |
The two e-commerce hooks have priority -100, so they run after the rest of the page content.
The
#in the hook namesylius_shop.base#javascriptsis part of the name. Write it exactly like this in your own hooks that target this point.
Twig functions
The hooks use these functions, which you can also call in your own templates:
| Function | Returns |
|---|---|
mmd_matomo_config() |
Tracking configuration of the current channel, or null if the channel may not track |
mmd_matomo_tracking_code(config) |
JavaScript for tracker initialisation and page view, without a <script> tag |
mmd_matomo_product_view_code(config, product) |
JavaScript for the product view, empty if the toggle is off |
mmd_matomo_order_tracking_code(config, order) |
JavaScript for the order, empty if the toggle is off |
mmd_matomo_wrap_script(config, code) |
Wraps code in a <script> tag, with Klaro gating in the blocked variant. Empty code yields empty output |
mmd_matomo_plugin_version() |
Installed plugin version: the version number for a tagged release, dev-main@ plus a short hash for a development install, dev if the package is not installed |
Theme compatibility
Because the plugin uses Twig hooks and overrides no templates, it works with themes as long as they keep rendering the hook points sylius_shop.base#javascripts, sylius_shop.product.show.content and sylius_shop.order.thank_you.content. If a theme replaces the base layout or the thank-you page so that a hook point disappears, the corresponding tracking no longer appears.