跳转至主内容
Version: 2.0.0-beta.16 🚧

📦 plugin-google-analytics

默认的 Google Analytics 插件。 此 JavaScript 库用于监测用户和您生产环境网站的交互情况。 若您正使用 Google Analytics 4,您可能需要考虑换用 plugin-google-gtag

production only

This plugin is always inactive in development and only active in production to avoid polluting the analytics statistics.

安装

npm install --save @docusaurus/plugin-google-analytics
tip

若您已安装 @docusaurus/preset-classic,您则并不需要安装此依赖。

You can configure this plugin through the preset options.

配置

Accepted fields:

NameTypeDefaultDescription
trackingIDstringRequiredThe tracking ID of your analytics service.
anonymizeIPbooleanfalseWhether the IP should be anonymized when sending requests.

示例配置

You can configure this plugin through preset options or plugin options.

tip

Most Docusaurus users configure this plugin through the preset options.

If you use a preset, configure this plugin through the preset options:

docusaurus.config.js
module.exports = {
presets: [
[
'@docusaurus/preset-classic',
{
googleAnalytics: {
trackingID: 'UA-141789564-1',
anonymizeIP: true,
},
},
],
],
};