Advertising sustains the DA. Ads are hidden for members. Join today

Third-party Integration Modules

How to change the Web Property ID per hostname / domain / language

Last updated on
30 April 2025

In rare situations you may like to use different Google Analytics Web Property ID's (UA-1234-1) on your sites. By adding the below code snippets to your sites sites/default/settings.php your are able to override the Google Analytics Web Property ID dynamically.

Change Web Property ID per hostname

[settings.php]

// Override Google Analytics Web Property ID per hostname. 
// Hostnames need to be lower-case!
switch ($_SERVER['HTTP_HOST']) {
  case 'www.example.com':
  case 'www.example.net':
  case 'forum.example.net':
    $conf['googleanalytics_account'] = 'UA-123456-2';
    break;

  case 'www.example.org':
    $conf['googleanalytics_account'] = 'UA-123456-3';
    break;

  default:
    $conf['googleanalytics_account'] = 'UA-123456-1';
}

D7: Change Web Property ID via Internationalization module (i18n), Organic Groups, and additional contexts.

The Google Analytics module 7.x-1.3+ integrates with Variables module. It is possible to create additional Web Property values for the contexts provided in a given Variable Realm. Examples include:

D6: Change Web Property ID with Internationalization module (i18n)

If you are running the Internationalization module you can setup a Web Property ID per language. I18n allows you to have Multilingual Variables. After you add the below code snippet to your settings.php you can go to your Google Analytics settings page and will see This is a multilingual variable. on the end of the Web Property ID description. Now you are able to configure a Web Property ID per language.

[settings.php]

$conf['i18n_variables'] = array (
   'googleanalytics_account',
);

Help improve this page

Page status: Not set

You can: