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

@tryformation/formation-web-analytics-client

v0.2.0

Published

Light weight browser analytics client intended to be used with the formation-web-analytics server.

Downloads

299

Readme

Formation Web Analytics Client

npm version CI

Small browser tracker with a low-surprise API close to Google Analytics. Intended to be used together with our analytics server.

Install

npm install @tryformation/formation-web-analytics-client

Usage

import { createAnalytics } from '@tryformation/formation-web-analytics-client';

const analytics = createAnalytics({
  endpoint: 'https://analytics.example.com/collect',
  siteId: 'marketing-site',
  onError(error) {
    console.warn('analytics delivery failed', error.kind, error.status);
  },
});

analytics.page();
analytics.event('cta_click', { label: 'hero-demo-button' });

Script Tag Usage

<script src="/analytics.iife.js"></script>
<script>
  window.analytics.init({
    endpoint: 'https://analytics.example.com/collect',
    siteId: 'marketing-site'
  });

  window.analytics.event('signup_started');
</script>

Behavior

  • validates endpoint, siteId, event names, and identify user ids
  • sends page context (url, path, title, referrer) on all events
  • sends events with fetch
  • treats non-2xx responses and network failures as delivery errors
  • reports failures through the optional onError hook while keeping public tracking calls best-effort

Notes

  • Keep custom event names backend-compatible: letters, digits, _, ., :, and -
  • The wire format is intended to stay compatible with the collector in the sibling formation-web-analytics project
  • autoPageviews defaults to true; set it to false if you want full manual control
  • Transport uses fetch with keepalive: true for best-effort delivery while preserving HTTP response/error handling.

Testing In The Browser

  • Browser-based ad blockers and privacy extensions can block analytics requests entirely, even when the client is working correctly.
  • If events seem to disappear during manual testing, retry with ad blockers disabled, in a clean browser profile, or in a private window without extensions.
  • Open the browser developer tools and inspect the Network tab while triggering page(), event(), or identify().
  • Filter for your collector endpoint or fetch requests and confirm the request URL, status code, timing, and response.
  • Click the request and inspect the request payload/body to verify the event shape, identifiers, page context, and custom payload fields.
  • If you use automatic page views in an SPA, keep the Network tab open while navigating with pushState, replaceState, back/forward, and hash changes to confirm one request per navigation.

Public API

  • page(payload?)
  • event(type, payload?)
  • identify(userId, payload?)
  • setContext(payload)

Outputs

  • dist/analytics.js for ESM
  • dist/analytics.iife.js for script tags
  • dist/index.d.ts for types

Commands

  • npm run lint
  • npm run build
  • npm run test
  • npm run audit
  • npm run verify

Releases

  • Create and push a semver tag like 0.1.1
  • Wait until CI on main has completed successfully before pushing the release tag
  • GitHub Actions will run tests, build, and publish to npm using npm trusted publishing via OIDC
  • Configure the package's trusted publisher on npmjs.com to match .github/workflows/publish.yml