Need ability to disable in development

robyedlin
56
robyedlin
commented a year ago

I don't see a config to disable this module in development. Current workaround is to set the env var as UA-000000-1, but this is not ideal.

With missing GA code, the following error returns in development:

client.js:533 [nuxt] Error while initializing app Error: [vue-analytics] Please enter a Google Analytics tracking ID
    at A (http://localhost:3000/_nuxt/vendor.js:19078:4201)
    at I (http://localhost:3000/_nuxt/vendor.js:19078:5605)
    at Function.Vue.use (http://localhost:3000/_nuxt/vendor.js:28179:14)
    at _callee$ (http://localhost:3000/_nuxt/app.js:1270:58)
    at tryCatch (http://localhost:3000/_nuxt/vendor.js:2017:40)
    at Generator.invoke [as _invoke] (http://localhost:3000/_nuxt/vendor.js:2251:22)
    at Generator.prototype.(anonymous function) [as next] (http://localhost:3000/_nuxt/vendor.js:2069:21)
    at step (http://localhost:3000/_nuxt/vendor.js:1832:30)
    at http://localhost:3000/_nuxt/vendor.js:1850:14
    at new Promise (<anonymous>)
0
MatteoGabriele
95
MatteoGabriele
commented a year ago

You can set debug.sendHitTask to false and it will not send anything to your domain

https://github.com/MatteoGabriele/vue-analytics/blob/master/docs/debug.md

0
stuartjnelson
0
stuartjnelson
commented a year ago

I couldn't get this to work. I was hoping I didn't have to pass a valid tracking code on development. This is my config;

['@nuxtjs/google-analytics', {
    id: process.env.NODE_ENV === 'production' ? process.env.GOOGLE_ANALYTICS : false,
    debug: {
        sendHitTask: process.env.NODE_ENV === 'production',
    }
}]
0
robyedlin
56
robyedlin
commented a year ago

What error is it giving you? It wants a code.

I set an env UA-000000-1 for dev.

0
stuartjnelson
0
stuartjnelson
commented a year ago

Thanks for SUPER fast reply @robyedlin.

This is the error I was getting;
screen shot 2018-03-24 at 19 41 06

That is a sweet solution! Solved my error. Thanks for your help!

0
robyedlin
56
robyedlin
commented a year ago

๐Ÿ‘ You can also use @MatteoGabriele 's suggestion: https://github.com/nuxt-community/analytics-module/issues/10#issuecomment-370054625, but I prefer not to fiddle with the config in this case.

0
lukas-pierce
0
lukas-pierce
commented 8 months ago

you can use spread ... operator

const isProd = process.env.NODE_ENV === 'production';
const analyticsModule = isProd ?  ['@nuxtjs/google-analytics', {id: 'YOUR-TRACKING-ID'}] : null;

modules: [
  //other modules
  ...(analyticsModule ? [analyticsModule] : [])
  //other modules
]
0
Informations
Question โ€ข Unresolved
#c9 - Created a year ago