Skip to main content
Version: 3.5.1

📦 plugin-google-tag-manager

用于将 Google 跟踪代码管理器 (gtm.js) 添加到 Docusaurus 站点的插件。将此插件与标准 gtag 插件 结合使用,可以深入分析用户如何使用你的网站。

¥A plugin for adding Google Tag Manager (gtm.js) to a Docusaurus site. Use this plugin in conjunction with the standard gtag plugin for in-depth analysis of how users are using your site.

提示

你可以使用 谷歌的标签助手 工具检查标签管理器是否设置正确!

¥You can use Google's Tag Assistant tool to check if tag manager is set up correctly!

仅限生产

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

¥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-tag-manager
提示

如果你使用预设 @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:

名称类型默认描述
containerIdstring必需的你的跟踪代码管理器容器 ID(通常以 GTM- 开头)。

配置示例

¥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',
{
googleTagManager: {
containerId: 'GTM-12345',
},
},
],
],
};