Nuxt Umami Module
This is a fully featured nuxt module that makes implementing Umami Analytics into your Nuxt project a breeze.
Features
- 📖 Open Source
- ✨ SSR support
- 💯 Feature complete
- ✅ TypeScript & JSDocs
- ✅ Supports
<script setup>
syntax
Installation
With pnpm
pnpm add -D nuxt-umami
Or, with npm
npm install -D nuxt-umami
Or, with yarn
yarn add -D nuxt-umami
Setup
Add the module to nuxt.config
:
export default defineNuxtConfig({
modules: ['nuxt-umami'],
umami: {
enable: true,
autoTrack: true,
doNotTrack: false,
cache: false,
domains: 'mywebsite.com,mywebsite2.com',
websiteId: 'your-website-id',
scriptUrl: 'https://path.to.umami.js',
}
})
export default defineNuxtConfig({
modules: [['nuxt-umami', {
}]]
})
export default {
modules: [
['nuxt-umami'],
],
umami: {
autoTrack: true,
doNotTrack: false,
cache: false,
domains: 'mywebsite.com,mywebsite2.com',
websiteId: 'your-website-id',
scriptUrl: 'https://path.to.umami.js',
}
}
export default {
modules: [
['nuxt-umami', {
}]
]
}
Only websiteId
and scriptUrl
are mandatory. See the Umami docs for more explanation of these options.
New:
Set the enable
option to false
to disable the module (temporarily).
Environment Variables
If you want, you can set up and use environment variables in .env
files. But that is not really necessary as the module config does not require any "sensitive" data. Every part of the configuration can be viewed in the script in <head>
after the page is loaded.
Usage
Note:
You can use $umami
anywhere you have access to NuxtApp
or the useNuxtApp
composable (middleware, asyncData, etc).
Warning:
$umami is only available onMounted
.
In <script setup>
<script setup>
const { $umami } = useNuxtApp();
onMounted(() => {
// Sends an event with an event type of custom.
$umami("Signup button click");
});
</script>
In middleware, asyncData, etc
const { data } = await useAsyncData("mountains", (nuxtApp) => {
const { $umami } = nuxtApp();
});
Available Functions
For a list of all available functions, see Umami Tracker Functions
Credits
- VueUse - for
useScriptTag
composable. - Joe Pritchard - author of nuxt-umami-module (compatible only with Nuxt 2).
Author
Hi, I'm ML. I'm dedicated to contributing to open source and sharing my insights on Twitter. If you encounter any issues with my module, don't hesitate to open an issue. I'm always available to help and resolve any bugs.
Using the module in your app? Consider giving it a star 🌟. It'd mean the world to me.
Contributions