Skip to main content
Umami allows you to attach custom data to events, providing deeper insights into user behavior. Event data can be added using HTML attributes or the JavaScript API.

Adding Data with HTML Attributes

Attach custom data to events using data-umami-event-* attributes:
<button
  data-umami-event="purchase"
  data-umami-event-product="Pro Plan"
  data-umami-event-price="29.99"
  data-umami-event-currency="USD"
>
  Buy Now
</button>
The tracker automatically extracts all attributes matching the pattern data-umami-event-* and includes them in the event payload.

How It Works

When you click the button above, the tracker:
  1. Finds the data-umami-event attribute (event name: purchase)
  2. Scans for all data-umami-event-* attributes
  3. Extracts the property name from each attribute (e.g., data-umami-event-productproduct)
  4. Creates an event data object:
{
  name: 'purchase',
  data: {
    product: 'Pro Plan',
    price: '29.99',
    currency: 'USD'
  }
}
The regex pattern used to match attributes is /data-umami-event-([\w-_]+)/. Property names can contain letters, numbers, hyphens, and underscores.

Adding Data with JavaScript

Pass an object as the second parameter to umami.track():
umami.track('purchase', {
  product: 'Pro Plan',
  price: 29.99,
  currency: 'USD',
  quantity: 1
});

Data Structure

Event data accepts any JSON-compatible structure:
interface EventData {
  [key: string]: number | string | EventData | number[] | string[] | EventData[];
}

Supported Data Types

umami.track('event', {
  name: 'John Doe',
  email: '[email protected]',
  plan: 'premium'
});
Strings have a maximum length of 500 characters and will be truncated if longer.

Data Limitations

To maintain performance, Umami enforces these limits on event data:
TypeLimitationBehavior
StringsMax 500 charactersTruncated
NumbersMax 4 decimal placesRounded
ObjectsMax 50 propertiesExcess ignored
ArraysConverted to stringMax 500 characters
Data exceeding these limits will be automatically truncated or modified. Plan your event structure accordingly.

Common Data Patterns

E-commerce Events

umami.track('product-view', {
  product_id: 'SKU-12345',
  product_name: 'Wireless Headphones',
  category: 'Electronics',
  price: 79.99,
  currency: 'USD',
  in_stock: true
});

User Interactions

umami.track('form-submit', {
  form_name: 'contact',
  form_type: 'support',
  fields_filled: 5,
  time_spent: 45
});

Feature Usage

umami.track('feature-enabled', {
  feature_name: 'dark_mode',
  user_type: 'premium',
  enabled_from: 'settings',
  first_time: true
});

HTML Attribute Examples

<button
  data-umami-event="add-to-cart"
  data-umami-event-product-id="SKU-12345"
  data-umami-event-product-name="Wireless Headphones"
  data-umami-event-price="79.99"
  data-umami-event-quantity="1"
>
  Add to Cart
</button>

Best Practices

1

Use consistent naming

Choose a naming convention and stick to it:
// Good - snake_case
umami.track('event', {
  user_id: 123,
  product_name: 'Item',
  cart_total: 99.99
});

// Good - camelCase
umami.track('event', {
  userId: 123,
  productName: 'Item',
  cartTotal: 99.99
});
2

Keep data relevant

Only include data you’ll actually use for analysis:
// Good - focused data
umami.track('signup', {
  plan: 'premium',
  referral_source: 'google'
});

// Avoid - unnecessary data
umami.track('signup', {
  plan: 'premium',
  browser_plugins: [...],
  screen_resolution: '1920x1080',
  timezone: 'UTC-5'
  // Already tracked automatically
});
3

Mind the limits

Stay within data constraints:
// Good - concise strings
umami.track('event', {
  description: 'User completed checkout'
});

// Avoid - very long strings
umami.track('event', {
  description: 'Very long description that exceeds 500 characters...'
  // Will be truncated
});
4

Structure nested data carefully

Remember the 50 property limit:
// Good - within limits
umami.track('event', {
  order: {
    id: 123,
    total: 99.99,
    items: [...] // Counts as 1 property
  }
});

// Avoid - too many properties
umami.track('event', {
  prop1: 1, prop2: 2, /* ... */ prop51: 51
  // Properties beyond 50 will be ignored
});
For complex data that exceeds limits, consider tracking multiple events or summarizing the data before sending.

Next Steps

Tracker Functions

Explore all available tracker functions

User Identification

Learn how to identify and track users

Build docs developers (and LLMs) love