Add Privatus Analytics to Nuxt
Add privacy-friendly analytics to a Nuxt app with a head script in nuxt.config. Route changes are tracked automatically and events are one call.
Add the script to the app head:
ts
// nuxt.config.ts
export default defineNuxtConfig({
app: {
head: {
script: [
{ src: 'https://privatusstats.com/js/pa.js', defer: true, 'data-site': 'pa_YOURSITEID',
'data-modules': 'engage,auto,vitals,clicks,ask' },
],
},
},
})
Vue Router uses history.pushState, so route changes are tracked
automatically.
Events#
vue
<script setup lang="ts">
function download() {
window.privatus?.track('Download', { file: 'guide.pdf' })
}
</script>
<template>
<button @click="download">Download</button>
</template>
For types on window.privatus, add the declarations from the
JavaScript API page.