Skip to content
This repository was archived by the owner on Mar 21, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions __tests__/lib/event.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ window.ga = jest.fn()
let $vm

beforeEach(() => {
window.ga.mockClear()

Vue.use(VueAnalytics, {
id: 'UA-1234-5'
})
Expand Down
2 changes: 2 additions & 0 deletions __tests__/lib/exception.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ window.ga = jest.fn()
let $vm

beforeEach(() => {
window.ga.mockClear()

Vue.config.errorHandler = jest.fn()

Vue.use(VueAnalytics, {
Expand Down
2 changes: 2 additions & 0 deletions __tests__/lib/page.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ window.ga = jest.fn()
let $vm

beforeEach(done => {
window.ga.mockClear()

Vue.use(VueRouter)

const router = new VueRouter({
Expand Down
2 changes: 2 additions & 0 deletions __tests__/lib/require.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ window.ga = jest.fn()
let $vm

beforeEach(() => {
window.ga.mockClear()

Vue.use(VueAnalytics, {
id: 'UA-1234-5'
})
Expand Down
2 changes: 2 additions & 0 deletions __tests__/lib/set.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ window.ga = jest.fn()
let $vm

beforeEach(() => {
window.ga.mockClear()

Vue.use(VueAnalytics, {
id: 'UA-1234-5'
})
Expand Down
2 changes: 2 additions & 0 deletions __tests__/lib/social.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ window.ga = jest.fn()
let $vm

beforeEach(() => {
window.ga.mockClear()

Vue.use(VueAnalytics, {
id: 'UA-1234-5'
})
Expand Down
2 changes: 2 additions & 0 deletions __tests__/lib/time.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ window.ga = jest.fn()
let $vm

beforeEach(() => {
window.ga.mockClear()

Vue.use(VueAnalytics, {
id: 'UA-1234-5'
})
Expand Down
43 changes: 24 additions & 19 deletions src/lib/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,11 @@ export default function page (...args) {
}

if (route) {
const {
router,
autoTracking: {
transformQueryString,
prependBase
}
} = config

const queryString = getQueryString(route.query)
const base = router && router.options.base
const needsBase = prependBase && base

let path = route.path + (transformQueryString ? queryString : '')
path = needsBase ? getBasePath(base, path) : path

set('page', path)
query('send', 'pageview')
trackRoute(route)
} else {
set('page', args[0].page)
// We can call with `page('/my/path')`
let page = typeof args[0] === 'object' ? args[0].page : args[0]
set('page', page)
query('send', 'pageview', ...args)
}
}
Expand All @@ -68,7 +54,26 @@ export function trackRoute (route) {
return
}

page(proxy ? proxy(route) : route)
if (proxy) {
page(proxy(route))
} else {
const {
router,
autoTracking: {
transformQueryString,
prependBase
}
} = config

const queryString = getQueryString(route.query)
const base = router && router.options.base
const needsBase = prependBase && base

let path = route.path + (transformQueryString ? queryString : '')
path = needsBase ? getBasePath(base, path) : path

page(path)
}
}

export function autoTracking () {
Expand Down