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

Commit

Permalink
docs(page): add custom router updates docs
Browse files Browse the repository at this point in the history
  • Loading branch information
MatteoGabriele committed Nov 28, 2017
1 parent 19b2d4b commit b776209
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions docs/page-tracking.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ It is possible to avoid route query to be sent as querystring using the `transfo

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

```js
Vue.use(VueAnalytics, {
id: 'UA-XXX-X',
router,
autoTracking: {
prependBase: false
}
})
```

## Customize router updates
On every route change, the plugin will track the new route: when we change hashes, query strings or other parameters.

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

```js
Vue.use(VueAnalytics, {
id: 'UA-XXX-X',
router,
autoTracking: {
skipSamePath: true
}
})
```

For other use cases it is also possible to use the `shouldRouterUpdate`, accessable in the plugin configuartion object, inside the `autoTracking` property.
The methods has the previous and current route as parameters and it needs to return a truthy or falsy value.

```js
Vue.use(VueAnalytics, {
id: 'UA-XXX-X',
router,
autoTracking: {
shouldRouterUpdate (to, from) {
// Here I'm allowing tracking only when
// next route path is not the same as the previous
return to.path !== from.path
}
}
})
```

0 comments on commit b776209

Please sign in to comment.