Google GTag for Nuxt.js
npm install @nuxtjs/google-gtag> Google official gtagjs for Nuxt.js
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 gtag
@nuxtjs/google-gtag dependency using yarn or npm to your project@nuxtjs/google-gtag to modules section of nuxt.config.js``js
{
modules: [
// Simple usage
'@nuxtjs/google-gtag',
// With options
['@nuxtjs/google-gtag', { / module options / }],
]
// example config
'google-gtag':{
id: 'UA-XXXX-XX', // required
config:{
  // this are the config options for gtag
// check out official docs: https://developers.google.com/analytics/devguides/collection/gtagjs/
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(...)
// optional you can add more configuration like AdWords
additionalAccounts:[{
id: 'AW-XXXX-XX', // required if you are adding additional IDs
config:{
send_page_view:false // optional configurations
}
}]
}
}
``
This module inlcudes 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 /})
Install Google Tag Assistant and see if your page is being tracked.
- Clone this repository
- Install dependencies using yarn install or npm installnpm run dev`
- Start development server using
Copyright (c) Dominic Garms