Skip to content

Commit

Permalink
Add matomo tracker for client side only (#236)
Browse files Browse the repository at this point in the history
This will include a script from stats.data.gouv.fr, adding this
information for datagouv/data.gouv.fr#1557
  • Loading branch information
nicolaskempf57 authored Jan 7, 2025
1 parent ebf7d70 commit 8000c99
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
6 changes: 6 additions & 0 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ export default defineNuxtConfig({
sentry: {
dsn: '',
},

// URL of your matomo host.
matomo_host: undefined,

// Matomo ID of your site. Check the Matomo backend for it
matomo_site_id: 1,
},
},

Expand Down
19 changes: 19 additions & 0 deletions plugins/matomo.client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export default defineNuxtPlugin((nuxtApp) => {
const _paq = (window._paq = window._paq || [])
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
_paq.push(['trackPageView'])
_paq.push(['enableLinkTracking']);
(function () {
const u = nuxtApp.$config.public.matomo_host
if (u) {
_paq.push(['setTrackerUrl', u + 'matomo.php'])
_paq.push(['setSiteId', nuxtApp.$config.public.matomo_site_id])
const d = document,
g = d.createElement('script'),
s = d.getElementsByTagName('script')[0]
g.async = true
g.src = u + 'matomo.js'
s.parentNode.insertBefore(g, s)
}
})()
})

0 comments on commit 8000c99

Please sign in to comment.