---
title: Umami Analytics
description: Open-source, cookieless analytics with a prebuilt helper that maps Umami's data attributes into a c15t-managed script.
lastModified: 2026-05-10
icon: umami-analytics
---
Umami is an open-source, cookieless analytics product configured entirely through `data-*` attributes on its loader. The `umamiAnalytics()` helper serializes your website ID, host override, and tracking options into those attributes and hands the result to c15t's script loader.

## Integrate with c15t

**React**

```tsx
import { type ReactNode } from 'react';
import { ConsentManagerProvider } from '@c15t/react';
import { umamiAnalytics } from '@c15t/scripts/umami-analytics';

const scripts = [umamiAnalytics({ websiteId: 'site-abc-123' })];

export function ConsentProvider({ children }: { children: ReactNode }) {
  return (
    <ConsentManagerProvider
      options={{
        mode: 'hosted',
        backendURL: 'https://your-instance.c15t.dev',
        scripts,
      }}
    >
      {children}
    </ConsentManagerProvider>
  );
}
```

**Next.js**

```tsx
'use client';

import { type ReactNode } from 'react';
import { ConsentManagerProvider } from '@c15t/nextjs';
import { umamiAnalytics } from '@c15t/scripts/umami-analytics';

const scripts = [umamiAnalytics({ websiteId: 'site-abc-123' })];

export function ConsentProvider({ children }: { children: ReactNode }) {
  return (
    <ConsentManagerProvider
      options={{
        mode: 'hosted',
        backendURL: '/api/c15t',
        scripts,
      }}
    >
      {children}
    </ConsentManagerProvider>
  );
}
```

**JavaScript**

```ts
import { getOrCreateConsentRuntime } from 'c15t';
import { umamiAnalytics } from '@c15t/scripts/umami-analytics';

getOrCreateConsentRuntime({
  mode: 'hosted',
  backendURL: 'https://your-instance.c15t.dev',
  scripts: [umamiAnalytics({ websiteId: 'site-abc-123' })],
});
```

## How c15t loads it

* **Category:** `measurement` (Analytics)
* **Loads when:** measurement consent is granted
* **On revocation:** unloaded — c15t removes the script element from the DOM. Umami is cookieless, so no client-side state needs clearing.

If you self-host Umami or need to restrict tracking to specific domains:

```ts
umamiAnalytics({
  websiteId: 'site-abc-123',
  hostUrl: 'https://analytics.example.com',
  domains: ['example.com', 'www.example.com'],
  autoTrack: false,
  tag: 'release-2025',
})
```

Each option is mapped to Umami's published `data-*` attribute (`data-website-id`, `data-host-url`, `data-auto-track`, `data-domains`, `data-tag`, `data-before-send`) and the script uses `defer` so it matches Umami's recommended embed pattern.

> ℹ️ **Info:**
> beforeSend accepts a string referencing a global hook (e.g. 'window\.umamiBeforeSend'), not a function value. The c15t manifest runtime serializes script configuration, so inline callbacks cannot be passed through it.

## Tracking events in your app

c15t gates the Umami script from loading until `measurement` consent is granted. Your application code that calls Umami's runtime API (`window.umami.track`, `window.umami.identify`) is **not** automatically gated — `window.umami` does not exist until the script is loaded, so unguarded calls before consent throw.

Guard event calls by checking consent state. From React:

```tsx
import { useConsentManager } from '@c15t/react';

function useTrackSignup() {
  const { has } = useConsentManager();

  return () => {
    if (has('measurement')) {
      window.umami?.track('signup');
    }
  };
}
```

From plain JavaScript:

```ts
import { getOrCreateConsentRuntime } from 'c15t';

const { consentStore } = getOrCreateConsentRuntime();

if (consentStore.getState().has('measurement')) {
  window.umami?.track('signup');
}
```

## Types

### UmamiAnalyticsOptions

|Property|Type|Description|Default|Required|
|:--|:--|:--|:--|:--:|
|websiteId|string|Your Umami website ID.|-|✅ Required|
|hostUrl|string \|undefined|Override the host that receives analytics events.|-|Optional|
|autoTrack|boolean \|undefined|Disable automatic tracking when set to \`false\`.|-|Optional|
|domains|string \|string\[] \|undefined|Restrict tracking to specific domains.|-|Optional|
|tag|string \|undefined|Attach a tag to tracked events.|-|Optional|
|beforeSend|string \|undefined|Optional global hook name used for Umami's \`data-before-send\` attribute. Callback functions are intentionally not supported here because the c15t manifest runtime cannot serialize custom JavaScript functions.|-|Optional|
|scriptUrl|string \|undefined|Custom loader URL.|'https\://cloud.umami.is/script.js'|Optional|

### Script

|Property|Type|Description|Default|Required|
|:--|:--|:--|:--|:--:|
|id|string|Unique identifier for the script|-|✅ Required|
|src|string \|undefined|URL of the script to load|-|Optional|
|textContent|string \|undefined|Inline JavaScript code to execute|-|Optional|
|category|HasCondition\<AllConsentNames>|Consent category or condition required to load this script|-|✅ Required|
|callbackOnly|boolean \|undefined|Whether this is a callback-only script that doesn't need to load an external resource. When true, no script tag will be added to the DOM, only callbacks will be executed.|false|Optional|
|persistAfterConsentRevoked|boolean \|undefined|Whether the script should persist after consent is revoked.|false|Optional|
|alwaysLoad|boolean \|undefined|Whether the script should always load regardless of consent state. This is useful for scripts like Google Tag Manager or PostHog that manage their own consent state internally. The script will load immediately and never be unloaded based on consent changes. Note: When using this option, you are responsible for ensuring the script itself respects user consent preferences through its own consent management.|false|Optional|
|fetchPriority|"high" \|"low" \|"auto" \|undefined|Priority hint for browser resource loading|-|Optional|
|attributes|Record\<string, string> \|undefined|Additional attributes to add to the script element|-|Optional|
|async|boolean \|undefined|Whether to use async loading|-|Optional|
|defer|boolean \|undefined|Whether to defer script loading|-|Optional|
|nonce|string \|undefined|Content Security Policy nonce|-|Optional|
|anonymizeId|boolean \|undefined|Whether to use an anonymized ID for the script element, this helps ensure the script is not blocked by ad blockers|true|Optional|
|target|"head" \|"body" \|undefined|Where to inject the script element in the DOM. Options: \`'head'\`: Scripts are appended to \`\<head>\` (default); \`'body'\`: Scripts are appended to \`\<body>\`|'head'|Optional|
|onBeforeLoad|Object \|undefined|Callback executed before the script is loaded|-|Optional|
|onLoad|Object \|undefined|Callback executed when the script loads successfully|-|Optional|
|onError|Object \|undefined|Callback executed if the script fails to load|-|Optional|
|onConsentChange|Object \|undefined|Callback executed whenever the consent store is changed. This callback only applies to scripts already loaded.|-|Optional|
|vendorId|string \|number \|undefined|IAB TCF vendor ID - links script to a registered vendor. When in IAB mode, the script will only load if this vendor has consent. Takes precedence over \`category\` when in IAB mode. Use custom vendor IDs (string or number) to gate non-IAB vendors too.|-|Optional|
|iabPurposes|number\[] \|undefined|IAB TCF purpose IDs this script requires consent for. When in IAB mode and no vendorId is set, the script will only load if ALL specified purposes have consent.|-|Optional|
|iabLegIntPurposes|number\[] \|undefined|IAB TCF legitimate interest purpose IDs. These purposes can operate under legitimate interest instead of consent. The script loads if all iabPurposes have consent OR all iabLegIntPurposes have legitimate interest established.|-|Optional|
|iabSpecialFeatures|number\[] \|undefined|IAB TCF special feature IDs this script requires. Options: 1: Use precise geolocation data; 2: Actively scan device characteristics for identification|-|Optional|

#### `onBeforeLoad`

Callback executed before the script is loaded

|Property|Type|Description|Default|Required|
|:--|:--|:--|:--|:--:|
|id|string|The original script ID|-|✅ Required|
|elementId|string|The actual DOM element ID used (anonymized if enabled)|-|✅ Required|
|hasConsent|boolean|Has consent|-|✅ Required|
|consents|ConsentState|The current consent state|-|✅ Required|
|element|HTMLScriptElement \|undefined|The script element (for load/error callbacks) Will be undefined for callback-only scripts|-|Optional|
|error|Error \|undefined|Error information (for error callbacks)|-|Optional|

#### `onLoad`

Callback executed when the script loads successfully

|Property|Type|Description|Default|Required|
|:--|:--|:--|:--|:--:|
|id|string|The original script ID|-|✅ Required|
|elementId|string|The actual DOM element ID used (anonymized if enabled)|-|✅ Required|
|hasConsent|boolean|Has consent|-|✅ Required|
|consents|ConsentState|The current consent state|-|✅ Required|
|element|HTMLScriptElement \|undefined|The script element (for load/error callbacks) Will be undefined for callback-only scripts|-|Optional|
|error|Error \|undefined|Error information (for error callbacks)|-|Optional|

#### `onError`

Callback executed if the script fails to load

|Property|Type|Description|Default|Required|
|:--|:--|:--|:--|:--:|
|id|string|The original script ID|-|✅ Required|
|elementId|string|The actual DOM element ID used (anonymized if enabled)|-|✅ Required|
|hasConsent|boolean|Has consent|-|✅ Required|
|consents|ConsentState|The current consent state|-|✅ Required|
|element|HTMLScriptElement \|undefined|The script element (for load/error callbacks) Will be undefined for callback-only scripts|-|Optional|
|error|Error \|undefined|Error information (for error callbacks)|-|Optional|

#### `onConsentChange`

Callback executed whenever the consent store is changed. This callback only applies to scripts already loaded.

|Property|Type|Description|Default|Required|
|:--|:--|:--|:--|:--:|
|id|string|The original script ID|-|✅ Required|
|elementId|string|The actual DOM element ID used (anonymized if enabled)|-|✅ Required|
|hasConsent|boolean|Has consent|-|✅ Required|
|consents|ConsentState|The current consent state|-|✅ Required|
|element|HTMLScriptElement \|undefined|The script element (for load/error callbacks) Will be undefined for callback-only scripts|-|Optional|
|error|Error \|undefined|Error information (for error callbacks)|-|Optional|
