跳到主要内容
版本:Canary 🚧

📦 plugin-google-analytics(弃)

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

Deprecated

此插件已弃用,并将于 2023 年 7 月 1 日失效。

谷歌正在远离通用分析。

如果你还在用UA-*跟踪 id 使用这个插件,你应该尽快创建一个谷歌分析 4 帐户,并使用@docusaurus/plugin-google-gtag代替这个插件。更多细节在这里。

只生产

这个插件在开发中总是不活跃的,并且只在生产中活跃,以避免污染分析统计。

安装​

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

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

You can configure this plugin through the preset options.

配置​

接受字段:

名字类型默认描述
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.

提示

Most Docusaurus users configure this plugin through the preset options.

如果使用预设,请通过预设选项配置此插件:

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