📦 plugin-google-tag-manager
用于将 Google 标签管理器(gtm.js)添加到 Docusaurus 站点的插件。与标准的 gtag 插件配合使用,可以深入分析用户如何使用您的站点。
提示
您可以使用 Google 的标签助手 工具检查标签管理器是否设置正确!
仅在生产环境中
此插件在开发环境中始终处于非活动状态,仅在生产环境中激活,以避免污染分析统计数据。
安装
- npm
- Yarn
- pnpm
- Bun
npm install --save @docusaurus/plugin-google-tag-manager
yarn add @docusaurus/plugin-google-tag-manager
pnpm add @docusaurus/plugin-google-tag-manager
bun add @docusaurus/plugin-google-tag-manager
提示
如果您使用预设 @docusaurus/preset-classic
,则无需将此插件作为依赖项安装。
您可以通过预设选项配置此插件。
配置
接受的字段:
名称 | 类型 | 默认值 | 描述 |
---|---|---|---|
containerId | string | 必需 | 您的标签管理器容器 ID(通常以 GTM- 开头)。 |
示例配置
您可以通过预设选项或插件选项配置此插件。
提示
大多数 Docusaurus 用户通过预设选项配置此插件。
- Preset options
- Plugin options
If you use a preset, configure this plugin through the preset options:
docusaurus.config.js
module.exports = {
presets: [
[
'@docusaurus/preset-classic',
{
[translation failure]: {
containerId: 'GTM-12345',
},
},
],
],
};
If you are using a standalone plugin, provide options directly to the plugin:
docusaurus.config.js
module.exports = {
plugins: [
[
'[translation failure]',
{
containerId: 'GTM-12345',
},
],
],
};