google-analytics
Integrate Google Analytics into VuePress.
This plugin imports gtag.js to enable Google Analytics 4 tracking.
Usage
npm i -D @vuepress/plugin-google-analytics@next
import { googleAnalyticsPlugin } from '@vuepress/plugin-google-analytics'
export default {
plugins: [
googleAnalyticsPlugin({
// options
}),
],
}
Reporting Events
Google Analytics automatically collects some events, such as page_view
, first_visit
, etc.
If you only need to collect basic site data, simply set the Measurement ID correctly.
After using this plugin, the global gtag()
function is available on the window
object for custom event reporting.
Options
id
Type:
string
Required: Yes
Details:
Google Analytics 4 Measurement ID, which should start with
'G-'
.You can follow the instructions here to find your Measurement ID. Note the difference between Google Analytics 4 Measurement ID ("G-" ID) and Universal Analytics Tracking ID ("UA-" ID).
Example:
export default { plugins: [ googleAnalyticsPlugin({ id: 'G-XXXXXXXXXX', }), ], }
debug
Type:
boolean
Details:
Set totrue
to enable sending events to DebugView. See more information on DebugView.Example:
export default { plugins: [ googleAnalyticsPlugin({ id: 'G-XXXXXXXXXX', debug: true, }), ], }