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

Commit 9e8a770

Browse files
authored
Merge branch 'master' into typescript-extract-payload-types
2 parents be5ec8d + cc858f7 commit 9e8a770

File tree

2 files changed

+24
-23
lines changed

2 files changed

+24
-23
lines changed

src/lib/page.js

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -85,28 +85,26 @@ export function autoTracking () {
8585
return
8686
}
8787

88-
if (autoTracking.pageviewOnLoad && router.history.ready) {
89-
trackRoute(router.currentRoute)
90-
}
88+
router.onReady(() => {
89+
if (autoTracking.pageviewOnLoad && router.history.ready) {
90+
trackRoute(router.currentRoute)
91+
}
9192

92-
config.router.afterEach(function (to, from) {
93-
const { skipSamePath, shouldRouterUpdate } = autoTracking
93+
router.afterEach(function (to, from) {
94+
const { skipSamePath, shouldRouterUpdate } = autoTracking
9495

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

102-
// Adds a custom way to define when the router should track
103-
if (typeof shouldRouterUpdate === 'function' && !shouldRouterUpdate(to, from)) {
104-
return
105-
}
103+
// Adds a custom way to define when the router should track
104+
if (typeof shouldRouterUpdate === 'function' && !shouldRouterUpdate(to, from)) {
105+
return
106+
}
106107

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

vue-analytics.d.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,14 @@ declare module 'vue-analytics' {
2828
(route: VueRouter): void;
2929
}
3030

31+
interface SetFieldValue {
32+
field: string;
33+
value: any;
34+
}
35+
3136
interface setFn {
32-
(fieldName: string, fieldValue: string): void;
33-
(options: {
34-
field: string, value: string
35-
}): void;
37+
(fieldName: string, fieldValue: any): void;
38+
(options: Record<string, any>): void;
3639
}
3740

3841
interface SocialPayload {
@@ -237,7 +240,7 @@ declare module 'vue-analytics' {
237240
disabled?: boolean | (() => boolean) | (() => Promise<boolean>) | Promise<boolean>,
238241
checkDuplicatedScript?: boolean,
239242
disableScriptLoader?: boolean
240-
set?: { field: string, value: string }[],
243+
set?: SetFieldValue[],
241244
commands?: any,
242245
beforeFirstHit?: () => void,
243246
ready?: () => void

0 commit comments

Comments
 (0)