Skip to content

Commit

Permalink
fix: disable on dev unless specified
Browse files Browse the repository at this point in the history
  • Loading branch information
pooya parsa committed Feb 17, 2019
1 parent a38083f commit 63e22e5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Differences between vue-analytics and the Nuxt.js implementation:

- The router instance is already added out of the box (read [here](https://github.com/MatteoGabriele/vue-analytics/blob/master/docs/page-tracking.md#disable-page-auto-tracking) if you need to disable it)
- The `id` and `ua` properties have the exact same behaviour. The `ua` property has been added for backwards compatibily with previous releases
- You can enable module for development by setting `dev: true` option in module options

## Development

Expand Down
24 changes: 15 additions & 9 deletions lib/module.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
const { resolve } = require('path')

function analyticsModule(moduleOptions) {
// Turn off during development
const defaults = {
debug: {
sendHitTask: !this.options.dev
}
}

const options = {
...{},
...defaults,
debug: {
sendHitTask: undefined
},
...this.options['google-analytics'],
...moduleOptions
}

// Dev mode
if (this.options.dev) {
// Disable unless dev: true specified for module option
if (!options.dev) {
return
}
// Disable sendHitTask
if (options.debug.sendHitTask === undefined) {
options.debug.sendHitTask = false
}
}

// see https://github.com/nuxt-community/analytics-module/issues/2
if (options.ua) {
options.id = options.ua
Expand Down

0 comments on commit 63e22e5

Please sign in to comment.