Analytics¶
Give each site its own Matomo and Google Tag ids.
Needs Sites analytics
Part of Sites analytics.
Matomo and Google Tag keep rendering the tracking code; Sites analytics replaces the ids they read with the ids of the current site. A site that leaves an id empty uses the global one. Consent banners and cookie compliance are outside Sites analytics; set them up with a module of their own.
Set up¶
- Install Sites analytics with the provider you use:
For Google Tag, use
composer require drupal/sites_analytics drupal/matomo drush en sites_analytics matomodrupal/google_tagandgoogle_tag. Without a provider the status report warns and the site section shows a hint. - Configure the provider as the fallback for every site: Matomo at
/admin/config/system/matomo, Google Tag at/admin/config/services/google-tag. - With Google Tag, a site's ids replace those of one tag container. When no container exists, Sites analytics creates Sites analytics for it. If you have one already, set its machine name as the default of Google Tag container on each site type.
- Fill in each site's ids in its Analytics section
(
/admin/sites/{site}/analytics, System group of the site dashboard). It takes Manage site settings on the site; the fields are listed in Site settings.
Keep test environments out¶
The analytics settings can differ per environment. To track production only:
- On the site type, tick Environment overrides for Disable tracking.
- In a site's Analytics section, open the Environments tab.
- Click Override next to each test environment and tick Disable tracking on this site.
How environments work: Setting layers.