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

Commit

Permalink
fix(page): pageview resolved before routes ready
Browse files Browse the repository at this point in the history
closes #267
  • Loading branch information
MatteoGabriele committed Dec 28, 2019
1 parent 809f633 commit cc858f7
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions src/lib/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,28 +85,26 @@ export function autoTracking () {
return
}

if (autoTracking.pageviewOnLoad && router.history.ready) {
trackRoute(router.currentRoute)
}
router.onReady(() => {
if (autoTracking.pageviewOnLoad && router.history.ready) {
trackRoute(router.currentRoute)
}

config.router.afterEach(function (to, from) {
const { skipSamePath, shouldRouterUpdate } = autoTracking
router.afterEach(function (to, from) {
const { skipSamePath, shouldRouterUpdate } = autoTracking

// Default behaviour of the router when the `skipSamePath` is turned on.
// Skip router change when current and previous route have the same path
// https://github.com/MatteoGabriele/vue-analytics/issues/73
if (skipSamePath && to.path === from.path) {
return
}
// Default behaviour of the router when the `skipSamePath` is turned on.
// Skip router change when current and previous route have the same path
// https://github.com/MatteoGabriele/vue-analytics/issues/73
if (skipSamePath && to.path === from.path) {
return
}

// Adds a custom way to define when the router should track
if (typeof shouldRouterUpdate === 'function' && !shouldRouterUpdate(to, from)) {
return
}
// Adds a custom way to define when the router should track
if (typeof shouldRouterUpdate === 'function' && !shouldRouterUpdate(to, from)) {
return
}

// Fire tracking after the nextTick or it will still register the previous route
// https://github.com/MatteoGabriele/vue-analytics/issues/44
config.$vue.nextTick().then(() => {
trackRoute(router.currentRoute)
})
})
Expand Down

0 comments on commit cc858f7

Please sign in to comment.