Mastering Umami: A Deep Dive into Custom Event Tracking
Unlock the true power of your analytics. This deep dive shows you how to master Umami's custom event tracking to understand user behavior beyond just pageviews.
Alex Porter
A full-stack developer and data enthusiast passionate about privacy-first analytics tools.
You’ve installed Umami. You’re basking in the glory of simple, privacy-focused analytics. You can see which pages are popular, where your visitors are coming from, and what devices they’re using. It’s a clean, refreshing change from the bloated alternatives. But are you getting the whole story? Pageviews tell you where your users are going, but they don’t tell you what they’re doing.
What if you could know which call-to-action button is most effective? Or how many people actually complete your contact form? Or which video on your homepage gets the most plays? This is where standard analytics falls short, and where custom event tracking becomes your superpower. It’s the key to transforming Umami from a simple traffic counter into a nuanced tool for understanding user behavior.
What Are Custom Events, Really?
In the simplest terms, custom events are specific actions a user takes on your website that aren’t just navigating to a new page. Think of them as digital footprints that reveal intent and engagement. While Umami automatically tracks pageviews, custom events let you manually track things like:
- Button clicks (e.g., "Add to Cart," "Download PDF," "Sign Up")
- Form submissions
- Video plays, pauses, or completions
- Clicks on external links
- Interactions with a specific feature of your web app
By tracking these interactions, you move beyond asking "How many people visited the pricing page?" to answering, "Of the people who visited the pricing page, how many clicked to sign up for the Pro plan?" That’s not just data; it’s insight.
Getting Started: Tracking Events in Umami
The beauty of Umami is its simplicity, and its event tracking API is no exception. It all boils down to a single, powerful JavaScript function: umami.track()
. You can call this function whenever a user performs an action you want to record.
The Core Function: umami.track()
The function has a straightforward syntax. In its basic form, you just provide a name for the event:
umami.track('event-name');
For more detailed analysis, you can include a data payload, which is an object containing extra information about the event:
umami.track('event-name', { type: 'category', value: 'detail' });
This payload is incredibly useful for segmenting your data later on. Let's see it in action.
Example 1: Tracking a Simple Button Click
Let's say you have a newsletter signup button on your blog. You want to know how many people are clicking it. First, here’s your HTML:
<button id="newsletter-signup-btn">Subscribe to our Newsletter</button>
Now, you can add a small JavaScript snippet to your page that listens for a click on this button and sends an event to Umami.
const signupButton = document.getElementById('newsletter-signup-btn');
if (signupButton) {
signupButton.addEventListener('click', () => {
// This sends the event to your Umami instance
umami.track('newsletter-signup-click');
});
}
That's it! Now, every time a user clicks that button, an event named "newsletter-signup-click" will appear in your Umami dashboard. Simple, right?
Example 2: Adding Context with Data
Now for a more advanced scenario. Imagine you have a pricing page with three different plans: Basic, Pro, and Enterprise. You want to track which plan users are most interested in.
Here's the HTML, using data-
attributes to store the plan name:
<button class="plan-button" data-plan="basic">Choose Basic</button>
<button class="plan-button" data-plan="pro">Choose Pro</button>
<button class="plan-button" data-plan="enterprise">Choose Enterprise</button>
Now, the JavaScript can be written to handle any of these buttons and send the specific plan data along with the event.
const planButtons = document.querySelectorAll('.plan-button');
planButtons.forEach(button => {
button.addEventListener('click', () => {
// Get the plan name from the data-plan attribute
const plan = button.dataset.plan;
// Send the event with a data payload
umami.track('plan-selection', { type: 'plan', value: plan });
});
});
In your Umami dashboard, you'll now see a single event called "plan-selection". When you click to view its details, you’ll be able to see a breakdown of how many times the `value` was "basic", "pro", or "enterprise". This is a game-changer for understanding user choice.
Best Practices for a Smart Event Strategy
Before you go and track every single click on your site, pause for a moment. A successful event tracking strategy isn't about collecting the most data; it's about collecting the right data. Here are a few tips to keep your analytics clean and useful.
Keep Your Naming Convention Clean
Your future self will thank you for this. Adopt a consistent naming convention from the start. A popular and effective format is object-action.
cta-click
form-submit
video-play
external-link-click
This makes your event list in Umami instantly scannable and easy to understand.
Start Small and Focus on KPIs
Don't try to boil the ocean. Identify the 1-3 most important actions on your site. These are your Key Performance Indicators (KPIs). Is it a sale? A lead generation? A signup? Start by tracking those. You can always add more events later as new questions arise.
Document Your Events
It might seem like overkill, but a simple spreadsheet or document that lists your events, their names, and what they signify is invaluable. It ensures consistency, especially if multiple people are working on the site, and serves as a quick reference when you're analyzing your data months down the line.
Making Sense of Your Data in Umami
Once you've implemented your events, where do you find them? In your Umami dashboard, you’ll see an "Events" section in the sidebar. This is your new command center. It will list all the event names you're tracking and the total count for each.
Clicking on any event name will drill down into the details, showing you a timeline of when it occurred and, crucially, any data payloads you sent along with it. This is where you’ll see the breakdown of your "plan-selection" event, proving that the Pro plan is, in fact, the most popular choice.
Mastering custom event tracking is the single most impactful step you can take to level up your analytics game. It elevates Umami from a simple, privacy-friendly pageview counter to a powerful tool for understanding genuine user engagement and intent. By moving beyond the "where" and focusing on the "what," you can finally start making data-informed decisions that truly improve your website and your business.
So, what's the one user action you wish you could measure right now? Start there. Implement one custom event today and watch the insights roll in.