VuePress EcosystemVuePress Ecosystem
  • Theme Guidelines
  • theme-default
  • Hope Theme
  • Plume Theme
  • Reco Theme
  • Feature Plugins
  • Markdown Plugins
  • Search Plugins
  • Blog Plugins
  • PWA Plugins
  • Analytics Plugins
  • SEO Plugins
  • Development Plugins
  • Tool Plugins
  • AI Plugins
  • @vuepress/helper
  • English
  • 简体中文
GitHub
  • Theme Guidelines
  • theme-default
  • Hope Theme
  • Plume Theme
  • Reco Theme
  • Feature Plugins
  • Markdown Plugins
  • Search Plugins
  • Blog Plugins
  • PWA Plugins
  • Analytics Plugins
  • SEO Plugins
  • Development Plugins
  • Tool Plugins
  • AI Plugins
  • @vuepress/helper
  • English
  • 简体中文
GitHub
  • baidu-analytics
  • google-analytics
  • umami-analytics

google-analytics

@vuepress/plugin-google-analytics

Integrate Google Analytics into VuePress.

This plugin will import gtag.js for Google Analytics 4.

Usage

npm i -D @vuepress/plugin-google-analytics@next
.vuepress/config.ts
import { googleAnalyticsPlugin } from '@vuepress/plugin-google-analytics'

export default {
  plugins: [
    googleAnalyticsPlugin({
      // options
    }),
  ],
}

Reporting Events

Google Analytics will automatically collect some events, such as page_view, first_visit, etc.

So if you only want to collect some basic data of your site, you don't need to do anything else except setting the Measurement ID correctly.

After using this plugin, the global gtag() function is available on the window object, and you can use it for custom events reporting.

Options

id

  • Type: string

  • Details:

    The Measurement ID of Google Analytics 4, which should start with 'G-'.

    You can follow the instructions here to find your Measurement ID. Notice the difference between Google Analytics 4 Measurement ID (i.e. "G-" ID) and Universal Analytics Tracking ID (i.e. "UA-" ID).

  • Example:

    .vuepress/config.ts
    export default {
      plugins: [
        googleAnalyticsPlugin({
          id: 'G-XXXXXXXXXX',
        }),
      ],
    }

debug

  • Type: boolean

  • Details:

    Set to true to enable sending events to DebugView. See more information on DebugView.

  • Example:

    .vuepress/config.ts
    export default {
      plugins: [
        googleAnalyticsPlugin({
          id: 'G-XXXXXXXXXX',
          debug: true,
        }),
      ],
    }
Edit this page on GitHub
Last Updated:: 4/12/25, 7:03 PM
Contributors: Mister-Hope
Prev
baidu-analytics
Next
umami-analytics