Configure tracking consent for Matomo on Shopify
Website owners are responsible for their website’s compliance with privacy laws, including collecting and retaining a log of their visitors’ valid tracking consent where required.
Shopify provides a native customer privacy framework and cookie banner. However, it does not automatically control third-party analytics platforms such as Matomo. To manage consent for Matomo, use a consent management solution that integrates with Shopify’s Customer Privacy API.
Do not enable both the Shopify native cookie banner and a third-party consent manager at the same time, as this can result in conflicting consent signals.
Using Shopify’s Customer Privacy API
This guide explains how to use Shopify’s Customer Privacy API and a consent management platform to enable or disable Matomo tracking based on visitor consent.
The Cookiebot app is used as an example to manage the visitor’s consent banner, while the Customer Privacy API makes the visitor’s consent status available to the Matomo custom pixel. The pixel then enables or disables tracking based on the visitor’s analytics consent.
The same approach can be adapted for other consent management solutions that integrate with Shopify’s Customer Privacy API.
Before you start
Ensure the following prerequisites are place:
- Set up the custom pixel for Matomo and check that Matomo is successfully tracking. Refer to the guides on installing the Matomo tracking code on Shopify or installing with Matomo Tag Manager.
- Note your Matomo site ID and tracking URL as this is required for the setup process below.
Install and configure a consent manager
- Log in to your Shopify store as an administrator.
- Install your preferred consent management app from the Shopify App Store.
- Complete the app’s setup and configure the consent banner according to your privacy requirements.
- To embed the app in your Shopify theme, go to your Online Store and click Edit theme.
- Click on App embeds and check your consent manager app is enabled.
- Verify that the consent banner appears on your storefront.
Register the Matomo cookies
Configure your consent manager so that the Matomo tracking cookies are categorised as Statistics (or the equivalent analytics category used by your consent manager). Cookiebot can detect these cookies automatically during a website scan, or you can add them manually if required.
Most consent management platforms group Matomo cookies under a Statistics or Analytics category. This category is presented to visitors in the consent banner.
The Matomo custom pixel should determine whether tracking is allowed by reading Shopify’s Customer Privacy API (analyticsProcessingAllowed) rather than by checking a consent category directly.
Modify the Matomo custom pixel
Update your Matomo custom pixel so that tracking only starts after the visitor has granted analytics consent.
- In Shopify, go to Settings and open Customer Events.
- Click on the Matomo custom pixel to edit.
- Update the code to prevent Matomo from sending tracking requests until consent granted.
The example in this guide uses Shopify’s Customer Privacy API to determine whether analytics tracking is permitted.
The Matomo custom pixel reads the value of analyticsProcessingAllowed and enables or disables tracking accordingly. If using the sample script below, replace https://YOUR-MATOMO-URL.com/ and YOUR_SITE_ID with your Matomo instance URL and site ID:
var _paq = window._paq = window._paq || [];
// Prevent Matomo from sending tracking requests until
// Shopify confirms that analytics processing is allowed.
_paq.push(['requireConsent']);
_paq.push(['enableLinkTracking']);
(function () {
var u = 'https://YOUR-MATOMO-URL.com/';
_paq.push(['setTrackerUrl', u + 'matomo.php']);
_paq.push(['setSiteId', 'YOUR_SITE_ID']);
var d = document;
var g = d.createElement('script');
var s = d.getElementsByTagName('script')[0];
g.async = true;
g.src = u + 'matomo.js';
s.parentNode.insertBefore(g, s);
})();
var currentMatomoConsent = null;
function applyMatomoConsent(isAllowed) {
isAllowed = isAllowed === true;
if (currentMatomoConsent === isAllowed) {
return;
}
currentMatomoConsent = isAllowed;
if (isAllowed) {
_paq.push(['setConsentGiven']);
return;
}
_paq.push(['forgetConsentGiven']);
_paq.push(['deleteCookies']);
}
// Apply the consent state available when the pixel loads.
applyMatomoConsent(
init.customerPrivacy.analyticsProcessingAllowed
);
// Update Matomo when the visitor changes their consent.
api.customerPrivacy.subscribe(
'visitorConsentCollected',
function (event) {
applyMatomoConsent(
event.customerPrivacy.analyticsProcessingAllowed
);
}
);
// Subscribe to Shopify customer events below this point.
Verify consent applied before tracking
After updating your custom pixel, verify that Matomo only tracks visitors who granted analytics consent.
- Open your Shopify store and the browser’s developer tools.
- Go to the Application (or Storage) tab to inspect cookies.
- Open the Network tab and filter requests by
matomo.php. - Test the following scenarios:
- No consent given: No Matomo tracking requests should be sent and no Matomo cookies should be created.
- Analytics consent granted: Matomo tracking should begin when the visitor next performs an action covered by the custom pixel, such as navigating to another page. The
_pk_idand_pk_sesMatomo cookies are then created. - Analytics consent revoked: Matomo should stop sending tracking requests. Existing Matomo cookies should be removed.
- Reload the page: The visitor’s consent choice should persist. If analytics consent was granted, tracking should continue after the page reload. If consent was denied, no tracking requests or cookies should be present.
- Complete a test order and verify that the transaction appears in the Ecommerce Log report in Matomo.
Troubleshooting
Work through the following checks if Matomo does not respond to the visitor’s consent choice.
The consent banner does not appear
- Confirm that the consent manager app is active in your Shopify theme.
- Do not enable both Shopify’s native banner and a third-party consent manager.
- For Cookiebot, verify that the Domain Group ID configured in Shopify matches the ID in the Cookiebot manager. An incorrect ID can prevent the banner from loading.
Tracking starts before consent
Confirm that the following call appears before any Matomo tracking methods or Shopify event subscriptions:
_paq.push(['requireConsent']);
Requests such as trackPageView must not run before Matomo has been configured to require consent.
Tracking does not start after consent is granted
Confirm that the custom pixel reads init.customerPrivacy.analyticsProcessingAllowed and subscribes through:
api.customerPrivacy.subscribe(
'visitorConsentCollected',
function (event) {
applyMatomoConsent(
event.customerPrivacy.analyticsProcessingAllowed
);
}
);
- Do not call
customerPrivacy.subscribe()directly. Shopify exposes the Customer Privacy API throughapi.customerPrivacy. - Tracking starts when the visitor next performs an action covered by a Shopify event subscription. Granting consent alone may not send a Matomo request.
Next steps
After confirming that tracking works correctly, use the Matomo Ecommerce reports to analyse visitor behaviour and optimise your Shopify store. Monitor revenue, conversion rate, abandoned carts, and identify your best-selling products. Read more about data measured with Ecommerce tracking.
Disclaimer: The use of any third-party tools (plugins, extensions, platforms, APIs, widgets, etc.) is at your own risk. Matomo does not own, control, maintain or support any third-party tools that integrate with our product. We recommend checking your privacy setup is correctly configured across your environment when using any third-party tools.