Skip to content

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

  1. Install Sites analytics with the provider you use:
    composer require drupal/sites_analytics drupal/matomo
    drush en sites_analytics matomo
    
    For Google Tag, use drupal/google_tag and google_tag. Without a provider the status report warns and the site section shows a hint.
  2. Configure the provider as the fallback for every site: Matomo at /admin/config/system/matomo, Google Tag at /admin/config/services/google-tag.
  3. 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.
  4. 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:

  1. On the site type, tick Environment overrides for Disable tracking.
  2. In a site's Analytics section, open the Environments tab.
  3. Click Override next to each test environment and tick Disable tracking on this site.

How environments work: Setting layers.