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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@senzops/web

v1.2.0

Published

Senzor Web Analytics SDK

Downloads

321

Readme

@senzops/web

The official, lightweight, and privacy-conscious web analytics SDK for Senzor.

Senzor Web is a tiny (< 2KB gzipped) TypeScript agent designed to track page views, visitor sessions, and engagement duration without impacting your website's performance. It works seamlessly with Single Page Applications (SPAs) like React, Next.js, and Vue.

🚀 Installation

Option 1: NPM (Recommended for React/Vue/Next.js)

npm install @senzops/web
# or
yarn add @senzops/web

Option 2: CDN (HTML Script Tag)

Add this to the of your website:

<script src="https://cdn.jsdelivr.net/gh/senzops/web-agent/dist/index.global.js"></script>
<script>
  window.Senzor.init({
    webId: "YOUR_WEB_ID_HERE",
  });
</script>

🛠 Usage

In React / Next.js

Initialize the agent once in your root layout or main app component.

import { useEffect } from "react";
import { Senzor } from "@senzops/web";

export default function App({ Component, pageProps }) {
  useEffect(() => {
    Senzor.init({
      webId: "req_123456789", // Get this from your Senzor Dashboard
      // endpoint: '[https://custom-api.com](https://custom-api.com)' // Optional: For self-hosting
    });
  }, []);

  return <Component {...pageProps} />;
}

🧠 Working Principle

The Senzor Agent is designed to be "Fire and Forget". It operates asynchronously to ensure it never blocks the main thread or slows down page loads.

1. Identity & Sessions

  • Visitor ID: When a user visits, we generate a random UUID and store it in localStorage. This allows us to track unique visitors over a 1-year period.
  • Session ID: We generate a UUID in sessionStorage. This persists across tab reloads but clears when the browser/tab is closed, allowing us to calculate Bounce Rates and Session Duration.
  • Privacy: We do not use cookies. All data is first-party.

2. Event Tracking

The agent listens for specific browser events to capture accurate metrics:

  • Initialization: Sends a pageview event immediately.
  • History API (pushState): Automatically detects route changes in SPAs (e.g., clicking a Link in Next.js) and sends a new pageview.
  • Visibility Change: If a user minimizes the tab or switches to another tab, we pause the "Duration" timer and send a ping.

3. Duration & The "Ping"

Calculating how long a user spends on a page is difficult because users often close tabs abruptly. Senzor solves this with a Heartbeat/Ping mechanism:

  1. When a page loads, we start a timer (startTime).
  2. When the user navigates away (beforeunload) or hides the tab (visibilitychange), we calculate duration = Now - startTime.
  3. We send a ping event with this duration.
  4. The Backend receives this ping and updates the previous pageview entry in the database, incrementing its duration.

4. Data Transmission

We prioritize data reliability using navigator.sendBeacon:

  • Reliability: sendBeacon queues data to be sent by the browser even after the page has unloaded/closed. This ensures we don't lose data when users close the tab.
  • Fallback: If sendBeacon is unavailable, we fall back to a standard fetch request with keepalive: true.

⚙️ Configuration Options

| Option | Type | Default | Description | | :------- | :----- | :---------------- | :---------------------------------------------------------------------- | | webId | string | Required | The unique ID of your website generated in the Senzor Dashboard. | | endpoint | string | api.senzor.dev... | URL of the ingestion API. Use this if you are self-hosting the backend. |

📦 Development

To build the agent locally:

  1. Clone & Install
   git clone https://github.com/Senzops/web-agent.git
   cd web-agent
   npm install
  1. Build
    Uses tsup to bundle for ESM, CJS, and IIFE (Global variable).

     npm run build
  2. Output

    • dist/index.js (CommonJS)
    • dist/index.mjs (ES Modules)
    • dist/index.global.js (Browser Script)

📄 License

MIT © Senzor