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

Commit 7e48f05

Browse files
author
Matteo Gabriele
committed
feat(bootstrap): add config set array
instead of calling the beforeFirstHit callback and set manually each field the developer needs, it is now possible to just write an array of field/value pairs to set before the first hit
1 parent d76d85f commit 7e48f05

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

src/add-setters.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import set from 'lib/set'
2+
import config from './config'
3+
4+
export default function addSetters () {
5+
config.set.forEach(({ field, value }) => {
6+
if (typeof field === 'undefined' || typeof value === 'undefined') {
7+
throw new Error(
8+
'[vue-analytics] Wrong configuration in the plugin options.\n' +
9+
'The "set" array requires each item to have a "field" and a "value" property.'
10+
)
11+
}
12+
13+
set(field, value)
14+
})
15+
}

src/bootstrap.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import load from 'load-script'
22
import { onAnalyticsReady, hasGoogleScript } from './helpers'
33
import config, { update } from './config'
44
import createTrackers from './create-trackers'
5+
import addSetters from './add-setters'
56
import untracked from 'lib/untracked'
67
import { startAutoTracking as pageAutoTracking } from 'lib/page'
78
import { startAutoTracking as exceptionAutoTracking } from 'lib/exception'
@@ -35,6 +36,7 @@ export default function bootstrap () {
3536
.then(() => onAnalyticsReady())
3637
.then(() => {
3738
createTrackers()
39+
addSetters()
3840
ready()
3941
exceptionAutoTracking()
4042
pageAutoTracking()

src/config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ const defaultConfig = {
77
ignoreRoutes: [],
88
linkers: [],
99

10+
set: [],
11+
1012
autoTracking: {
1113
exception: false,
1214
page: true,

0 commit comments

Comments
 (0)