---
title: "Umami Analytics Setup for Nuxt · Nuxt Scripts"
description: "Add Umami Analytics to a Nuxt app with one composable. Works with Umami Cloud or a self-hosted server, and lets you identify sessions and filter events."
canonical_url: "https://scripts.nuxt.com/scripts/umami-analytics"
meta:
  "og:description": "Add Umami Analytics to a Nuxt app with one composable. Works with Umami Cloud or a self-hosted server, and lets you identify sessions and filter events."
  "og:image": "https://scripts.nuxt.com/_og/s/o_3464bbe890f0df3c.png"
  "og:image:height": "600"
  "og:image:type": image/png
  "og:image:width": "1200"
  "og:title": "Umami Analytics Setup for Nuxt · Nuxt Scripts"
  "twitter:image": "https://scripts.nuxt.com/_og/s/o_3464bbe890f0df3c.png"
---

> Index of every page on this site: [llms.txt](https://scripts.nuxt.com/llms.txt)

**Scripts**

# **Umami Analytics**

[Copy for LLMs](https://scripts.nuxt.com/scripts/umami-analytics.md)

[**Umami**](https://umami.is/) is an open-source web analytics platform that can run in Umami Cloud or on your own server.

**Umami Analytics**

[**View source **](https://github.com/nuxt/scripts/blob/main/packages/script/src/runtime/registry/umami-analytics.ts)

## Nuxt Config Setup

Add this to your `**nuxt.config.ts**` to load Umami Analytics globally. Alternatively you can use the **useScriptUmamiAnalytics** composable for more control.

```
export default defineNuxtConfig({
  scripts: {
    registry: {
      umamiAnalytics: {
        websiteId: '550e8400-e29b-41d4-a716-446655440000',
        trigger: 'onNuxtReady',
      }
    }
  }
})
```

This config automatically enables **first-party mode ** (bundle + proxy). See below to customise.

## useScriptUmamiAnalytics()

The `**useScriptUmamiAnalytics**` composable lets you have fine-grain control over when and how Umami Analytics is loaded on your site.

```
const { proxy } = useScriptUmamiAnalytics()

proxy.track('conversion', { value: 1 })
```

Please follow the [**Registry Scripts **](https://scripts.nuxt.com/docs/guides/registry-scripts) guide to learn more about advanced usage.

## First-Party Mode: Privacy Focused Proxy

No extra config needed. The script is bundled from your domain (faster loads, no extra DNS lookup) and runtime requests are reverse-proxied through your server with automatic anonymisation (user IPs stay hidden from Umami Analytics, works with ad blockers). [**Learn more. **](https://scripts.nuxt.com/docs/guides/first-party)

**Mode**

Bundle Proxy Partytown

**Privacy**

User IP addresses are anonymised. Other request data passes through.

```
export default defineNuxtConfig({
  scripts: {
    // ✅ First-party mode: bundled + proxied
    registry: {
      umamiAnalytics: {
        websiteId: '550e8400-e29b-41d4-a716-446655440000',
        trigger: 'onNuxtReady',
      },
    },
  },
})
```

## Example

Using Umami Analytics in a component with the proxy to send events .

ConversionButton.vue

```
<script setup lang="ts">
const { proxy } = useScriptUmamiAnalytics()

// noop in development, ssr
// just works in production, client
function handleAction() {
  proxy.track('conversion', { value: 1 })
}
</script>

<template>
  <div>
    <button @click="handleAction">
      Send Event
    </button>
  </div>
</template>
```

### Self-hosted Umami

If you use a self-hosted version of Umami, set `**hostUrl**` to your Umami origin. This maps to Umami's documented [`**data-host-url**`](https://docs.umami.is/docs/tracker-configuration#data-host-url) setting and tells the tracker where to send events.

```ts
useScriptUmamiAnalytics({
  websiteId: 'YOUR_WEBSITE_ID',
  hostUrl: 'https://my-self-hosted'
})
```

Use `**scriptInput.src**` only if you also need to override the script URL itself.

## Identify Sessions and Filter Data

### Identify a Session

Umami's [`**identify**`](https://docs.umami.is/docs/tracker-functions#sessions) function accepts either a distinct ID or an object with session data:

```ts
const { proxy } = useScriptUmamiAnalytics({
  websiteId: 'YOUR_WEBSITE_ID'
})

// Set a distinct ID
proxy.identify('user-12345')

// Attach data to the session
proxy.identify({
  userId: 'user-12345',
  plan: 'premium'
})
```

### Filter Data with `**beforeSend**`

Use [`**beforeSend**`](https://docs.umami.is/docs/tracker-configuration#data-before-send) to inspect, modify, or cancel a payload before Umami receives it:

```ts
useScriptUmamiAnalytics({
  websiteId: 'YOUR_WEBSITE_ID',
  beforeSend: (type, payload) => {
    // Log what's being sent while debugging
    console.log('Sending to Umami:', type, payload)

    // Filter out sensitive data
    if (payload.url && payload.url.includes('private')) {
      return false // Cancel send
    }

    // Modify payload before sending
    return {
      ...payload,
      referrer: '' // Remove referrer for privacy
    }
  }
})
```

You can also provide a string with the name of a globally defined function:

```ts
// Define function globally
window.myBeforeSendHandler = (type, payload) => {
  return checkPrivacyRules(payload) ? payload : false
}

useScriptUmamiAnalytics({
  websiteId: 'YOUR_WEBSITE_ID',
  beforeSend: 'myBeforeSendHandler'
})
```

`**websiteId**``string`** required **

Your Umami website ID.

`**hostUrl**``string`

By default, Umami will send data to wherever the script is located. You can override this to send data to another location.

`**autoTrack**``boolean` = true

By default, Umami tracks all pageviews and events for you automatically. You can disable this behavior and track events yourself using the tracker functions.

`**domains**``string[]`

If you want the tracker to only run on specific domains, you can add them to your tracker script. This is a comma delimited list of domain names. Helps if you are working in a staging/development environment.

`**tag**``string`

If you want the tracker to collect events under a specific tag. Events can be filtered in the dashboard by a specific tag.

`**beforeSend**``Function | string`

Function that will be called before data is sent to Umami. The function takes two parameters: type and payload. Return the payload to continue sending, or return a falsy value to cancel.

[Edit this page](https://github.com/nuxt/scripts/edit/main/docs/content/umami-analytics.md)

[Markdown For LLMs](https://scripts.nuxt.com/scripts/umami-analytics.md)

[**TikTok Pixel** Track TikTok conversions with consent, deduplication, and advanced matching.](https://scripts.nuxt.com/scripts/tiktok-pixel) [**Usercentrics** Load the Usercentrics CMP v3 and drive useScript consent triggers from UC\_UI\_CMP\_EVENT events.](https://scripts.nuxt.com/scripts/usercentrics)

**On this page **

- [Self-hosted Umami](#self-hosted-umami)
- [Identify Sessions and Filter Data](#identify-sessions-and-filter-data)

```json
{"@context":"https://schema.org","@graph":[{"@id":"https://scripts.nuxt.com/#website","@type":"WebSite","description":"Nuxt Scripts lets you load third-party scripts with better performance, privacy, security and DX. It includes many popular third-parties out of the box.","name":"Nuxt Scripts","url":"https://scripts.nuxt.com/","publisher":{"@id":"https://scripts.nuxt.com/#identity"}},{"@id":"https://scripts.nuxt.com/scripts/umami-analytics#webpage","@type":"WebPage","description":"Add Umami Analytics to a Nuxt app with one composable. Works with Umami Cloud or a self-hosted server, and lets you identify sessions and filter events.","name":"Umami Analytics Setup for Nuxt","url":"https://scripts.nuxt.com/scripts/umami-analytics","breadcrumb":{"@id":"https://scripts.nuxt.com/scripts/umami-analytics#breadcrumb"},"isPartOf":{"@id":"https://scripts.nuxt.com/#website"},"potentialAction":[{"@type":"ReadAction","target":["https://scripts.nuxt.com/scripts/umami-analytics"]}],"primaryImageOfPage":{"@id":"https://scripts.nuxt.com/#logo"}},{"@id":"https://scripts.nuxt.com/#identity","@type":"Organization","name":"Nuxt Scripts","url":"https://scripts.nuxt.com","logo":{"@id":"https://scripts.nuxt.com/#logo"}},{"@id":"https://scripts.nuxt.com/scripts/umami-analytics#breadcrumb","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","name":"Nuxt Scripts","item":"https://scripts.nuxt.com/","position":1},{"@type":"ListItem","name":"Scripts","item":"https://scripts.nuxt.com/scripts","position":2},{"@type":"ListItem","name":"Umami Analytics","item":"https://scripts.nuxt.com/scripts/umami-analytics","position":3}]},{"@id":"https://scripts.nuxt.com/#logo","@type":"ImageObject","caption":"Nuxt Scripts","contentUrl":"https://scripts.nuxt.com/logo.svg","inLanguage":"en","url":"https://scripts.nuxt.com/logo.svg"}]}
```

## Sitemap

See the full [sitemap](https://scripts.nuxt.com/sitemap.md) for all pages.
