Skip to content
This repository was archived by the owner on Mar 21, 2025. It is now read-only.

Commit d0fe78c

Browse files
fix: remove logs as errors
there's no need to crash the application for missing parameters or plugin errors
1 parent e1775b3 commit d0fe78c

File tree

5 files changed

+12
-29
lines changed

5 files changed

+12
-29
lines changed

__tests__/bootstrap.spec.js

-16
This file was deleted.

src/bootstrap.js

+5-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { promisify, loadScript, shouldGaLoad } from './helpers'
1+
import { promisify, loadScript, shouldGaLoad, log } from './helpers'
22
import config, { update } from './config'
33
import createTrackers from './create-trackers'
44
import collectors from './collectors'
@@ -16,9 +16,8 @@ export default () => {
1616
const resource = config.customResourceURL || `https://www.google-analytics.com/${filename}.js`
1717

1818
if (!config.id) {
19-
throw new Error(
20-
'[vue-analytics] Missing the "id" parameter. Add at least one tracking domain ID'
21-
)
19+
log('Missing the "id" parameter. Add at least one tracking domain ID')
20+
return
2221
}
2322

2423
const queue = [
@@ -29,11 +28,7 @@ export default () => {
2928
if (shouldGaLoad()) {
3029
queue.push(
3130
loadScript(resource).catch(() => {
32-
throw new Error (
33-
'[vue-analytics] An error occured! Please check your connection, ' +
34-
'if you have any Google Analytics blocker installed in your browser ' +
35-
'or check your custom resource URL if you have added any.'
36-
)
31+
log('An error occured! Please check your connection or disable your AD blocker')
3732
})
3833
)
3934
}
@@ -66,6 +61,6 @@ export default () => {
6661
return
6762
}
6863

69-
console.error(error.message)
64+
log(error.message)
7065
})
7166
}

src/create-trackers.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import set from './lib/set'
22
import query from './lib/query'
33
import config, { getId } from './config'
4-
import { getTracker } from './helpers'
4+
import { log, getTracker } from './helpers'
55

66
export default function createTrackers () {
77
if (!window.ga && config.debug.enabled) {
8-
throw new Error('[vue-analytics] Google Analytics has probably been blocked.')
8+
log('Google Analytics has probably been blocked.')
9+
return
910
}
1011

1112
if (!window.ga) {

src/helpers.js

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ import config, { getId } from './config'
22

33
export function noop () {}
44

5+
export const log = message => {
6+
console.warn(`[vue-analytics] ${message}`)
7+
}
8+
59
export function loadScript (url) {
610
return new Promise((resolve, reject) => {
711
var head = document.head || document.getElementsByTagName('head')[0]

src/lib/exception.js

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ export const autotracking = Vue => {
2626
exception(error.message)
2727

2828
if (config.autoTracking.exceptionLogs) {
29-
console.error(`[vue-analytics] Error in ${info}: ${error.message}`)
3029
console.error(error)
3130
}
3231

0 commit comments

Comments
 (0)