Quantcast
Channel: drupal.org - Site administrators
Viewing all articles
Browse latest Browse all 426

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

$
0
0

In rare situations you may like to use different Baidu Analytics Web Property ID's (in the format 0123456789abcdef0123456789abcdef, with exactly 32 hexadecimal characters) on your sites. By adding the below code snippets to your sites sites/default/settings.php you are able to override the Baidu Analytics Web Property ID dynamically.

Change Web Property ID per hostname

[settings.php]

<?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['baidu_analytics_account'] = '0123456789abcdef0123456789abcde0';
    break;

  case
'www.example.org':
   
$conf['baidu_analytics_account'] = '0123456789abcdef0123456789abcde1';
    break;

  default:
   
$conf['baidu_analytics_account'] = '0123456789abcdef0123456789abcde2';
}
?>

 
For Drupal 7, since the Baidu Analytics module integrates with the Variable API, many other solutions could be recommended, for example, with the Context, Variable API and Contextual variables modules, which would allow overridding the Web Property ID depending on the context defined which could vary based on path, URL or any other Context defined conditions. See screenshot of Baidu Analytics added variables below:
@TODO:Add screenshots with comments of the Baidu Analytics variables tab on the variables system page.
 
Caching support with multiple tracking accounts:Locally cache tracking code file
Since the tracker ID is also included in Baidu Analytics JavaScript tracking file, module supports caching per tracker by prefixing saved file on server with the first 7 digits of the Web Property ID.
So for example, cached file names could look like: 0123456-hm.js, 1123456-hm.js, 2123456-h.js, etc.... depending on account tracker and code type configured (Asynchronous or Standard).
See also related feature request: #2076863: Support caching for multiple trackers configured.
 

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

The Baidu Analytics module 7.x-1.x integrates with the Variable API module. It can be modified for different languages like any other system configuration variables, such as site_slogan or site_frontpage.


Viewing all articles
Browse latest Browse all 426

Trending Articles