Tzz.Dev

VuePressのGoogleアナリティクス設定方法

この記事を読むのに必要な時間は約1分です。

VuePressの公式プラグインに@vuepress/plugin-google-analyticsがあります。

このプラグインを使って、Google Analytics 4の設定ができます。

設定方法は下記となります。

  1. インストール
    yarn add -D @vuepress/plugin-google-analytics@next
    
  2. 設定ファイル修正(/docs/.vuepress/config.ts
    1
    2
    3
    4
    5
    6
    7
    8
    9
    
    import { googleAnalyticsPlugin } from '@vuepress/plugin-google-analytics'
    
    export default defineUserConfig({
        plugins: [
            googleAnalyticsPlugin({
                id: 'G-XXXXXXXXXX',
            }),
        ],
    })
    

以上。