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

@liwan.dev/tracker

v1.8.0

Published

Tracking script for Liwan, an open-source analytics platform

Readme

Liwan Tracker

Tracking script for Liwan, an open-source analytics platform.

Tracker versions follow the Liwan release needed for their latest features, with patch releases numbered independently. Older trackers still work with newer servers, but need an update to use new features.

For server-side events, use @liwan.dev/api.

Install

# npm
npm install @liwan.dev/tracker

# Bun
bun add @liwan.dev/tracker

# pnpm
pnpm add @liwan.dev/tracker

Usage

Pageviews

When the script is loaded directly in the browser, it will automatically send pageview events to the API endpoint specified in the data-api attribute (data-api is optional and defaults to the domain name the script is loaded from).

<script
  type="module"
  src="https://liwan.example.com/script.js"
  data-entity="example"
  data-api="https://liwan.example.com/api/event"
></script>

Pageviews send a best-effort exit signal when the page becomes hidden. Set data-exit="false" to disable exit tracking.

Set window.liwanProperties before loading the tracker to include properties on every pageview and custom event. You can update or delete keys later, and properties passed to event() take precedence.

<script>
  window.liwanProperties = { plan: "pro" };
</script>
<script type="module" src="https://liwan.example.com/script.js" data-entity="example"></script>

When importing the tracker, use setProperties() to update defaults. Set a key to null to remove it:

import { setProperties } from "@liwan.dev/tracker";

setProperties({ plan: "team" });
setProperties({ plan: null });

Globals in server-side environments are shared across requests. Pass request-specific properties to event() instead of setting global defaults.

To customize events, define a synchronous window.liwanTransformEvent function before the tracker loads. It runs for automatic pageviews and explicit event() calls, including custom events. The callback receives the normalized payload, including its name, sanitized URL, entity_id, and global properties, and should return the payload to send. Exit signals do not call the transformer. If you change the URL, avoid adding query parameters or fragments that contain personal data.

<script>
  window.liwanTransformEvent = (payload) => ({
    ...payload,
    properties: {
      ...payload.properties,
      section: new URL(payload.url).pathname.split("/")[1] || "home",
      event_type: payload.name,
    },
  });
</script>

Keep property values free of personal data. Events support at most 30 properties, with keys up to 64 characters and values up to 255 characters.

When using the package, call trackPageviews() to start automatic pageview tracking:

import { trackPageviews } from "@liwan.dev/tracker";

trackPageviews({
  endpoint: "https://liwan.example.com/api/event",
  entity: "example",
});

Calling trackPageviews() again logs a message and does not add another listener or send a duplicate pageview.

Custom events

Call event when an action happens. In the browser, the tracker uses the current page URL and referrer.

import { event } from "@liwan.dev/tracker";

await event("signup", {
  endpoint: "https://liwan.example.com/api/event",
  entity: "example",
  properties: { plan: "pro" },
});

API

export type EventOptions = {
  /**
   * The URL of the page where the event occurred.
   *
   * If not provided, the current page URL with only attribution query parameters preserved will be used.
   */
  url?: string;

  /**
   * The referrer of the page where the event occurred.
   *
   * If not provided, `document.referrer` will be used if available.
   */
  referrer?: string;

  /**
   * The API endpoint to send the event to.
   *
   * If not provided, either the `data-api` attribute or the url where the script is loaded from will be used.
   * Required in server-side environments.
   */
  endpoint?: string;

  /**
   * The entity that the event is associated with.
   *
   * If not provided, the `data-entity` attribute will be used.
   * Required for custom events.
   */
  entity?: string;

  /**
   * Whether to send a pageview exit signal when the page becomes hidden.
   *
   * Defaults to `true`. Ignored for custom events and in server-side environments.
   */
  exit?: boolean;

  /**
   * Custom properties to send with the event.
   */
  properties?: EventProperties;
};

export type EventProperties = Record<string, string | number | boolean | null | undefined>;

/** Set default properties for subsequent events. Pass `null` to remove a property. */
export function setProperties(properties: EventProperties): void;

/**
 * Sends an event to the Liwan API.
 *
 * @param name The name of the event. Defaults to "pageview".
 * @param options Additional options for the event. See {@link EventOptions}.
 * @returns A promise that resolves when the event has been sent.
 * @throws If {@link EventOptions.endpoint} is not provided in server-side environments.
 */
export function event(
  name: string = "pageview",
  options?: EventOptions
): Promise<void>;

/**
 * Starts automatically tracking pageviews.
 *
 * Sends an initial pageview immediately and tracks subsequent client-side
 * navigations using the Navigation API when available, with `popstate` as a fallback.
 *
 * @param options Options passed to each pageview event.
 */
export const trackPageviews: (options?: EventOptions) => void;

License

Licensed under the Apache License, Version 2.0.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in Liwan by you, as defined in the Apache-2.0 license, shall be licensed under Apache-2.0, without any additional terms or conditions.