Skip to content

Commit

Permalink
feat: finish matomo implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
AlejandroAkbal committed Nov 23, 2023
1 parent fe0e2cf commit ef8845e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 35 deletions.
2 changes: 0 additions & 2 deletions app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@
var _paq = window._paq = window._paq || [];
_paq.push(["disableCookies"]);
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="https://matomo.akbal.dev/";
Expand Down
30 changes: 0 additions & 30 deletions middleware/FixPostsRoute.js.bak

This file was deleted.

22 changes: 19 additions & 3 deletions plugins/matomo.client.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
import {defineNuxtPlugin} from '#imports'
import { defineNuxtPlugin } from '#imports'

/**
* Track page view using Matomo
* For the Script,
* @see app.vue
*
* @see https://developer.matomo.org/guides/spa-tracking#solution-2-embedding-the-tracking-code-manually
*/
export default defineNuxtPlugin((nuxt) => {
// TODO: Hook into the router to track page views - https://developer.matomo.org/guides/spa-tracking#solution-2-embedding-the-tracking-code-manually
export default defineNuxtPlugin((nuxtApp) => {
const router = useRouter()

router.afterEach((to, from) => {
onNuxtReady(() => {
if (!window._paq) {
return
}

window._paq.push(['setCustomUrl', to.fullPath])
window._paq.push(['setDocumentTitle', document.title])
window._paq.push(['trackPageView'])
window._paq.push(['enableLinkTracking'])
})
})
})

0 comments on commit ef8845e

Please sign in to comment.