This project is looking for maintainers. Please see RFC for future of module.
The module includes Google googletagmanager.com/gtag/js
into your project and enables it with config you pass in as options.
- Check the official reference gtagjs
- Add
@nuxtjs/google-gtag
dependency to your project
yarn add @nuxtjs/google-gtag # or npm install @nuxtjs/google-gtag
- Add
@nuxtjs/google-gtag
to themodules
section ofnuxt.config.js
{
modules: [
// Simple usage
'@nuxtjs/google-gtag',
// With options
['@nuxtjs/google-gtag', { /* module options */ }]
]
}
{
modules: [
'@nuxtjs/google-gtag'
],
'google-gtag': {
id: 'UA-XXXX-XX',
config: {
anonymize_ip: true, // anonymize IP
send_page_view: false, // might be necessary to avoid duplicated page track on page reload
linker: {
domains: ['domain.com','domain.org']
}
},
debug: true, // enable to track in dev mode
disableAutoPageTrack: false, // disable if you don't want to track each page route with router.afterEach(...).
additionalAccounts: [{
id: 'AW-XXXX-XX', // required if you are adding additional accounts
config: {
send_page_view: false // optional configurations
}
}]
}
}
Google Analytics property ID.
- Default:
{}
Config options for gtagjs
- Default:
false
Enable to track in dev mode.
- Default:
false
Disable if you don't want to track each page route with router.afterEach(...).
- Default:
[]
You can add more configuration like AdWords
This module includes Google gtag in your NuxtJs project and enables every page tracking by default. You can use gtag inside of your components/functions/methods like follow:
this.$gtag('event', 'your_event', { /* track something awesome */})
As the router code sometimes runs before head data is set correctly you can use following approach to make sure that everything is set correctly:
// make sure to set disableAutoPageTrack: true inside of nuxt.config.js
// inside of your Page.vue/Layout.vue file
mounted() {
if (process.browser) {
this.$gtag('config', 'UA-XXXX-XXX', {
page_title: this.$metaInfo.title,
page_path: this.$route.fullPath,
})
}
}
See official docs:
Install Google Tag Assistant
and see if your page is being tracked.
- Clone this repository
- Install dependencies using
yarn install
ornpm install
- Start development server using
npm run dev
Copyright (c) Nuxt Community