Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nuxt-umami

Package Overview
Dependencies
Maintainers
1
Versions
70
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nuxt-umami

Embed the Umami analytics library into Nuxt

  • 1.2.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
987
decreased by-53.24%
Maintainers
1
Weekly downloads
 
Created
Source

Nuxt Umami Module

npm Downloads License

This is a fully-featured nuxt module that makes implementing Umami Analytics into your Nuxt project a breeze.


Note:

Hey! If you're using Nuxt 3, I recommend upgrading to Nuxt Umami v2 for better types and DX. Heads up: starting May 7, 2023, the package will only be available as nuxt-umami@v1.



Features

  • 📖 Open Source
  • ✨ SSR support
  • 💯 Feature complete
  • ✅ TypeScript & JSDocs
  • ✅ Supports <script setup> syntax

Heads up: Nuxt Umami v2 has a superior feature set. If you are currently using Nuxt 3, please upgrade to Nuxt Umami v2.


Installation

With pnpm

pnpm add -D nuxt-umami@v1

Or, with npm

npm install -D nuxt-umami@v1

Or, with yarn

yarn add -D nuxt-umami@v1

Setup

Add the module to nuxt.config:

// nuxt.config.ts (Nuxt 3)
export default defineNuxtConfig({
  modules: ['nuxt-umami'],
  umami: {
    enable: true, // enable the module? true by default
    autoTrack: true,
    doNotTrack: false,
    cache: false,
    domains: 'mywebsite.com,mywebsite2.com',
    websiteId: 'your-website-id',
    scriptUrl: 'https://path.to.umami.js',
  }
})

// or inline config
export default defineNuxtConfig({
  modules: [['nuxt-umami', {
    // nuxt-umami options
  }]]
})
// nuxt.config.js (Nuxt 2)
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',
  }
}

// or inline config
export default {
  modules: [
    ['nuxt-umami', {
      // nuxt-umami options
    }]
  ]
}

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).

Type not working?

It's a bit of a hack, but adding

import {} from 'nuxt-umami';

to the top of your config might fix that.

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();
  // do something, return something
});

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



MIT License © 2023 ML

Keywords

FAQs

Package last updated on 09 Apr 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc