Skip to content
This repository has been archived by the owner on Jun 12, 2024. It is now read-only.

Commit

Permalink
Merge pull request #128 from mwaldstein/master
Browse files Browse the repository at this point in the history
Bug fixes to page (route tracking with pageviewTempland and strings) and tests (clear test pollution)
  • Loading branch information
MatteoGabriele authored May 21, 2018
2 parents 667bb43 + ae923bb commit cefabee
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 19 deletions.
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

0 comments on commit cefabee

Please sign in to comment.