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

Commit cefabee

Browse files
Merge pull request #128 from mwaldstein/master
Bug fixes to page (route tracking with pageviewTempland and strings) and tests (clear test pollution)
2 parents 667bb43 + ae923bb commit cefabee

File tree

8 files changed

+38
-19
lines changed

8 files changed

+38
-19
lines changed

__tests__/lib/event.spec.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ window.ga = jest.fn()
66
let $vm
77

88
beforeEach(() => {
9+
window.ga.mockClear()
10+
911
Vue.use(VueAnalytics, {
1012
id: 'UA-1234-5'
1113
})

__tests__/lib/exception.spec.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ window.ga = jest.fn()
66
let $vm
77

88
beforeEach(() => {
9+
window.ga.mockClear()
10+
911
Vue.config.errorHandler = jest.fn()
1012

1113
Vue.use(VueAnalytics, {

__tests__/lib/page.spec.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ window.ga = jest.fn()
3030
let $vm
3131

3232
beforeEach(done => {
33+
window.ga.mockClear()
34+
3335
Vue.use(VueRouter)
3436

3537
const router = new VueRouter({

__tests__/lib/require.spec.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ window.ga = jest.fn()
66
let $vm
77

88
beforeEach(() => {
9+
window.ga.mockClear()
10+
911
Vue.use(VueAnalytics, {
1012
id: 'UA-1234-5'
1113
})

__tests__/lib/set.spec.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ window.ga = jest.fn()
66
let $vm
77

88
beforeEach(() => {
9+
window.ga.mockClear()
10+
911
Vue.use(VueAnalytics, {
1012
id: 'UA-1234-5'
1113
})

__tests__/lib/social.spec.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ window.ga = jest.fn()
66
let $vm
77

88
beforeEach(() => {
9+
window.ga.mockClear()
10+
911
Vue.use(VueAnalytics, {
1012
id: 'UA-1234-5'
1113
})

__tests__/lib/time.spec.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ window.ga = jest.fn()
66
let $vm
77

88
beforeEach(() => {
9+
window.ga.mockClear()
10+
911
Vue.use(VueAnalytics, {
1012
id: 'UA-1234-5'
1113
})

src/lib/page.js

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,11 @@ export default function page (...args) {
2525
}
2626

2727
if (route) {
28-
const {
29-
router,
30-
autoTracking: {
31-
transformQueryString,
32-
prependBase
33-
}
34-
} = config
35-
36-
const queryString = getQueryString(route.query)
37-
const base = router && router.options.base
38-
const needsBase = prependBase && base
39-
40-
let path = route.path + (transformQueryString ? queryString : '')
41-
path = needsBase ? getBasePath(base, path) : path
42-
43-
set('page', path)
44-
query('send', 'pageview')
28+
trackRoute(route)
4529
} else {
46-
set('page', args[0].page)
30+
// We can call with `page('/my/path')`
31+
let page = typeof args[0] === 'object' ? args[0].page : args[0]
32+
set('page', page)
4733
query('send', 'pageview', ...args)
4834
}
4935
}
@@ -68,7 +54,26 @@ export function trackRoute (route) {
6854
return
6955
}
7056

71-
page(proxy ? proxy(route) : route)
57+
if (proxy) {
58+
page(proxy(route))
59+
} else {
60+
const {
61+
router,
62+
autoTracking: {
63+
transformQueryString,
64+
prependBase
65+
}
66+
} = config
67+
68+
const queryString = getQueryString(route.query)
69+
const base = router && router.options.base
70+
const needsBase = prependBase && base
71+
72+
let path = route.path + (transformQueryString ? queryString : '')
73+
path = needsBase ? getBasePath(base, path) : path
74+
75+
page(path)
76+
}
7277
}
7378

7479
export function autoTracking () {

0 commit comments

Comments
 (0)