Run only in production mode

cryptomaniac512
0
cryptomaniac512
commented 2 years ago

Can you provide some option or disable it by default for non-production mode?

0
MatteoGabriele
98
MatteoGabriele
commented 2 years ago

@cryptomaniac512 you can avoid analytics to send data during development, just by setting the debug.sendHitTask property to false ( check debug page )

check the rest of the documentation here

0
cryptomaniac512
0
cryptomaniac512
commented 2 years ago

How can I set sendHitTask to false only if project not in production mode? With this option analytics doesn't work when I run generate.

0
bjunc
114
bjunc
commented 2 years ago

@cryptomaniac512 (and for anyone else who stops by), this is how I ensure tracking events are only sent to GA in production:

// nuxt.config.js
const isProd = process.env.NODE_ENV === 'production'
module.exports = {
  modules: [
    ['@nuxtjs/google-analytics', { id: 'UA-XXXXXX', debug: { sendHitTask: isProd } }]
  ]
}

I use the isProd const elsewhere in the config (proxies, API urls, etc.).

@MatteoGabriele this might be worth documenting in the main README, as it's a very common (if not certain) configuration consideration.

3
MatteoGabriele
98
MatteoGabriele
commented 2 years ago

@bjunc Thanks for sharing this.
To be honest I gave this for granted, but I might gonna add an example right in the Debug section.

Thanks

0
Informations
Question โ€ข Unresolved
#c5 - Created 2 years ago