Skip to content

Commit

Permalink
Merge pull request #157 from beeldengeluid/analytics-improvements
Browse files Browse the repository at this point in the history
Analytics improvements
  • Loading branch information
gb-beng authored Apr 23, 2024
2 parents 8615b59 + 77580a6 commit aef4b1d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
18 changes: 18 additions & 0 deletions plugins/matomo.client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export default defineNuxtPlugin(() => {
// https://router.vuejs.org/guide/advanced/navigation-guards.html#Global-After-Hooks
const router = useRouter()
router.afterEach((to, from, failure) => {
if (to.path !== from.path && !failure) {
const { origin } = window.location

// https://developer.matomo.org/guides/spa-tracking
const _paq = window._paq
_paq.push(['deleteCustomVariables', 'page'])
_paq.push(['deleteCustomDimension', 1])
_paq.push(['setReferrerUrl', origin + from.path])
_paq.push(['setCustomUrl', origin + to.path])
_paq.push(['trackPageView'])
console.debug(`trackPageView ${from.path}->${to.path}`)
}
})
})
1 change: 0 additions & 1 deletion public/matomo-tracking-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ var _paq = (window._paq = window._paq || [])
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
_paq.push(['disableCookies'])
_paq.push(['trackPageView'])
_paq.push(['enableLinkTracking'])
;(function () {
var u = 'https://clariah-mediasuite.innocraft.cloud/'
_paq.push(['setTrackerUrl', u + 'matomo.php'])
Expand Down

0 comments on commit aef4b1d

Please sign in to comment.