baidu-analytics
This plugin integrates Baidu Analytics (Baidu Tongji) into your VuePress site, allowing you to track visitor traffic and user interactions.
Tips
Please disable the SPA mode in your Baidu Analytics settings.
This plugin automatically handles page view reporting on route changes. Enabling Baidu's built-in SPA mode may result in duplicate data or incorrect statistics.
Usage
npm i -D @vuepress/plugin-baidu-analytics@nextimport { baiduAnalyticsPlugin } from '@vuepress/plugin-baidu-analytics'
export default {
plugins: [
baiduAnalyticsPlugin({
// options
}),
],
}Event Tracking
Once configured, the plugin will automatically report page view (PV) events for both initial page loads and subsequent route navigations.
For advanced usage, the global _hmt array is exposed on the window object. You can utilize this to push custom events manually.
// Example: Manually reporting a custom event
window._hmt = window._hmt || []
window._hmt.push(['_trackEvent', 'category', 'action', 'label', 'value'])Options
id
- Type:
string - Required: Yes
- Details: The tracking ID for your Baidu Analytics account. This is usually the string found in the
hm.jsscript URL provided by Baidu (e.g.,hm.js?your_tracking_id).
