跳到主要内容

Google Tags

You can use Google tags to track how users are using your website.

plugin-google-gtag

plugin-google-gtag allows you to send event data to Google Analytics, Google Ads, and Google Marketing Platform. To begin with:

  1. Go to Google Tag Assistant, click Add domain, and input your website's URL. After this, you will obtain your trackingID formatted as G-xxxxxxxxxx.

  2. Go to your project's root and run yarn add @docusaurus/plugin-google-gtag to install the plugin-google-gtag plugin.

  3. Configure the plugin in your docusaurus.config.js file as follows (replace G-999X9XX9XX with the value you obtained from Step 1):

    module.exports = {
    plugins: [
    [
    '@docusaurus/plugin-google-gtag',
    {
    trackingID: 'G-999X9XX9XX',
    anonymizeIP: true,
    },
    ],
    ],
    };

plugin-google-tag-manager

You can use this plugin in conjunction with gtag for in-depth analysis of how users are using your site.

  1. Go to Google Tag Assistant, click Add domain, and input your website's URL. After this, you will obtain your containerId formatted as GTM-xxxxx.

  2. Go to your project's root and run yarn add @docusaurus/plugin-google-tag-manager to install the plugin-google-tag-manager plugin.

  3. Configure the plugin in your docusaurus.config.js file as follows (replace GTM-12345 with the value you obtained from Step 1):

    module.exports = {
    plugins: [
    [
    '@docusaurus/plugin-google-tag-manager',
    {
    containerId: 'GTM-12345',
    },
    ],
    ],
    };
警告

These two plugins are only active in production.