Set a different Google Tag ID per language/domain

Created on 6 March 2025, 3 months ago

Is it possible when having two different two Google Tag ID's (one for each language/domain) to set the active Google Tag ID per language/domain?

E.g. something like below in settings.php or some hook?

if (\Drupal::languageManager()->getCurrentLanguage()->getId() == 'de') {
  $config['google_tag.settings']['container_id'] = 'GTM-FOR-DE';
} elseif (\Drupal::languageManager()->getCurrentLanguage()->getId() == 'en') {
  $config['google_tag.settings']['container_id'] = 'GTM-FOR-EN;
}

If not, is the domain module working properly with this module to achieve that?

Thanks for any guidance...

💬 Support request
Status

Active

Version

2.0

Component

Code

Created by

🇳🇱Netherlands undersound3

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @undersound3
  • 🇳🇱Netherlands undersound3

    To answer my own question...

    I discovered that I can enable multiple containers

    - go to admin/config/services/google-tag/settings and enable "Allow multiple Tag Containers"
    - add another container with the other GTM ID
    - under each of your containers under Conditions use the Language tab to select which GTM ID will be active for which language

    To use a domain for conditions install the domain module, add your domains and a new tab will appear under your GTM container and you can select which GTM ID must be active on which domain.

Production build 0.71.5 2024