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

@dloizides/analytics-web

v1.0.1

Published

Product-agnostic web analytics layer for the dloizides.com portfolio: a guarded never-throws Umami event helper (track), first-touch UTM/ref/referrer attribution capture, and a snippet-injection helper that wires the Umami browser tracker by website-id. A

Readme

@dloizides/analytics-web

Product-agnostic web analytics layer for the dloizides.com portfolio. One shared vehicle so all four product web apps instrument Umami analytics identically, satisfying the mandatory web-app-standards analytics baseline.

It generalizes two existing implementations:

  • the kefi-marketing src/lib/track.ts pattern — a guarded, never-throws track() plus first-touch UTM/ref attribution;
  • the legacy BaseClient UmamiClient — the Umami send shape and PII redaction.

The package never imports a product, realm, or hardcoded website id. Each app supplies its own websiteId (from the Umami dashboard) and an enabled flag.

Install

npm install @dloizides/analytics-web

No runtime dependencies. Browser-only (every entry point no-ops under SSR/native where window/document are absent).

Quick start

import { createAnalytics } from '@dloizides/analytics-web';

// Once, at app bootstrap:
const analytics = createAnalytics({
  websiteId: import.meta.env.VITE_UMAMI_WEBSITE_ID, // per-app id
  enabled: import.meta.env.PROD,                     // off in dev/preview
});

analytics.injectSnippet();      // SPA only — see "Snippet placement" below
analytics.captureAttribution(); // snapshot first-touch UTM/ref/referrer

// At a conversion:
analytics.track('signup_submitted', { plan: 'pro', ...analytics.getAttribution() });

When enabled is false, createAnalytics returns a no-op facade — every method is inert and enabled is false — so call sites never need their own guards.

Public API

createAnalytics(config): Analytics

The app-facing facade. config:

| field | type | default | notes | | ----------- | --------- | --------------------------------------------- | -------------------------------------- | | websiteId | string | (required) | per-app Umami website id | | scriptSrc | string | https://analytics.dloizides.com/script.js | self-hosted Umami browser script | | enabled | boolean | true | false → fully inert no-op facade |

Returns { track, captureAttribution, getAttribution, injectSnippet, enabled }.

Standalone helpers

The facade is sugar over these, exported for direct use (e.g. Astro is:inline scripts that can't import a module facade easily):

  • track(event, props?) — fire a Umami event. Guarded: no-ops under SSR, when the snippet is absent (ad-blocker/CSP/dev), and swallows beacon throws. PII- looking props are redacted. Never blocks navigation.
  • captureAttribution() — snapshot utm_* + ref + document.referrer into sessionStorage on first touch (first-touch wins; idempotent per session).
  • getAttribution(): Record<string,string> — read back the snapshot.
  • getRef(): string | undefined — the ref from the snapshot.
  • injectSnippet({ websiteId, scriptSrc? }) — append the Umami <script defer ... data-website-id> to <head>. Idempotent (keyed by id).
  • isSnippetInjected(websiteId) — whether that snippet is already present.
  • sanitizeProps(props) — redact PII-looking keys (email/token/password/…).

Plus the Analytics, AnalyticsConfig, EventProps, UmamiTracker types and the DEFAULT_SCRIPT_SRC / ATTRIBUTION_KEY / UTM_KEYS / … constants.

Snippet placement

Umami needs its <script> on the page. There are two placements:

  • Static HTML (Astro marketing, Expo-web exported index.html) — hand-place the snippet in the static template (Expo strips <script> from React, so it must live in the exported HTML / Dockerfile, per the analytics skill's Expo gotcha). Then just call track/captureAttribution; do not also call injectSnippet.
  • SPA without a static template (poueni dashboard / Vite) — call analytics.injectSnippet() once at bootstrap.

isSnippetInjected / the idempotency of injectSnippet make double-injection during HMR safe.

License

MIT