@@ -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 } )
0 commit comments