📦 plugin-google-gtag
The default Global Site Tag (gtag.js) plugin. これは、Googleアナリティクス、Google広告、および Googleマーケティングプラットフォームにイベントデータを送信できるJavaScriptタグ付けフレームワークおよび API です。 このセクションでは、Google Analytics のグローバルサイトタグ (gtag. js) を有効にする方法を説明します。
You can use Google's Tag Assistant tool to check if your gtag is set up correctly!
This plugin is always inactive in development and only active in production to avoid polluting the analytics statistics.
インストール
- npm
- Yarn
- pnpm
- Bun
npm install --save @docusaurus/plugin-google-gtag
yarn add @docusaurus/plugin-google-gtag
pnpm add @docusaurus/plugin-google-gtag
bun add @docusaurus/plugin-google-gtag
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.
設定
Accepted fields:
| 名前 | Type | Default | 説明 |
|---|---|---|---|
trackingID | string | string[] | Required | gtagサービスの追跡ID。 複数のIDを与えることも可能です。 |
anonymizeIP | boolean | false | リクエストを送信するときにIPを匿名化するかどうか。 |
Example configuration
このプラグインは、プリセットオプションまたはプラグインオプションを通じて設定できます。
Most Docusaurus users configure this plugin through the preset options.
- プリセットオプション
- プラグイン
プリセットを使用する場合は、 設定オプション を介してこのプラグインを設定してください。
module.exports = {
presets: [
[
'@docusaurus/preset-classic',
{
gtag: {
trackingID: 'G-999X9XX9XX',
anonymizeIP: true,
},
},
],
],
};
スタンドアロンプラグインを使用している場合は、プラグインに直接オプションを指定します。
module.exports = {
plugins: [
[
'@docusaurus/plugin-google-gtag',
{
trackingID: 'G-999X9XX9XX',
anonymizeIP: true,
},
],
],
};