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

@addilytics/hono

v0.0.1

Published

Hono server analytics and bundled browser relay.

Downloads

194

Readme

@addilytics/hono

Hono middleware that records pageviews from the final Context.res. It does not read, clone, or replace the response body.

import { addilytics } from '@addilytics/hono';
import { Hono } from 'hono';

const app = new Hono();
const analytics = addilytics({
	endpoint: 'https://addilytics.example',
	siteKey: 'ak_...'
});

app.use('*', analytics);

Register authentication or context initialization first, Addilytics second, and routes or response-mutating middleware after it. Hono runs Addilytics as an outer layer around later handlers, so it sees the final response after they finish. Relay requests return from Addilytics without running later middleware. Redirects, JSON responses, and server errors are skipped by default.

Only requests dispatched through this Hono app count. A CDN response, prerendered file, client-side route change without an HTML request, or browser back-forward cache restore bypasses the middleware.

Custom events

The middleware carries a typed track() method.

app.post('/signup', async (context) => {
	await analytics.track(context, 'signup', {
		props: { source: 'pricing' }
	});
	return context.body(null, 204);
});

track() uses the same bot filtering and identity rules as the core client.

Identity and background delivery

Use user when identity lives in a Hono variable or binding.

const analytics = addilytics({
	endpoint: 'https://addilytics.example',
	siteKey: 'ak_...',
	user: (context) => context.get('userId')
});

app.use('*', authMiddleware);
app.use('*', analytics);

The user resolver can read context.get() only when an earlier middleware sets that value. A resolver that reads the raw request can stay inside the Addilytics options.

Hono does not expose a portable client-address API. Supply ip when the deployment runtime keeps the address on a binding, request property, or trusted context value:

const analytics = addilytics({
	endpoint: 'https://addilytics.example',
	siteKey: 'ak_...',
	ip: (context) => context.env.incomingRequestIp
});

The resolver may be async. If it throws, the adapter reports an ip error and records the event without an address. It does not fall back to forwarded headers after a resolver failure. Without an ip resolver, trustProxy: true enables the core client's forwarded-header fallback.

The adapter uses context.executionCtx.waitUntil() on runtimes that provide it. Elsewhere it waits for delivery before the request completes. You can supply waitUntil when a platform exposes its background-task hook somewhere else.

Analytics failures never replace or reject an otherwise successful application response.

Browser navigation modes

Server tracking remains the default. Use hybrid when Hono records the initial document and your client router reports later navigations. Use client when the browser owns every pageview. Client mode keeps custom server events enabled but skips automatic server document capture.

Configure authentication before the analytics middleware, then put routes after it so the relay can use established identity without reaching application handlers:

const analytics = addilytics({
	endpoint: process.env.ADDILYTICS_ENDPOINT!,
	mode: 'hybrid',
	relayPath: '/internal/analytics',
	siteKey: process.env.ADDILYTICS_SITE_KEY!
});

app.use('*', authMiddleware);
app.use('*', analytics);

Hono has no client router, so its browser entry re-exports the generic tracker. Call pageview() after your router commits a navigation, including the initial page:

import { createBrowserTracker } from '@addilytics/hono/browser';

const tracker = createBrowserTracker({
	endpoint: '/internal/analytics',
	mode: 'hybrid'
});

router.afterEach((url) => tracker.pageview(url));

Hybrid mode skips the first browser call because the server owns it. Client mode sends that call. The core tracker deduplicates repeated URLs and ignores hash-only changes unless you set trackHashChanges: true. Applications should also call pageview() with force: true for a persisted pageshow event if back-forward cache restores count as new visits.

The browser sends only a generated event ID, timestamp, pathname, allowlisted campaign query, and referrer. The relay adds trusted server metadata and user identity. It accepts only its exact path and rejects cross-origin or malformed requests. The site key and ingest endpoint stay in server code, and this package does not inject or load an external script.