npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

umami-helper

v0.0.3

Published

Helper library for Umami tracking

Readme

umami-helper

A helper library for Umami tracking that simplifies UTM parameter handling and automatic script loading. This library helps you integrate Umami analytics into your application with built-in UTM tracking persistence and event queuing.

Installation

npm install umami-helper

Usage

1. Initialize UTM Tracking (Optional but Recommended)

The UtmTrackService captures UTM parameters from the URL, persists them to localStorage, and automatically attaches them to future events. This is useful for tracking user acquisition across sessions.

import { UtmTrackService } from 'umami-helper';

const utmService = new UtmTrackService();

// Initialize on app startup (e.g., in your root component or main entry file)
// This will capture UTM params from the current URL and store them.
utmService.init();

// Optionally pass default values
utmService.init({
  utm_source: 'direct',
  utm_medium: 'organic'
});

2. Initialize Umami Service

The UmamiService handles loading the Umami script and sending events.

import { UmamiService } from 'umami-helper';

// Configuration
const config = {
  websiteId: 'YOUR-WEBSITE-ID-FROM-UMAMI', // Required
  scriptUrl: 'https://analytics.umami.is/script.js' // Optional, defaults to this URL
};

// Initialize the service
// You can pass the same utmService instance if you want to share the state
const umamiService = new UmamiService(config, utmService);

3. Track Events

Use the track method to send events to Umami. It automatically attaches any stored UTM parameters to the event data.

// Track a simple event
umamiService.track('signup-button-clicked');

// Track an event with custom properties
umamiService.track('purchase', {
  productId: '123',
  currency: 'USD',
  value: 99.99
});

The service handles:

  • Script Loading: Automatically injects the Umami script if not present.
  • Queuing: If the script hasn't loaded yet, events are queued and sent once the script is ready.
  • UTM Context: Merges stored UTM parameters with your event properties automatically.

API Reference

UtmTrackService

Responsible for managing UTM parameters (source, medium, campaign, term, content) and referrer information.

Methods

  • init(defaults?: Record<string, string>): void

    • Captures UTM parameters from window.location.search.
    • Merges them with stored values (localStorage) and any provided defaults.
    • Persists the result to localStorage for future sessions.
  • getUtmDetail(): Record<string, string>

    • Returns all stored UTM parameters as a key-value object.
  • getUtmDetailInObject(): UtmTrackContext

    • Returns a structured object with typed fields:
      • utm_source
      • utm_medium
      • utm_campaign
      • utm_term
      • utm_content
      • referrer
      • tracked_by
  • getUtmDetailByKey(key: string): string | undefined

    • Retrieves a specific UTM value by its key (e.g., 'utm_source').
  • clearUtmDetail(): void

    • Clears all stored UTM data from localStorage.

UmamiService

Responsible for interacting with the Umami tracking script.

Constructor

constructor(config: UmamiConfig, utmTrackService?: UtmTrackService)
  • config: Configuration object (see below).
  • utmTrackService: Optional instance of UtmTrackService. If not provided, a new instance is created internally.

Methods

  • track(event: string, props?: any): void
    • Sends an event to Umami.
    • event: Name of the event.
    • props: Optional object with event properties. stored UTM details are automatically merged into this object.

Interfaces

UmamiConfig

interface UmamiConfig {
  /** The specific Website ID generated in your Umami dashboard */
  websiteId: string;
  
  /** 
   * URL to your Umami script. 
   * Default: 'https://analytics.umami.is/script.js' 
   */
  scriptUrl?: string; 
}

UtmTrackContext

interface UtmTrackContext {
  utm_source: string | null;
  utm_medium: string | null;
  utm_campaign: string | null;
  utm_term: string | null;
  utm_content: string | null;
  referrer: string | null;
  tracked_by: 'umami_helper';
}