Last updated August 29, 2013. Created on August 29, 2013.
Edited by DYdave. Log in to edit this page.

Baidu Analytics (百度统计 Baidu Tongji, in Chinese) is Baidu search engine's free web statistics system which provides users with many reports about visitors to their website, such as a report on the source of visitors, user demographics, reports on content viewed on site, a heat map report, and many other features.

For webmasters to make use of Baidu Analytics you would normally need to insert some Javascript containing the unique Baidu Analytics account number (in the format 0123456789abcdef0123456789abcdef, with exactly 32 hexadecimal characters) in to the header or footer of every page.

This could be achieved by editing the Drupal template page.tpl.php. However, this would then mean you cannot run multiple sites from the same base theme template. Not to mention the maintenance of the JavaScript Tracking code if Baidu Analytics API's had to be updated.

This module allows you to enter your Baidu Analytics account number into the modules settings page located at ?q=admin/config/system/baidu_analytics. It will then automatically add the required Javascript to the selected scope of every page generated by Drupal (scope would default to header with the Asynchronous code, footer with the Standard (Legacy) code, or could be overridden).

The Drupal Baidu Analytics module is currently available from the module downloads.

Additional Features

The Drupal module also offers a bit more than basic tracking.

Page tracking

Allows you to provide a list of pages to track, or a list of pages not to track.
@TODO: Add screenshot with comments for pages visibility settings on module's admin settings form page, with the PHP filter enabled.

Role Tracking

Usually Baidu Analytics will track all users on a site, but you can also omit groups of users by Drupal role. Simply un-tick the role name on the settings page.
@TODO: Add screenshot with comments for role tracking on module's admin settings form page.

Profile / User segmentation

Baidu Analytics provides a rough mechanism called "segmentation" to track your users based on data about them.

For every page hit that is logged by Baidu, you can also attach the user roles to it. This can provide a good overview of what type of users visit what pages on your site.

Any fields added to the Users could be added to the tracking though available user tokens. This could further tracking of very valuable information such as the users' gender, the age group or their location!
@TODO: Investigate further integration with Profile 2.

Link tracking

The module provides functionality to track downloads of files, mailto and outgoing links on your site. Select the relevant options on the main Baidu Analytics settings page. A textfield is also provided where you can specify a list of file extensions that should be tracked. Separate each file extension with a '|' character. pdf|zip|doc

To see the link tracking reports, go into your Baidu Analytics dashboard and click on the main Content menu item on the left. That should reveal the Event Tracking option (事件跟踪).
@TODO: Add screenshots with comments for Baidu Analytics Event Tracking link, page and the configuration for link tracking on module's admin settings form page.

Search and Baidu Tuiguang

Allows you to track internal search and track Baidu Tuiguang (百度推广) ads (Tuiguang is not yet provided).
@TODO: Add screenshot with comments for search tracking on module's admin settings form page.

Custom variables

Allows you to send custom variables (自定义变量) along with the Baidu Analytics tracking request. You can use node tokens to populate the value on pages that provide the node object. Otherwise, Global tokens, such as current-user could also be selected and should be defined on every page.
@TODO: Add screenshot with comments for custom variables tracking on module's admin settings form page.

Advanced Settings

Advanced settings for Baidu Analytics are hidden away in the collapsed fieldset. Expand it and you'll find the following additional features.
@TODO: Add screenshot with comments for caching, code snippets on module's admin settings form page. Also add two paragraphs for code type and JS scope.

Cache tracking code

If you find your site pages load slow due to a delay in fetching the Baidu Analytics tracking code file from Baidu's servers - there's the option to cache the hm.js or h.js files locally on your server for a day (86,400 seconds). In order to use this feature your site must be configured to serve public files.

Custom code snippets

If you wish to inject additional custom Baidu Analytics JavaScript code snippets, two textareas is provided to add in code snippets. Just remember to remove the <script> ... </script> tags from the start and end of your snippet! The "before" textarea sets variables prior to the actual trackPageview, then the "after" handles variables, and additional actions (like tracking in multiple accounts).
For advanced Baidu Analytics usage, feel free to take a look at Advanced Baidu Analytics JavaScript Snippets.

Original development of this module sponsored by DAVYIN | 上海戴文.

Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.