Skip to main content
Version: 3.7.0

📦 plugin-google-analytics

默认的 谷歌分析 插件。它是一个 JavaScript 库,用于衡量用户在生产版本中如何与你的网站交互。如果你使用的是 Google Analytics 4,你可能需要考虑使用 plugin-google-gtag

¥The default Google Analytics plugin. It is a JavaScript library for measuring how users interact with your website in the production build. If you are using Google Analytics 4 you might need to consider using plugin-google-gtag instead.

已弃用

此插件已弃用,并于 2023 年 7 月 1 日变得无用。

¥This plugin is deprecated and became useless on July 1, 2023.

谷歌是 远离通用分析

¥Google is moving away from Universal Analytics.

如果你仍在使用带有 UA-* 跟踪 ID 的此插件,你应该尽快创建一个 Google Analytics 4 账户,并使用 @docusaurus/plugin-google-gtag 而不是此插件。更多细节 此处

¥If you are still using this plugin with a UA-* tracking id, you should create a Google Analytics 4 account as soon as possible, and use @docusaurus/plugin-google-gtag instead of this plugin. More details here.

仅限生产

该插件在开发中始终处于不活动状态,仅在生产中处于活动状态,以避免污染分析统计数据。

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

安装

¥Installation

npm install --save @docusaurus/plugin-google-analytics
提示

如果你使用预设 @docusaurus/preset-classic,则无需安装此插件作为依赖。

¥If you use the preset @docusaurus/preset-classic, you don't need to install this plugin as a dependency.

你可以通过 预设选项.conf 配置该插件。

¥You can configure this plugin through the preset options.

配置

¥Configuration

接受的字段:

¥Accepted fields:

名称类型默认描述
trackingIDstring必需的你的分析服务的跟踪 ID。
anonymizeIPbooleanfalse发送请求时 IP 是否应该匿名。

配置示例

¥Example configuration

你可以通过预设选项或插件选项配置此插件。

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

提示

大多数 Docusaurus 用户通过预设选项配置此插件。

¥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,
},
},
],
],
};