Skip to content

Commit 4b6cc93

Browse files
committed
Add trackInteraction predicate function option
- Allows vue-matomo to ignore some types of router interactions with a predicate function
1 parent 3e4c800 commit 4b6cc93

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,15 @@ Vue.use(VueMatomo, {
109109
// ]
110110
preInitActions: [],
111111

112+
// A function to determine whether to track a router page change. If not a function
113+
// all interactions will be tracked. Receives both the new route and the previous route
114+
// and returns either true or false. True if the interaction should be tracked, false
115+
// if the interaction should be ignored
116+
// Default: undefined
117+
// Example: (to, from) => {
118+
// return !(from && to.path === from.path)
119+
// }
120+
trackInteraction: undefined,
112121
// A function to determine whether to track an interaction as a site search
113122
// instead of as a page view. If not a function, all interactions will be
114123
// tracked as page views. Receives the new route as an argument, and

src/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const defaultOptions = {
1010
requireConsent: false,
1111
trackInitialView: true,
1212
trackSiteSearch: false,
13+
trackInteraction: undefined,
1314
trackerFileName: 'matomo',
1415
trackerUrl: undefined,
1516
trackerScriptUrl: undefined,
@@ -23,6 +24,10 @@ const defaultOptions = {
2324
export const matomoKey = 'Matomo'
2425

2526
function trackUserInteraction (options, to, from) {
27+
if (typeof options.trackInteraction === 'function' && !options.trackInteraction(to, from)) {
28+
return
29+
}
30+
2631
if (typeof options.trackSiteSearch === 'function') {
2732
const siteSearch = options.trackSiteSearch(to)
2833
if (siteSearch) {

0 commit comments

Comments
 (0)