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

Commit b776209

Browse files
docs(page): add custom router updates docs
1 parent 19b2d4b commit b776209

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

docs/page-tracking.md

+33
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ It is possible to avoid route query to be sent as querystring using the `transfo
151151

152152
```js
153153
Vue.use(VueAnalytics, {
154+
id: 'UA-XXX-X',
154155
router,
155156
autoTracking: {
156157
transformQueryString: false
@@ -163,10 +164,42 @@ When a base path is added to the VueRouter instance, the path is merged to the a
163164

164165
```js
165166
Vue.use(VueAnalytics, {
167+
id: 'UA-XXX-X',
166168
router,
167169
autoTracking: {
168170
prependBase: false
169171
}
170172
})
171173
```
172174

175+
## Customize router updates
176+
On every route change, the plugin will track the new route: when we change hashes, query strings or other parameters.
177+
178+
To avoid router to update and start tracking when a route has the same path of the previous one, it is possible to use the `skipSamePath` property in the `autoTracking` object
179+
180+
```js
181+
Vue.use(VueAnalytics, {
182+
id: 'UA-XXX-X',
183+
router,
184+
autoTracking: {
185+
skipSamePath: true
186+
}
187+
})
188+
```
189+
190+
For other use cases it is also possible to use the `shouldRouterUpdate`, accessable in the plugin configuartion object, inside the `autoTracking` property.
191+
The methods has the previous and current route as parameters and it needs to return a truthy or falsy value.
192+
193+
```js
194+
Vue.use(VueAnalytics, {
195+
id: 'UA-XXX-X',
196+
router,
197+
autoTracking: {
198+
shouldRouterUpdate (to, from) {
199+
// Here I'm allowing tracking only when
200+
// next route path is not the same as the previous
201+
return to.path !== from.path
202+
}
203+
}
204+
})
205+
```

0 commit comments

Comments
 (0)