Skip to content

Commit

Permalink
Add trackInteraction predicate function option
Browse files Browse the repository at this point in the history
- Allows vue-matomo to ignore some types of router interactions with a
  predicate function
  • Loading branch information
erupert-st committed Feb 1, 2023
1 parent 3e4c800 commit 4b6cc93
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
9 changes: 9 additions & 0 deletions README.md
Expand Up @@ -109,6 +109,15 @@ Vue.use(VueMatomo, {
// ]
preInitActions: [],

// A function to determine whether to track a router page change. If not a function
// all interactions will be tracked. Receives both the new route and the previous route
// and returns either true or false. True if the interaction should be tracked, false
// if the interaction should be ignored
// Default: undefined
// Example: (to, from) => {
// return !(from && to.path === from.path)
// }
trackInteraction: undefined,
// A function to determine whether to track an interaction as a site search
// instead of as a page view. If not a function, all interactions will be
// tracked as page views. Receives the new route as an argument, and
Expand Down
5 changes: 5 additions & 0 deletions src/index.js
Expand Up @@ -10,6 +10,7 @@ const defaultOptions = {
requireConsent: false,
trackInitialView: true,
trackSiteSearch: false,
trackInteraction: undefined,
trackerFileName: 'matomo',
trackerUrl: undefined,
trackerScriptUrl: undefined,
Expand All @@ -23,6 +24,10 @@ const defaultOptions = {
export const matomoKey = 'Matomo'

function trackUserInteraction (options, to, from) {
if (typeof options.trackInteraction === 'function' && !options.trackInteraction(to, from)) {
return
}

if (typeof options.trackSiteSearch === 'function') {
const siteSearch = options.trackSiteSearch(to)
if (siteSearch) {
Expand Down

0 comments on commit 4b6cc93

Please sign in to comment.