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

@narrowbeam/browser

v1.1.0

Published

Privacy-first browser analytics tracking for Narrowbeam

Readme

@narrowbeam/browser

Privacy-first browser analytics tracking for Narrowbeam. Track page views and custom actions without cookies or persistent user identifiers.

Features

  • 🔒 Privacy-First: No cookies, no persistent tracking
  • 📊 Automatic Page View Tracking: Works with SPAs and traditional sites
  • 🎯 Custom Action Tracking: Track button clicks and custom events
  • 📱 Framework Agnostic: Works with React, Vue, Svelte, vanilla JS, etc.
  • 🚀 Lightweight: Small bundle size with minimal dependencies
  • 🔄 Dual Usage: Use via script tag or npm package

Installation

Via npm/yarn

npm install @narrowbeam/browser
# or
yarn add @narrowbeam/browser

Via CDN (Script Tag)

Use a single script tag with the Narrowbeam loader:

<script>
  (function(w,d,e,s,n) {
    w=w[n]=w[n]||{q:[],onReady:function(c){w.q.push(c)}}
    e=d.createElement(e);e.async=1;e.src=s
    s=d.getElementsByTagName('script')[0];s.parentNode.insertBefore(e,s)
  })(window,document,'script','https://unpkg.com/@narrowbeam/browser/dist/narrowbeam.min.js','narrowbeam')

  window.narrowbeam.onReady(function() {
    window.narrowbeam.init({
      orgKey: 'your-org-key-here'
    })
  })
</script>

Usage

NPM Package Usage

import { narrowbeam } from '@narrowbeam/browser'

// Initialize with your organization key
narrowbeam.init({
  orgKey: 'your-org-key'
})

// Track custom actions
narrowbeam.trackAction('signup-click')
narrowbeam.trackAction('button-press')

// Manually track a page view
narrowbeam.trackPageView()

// Check for route changes (useful for SPAs)
narrowbeam.checkPageChange()

Framework Examples

React

// src/analytics.js
import { narrowbeam } from '@narrowbeam/browser'

narrowbeam.init({
  orgKey: 'your-org-key'
})
// src/main.jsx or src/index.jsx
import './analytics'
import React from 'react'
import ReactDOM from 'react-dom/client'
import App from './App'

ReactDOM.createRoot(document.getElementById('root')).render(
  <React.StrictMode>
    <App />
  </React.StrictMode>
)
// src/App.jsx
import { narrowbeam } from '@narrowbeam/browser'

function App() {
  const handleSignup = () => {
    narrowbeam.trackAction('signup-click')
    // ... your signup logic
  }

  return (
    <button onClick={handleSignup}>
      Sign Up
    </button>
  )
}

Vue 3

<script setup>
import { onMounted } from 'vue'
import { narrowbeam } from '@narrowbeam/browser'

onMounted(() => {
  narrowbeam.init({ orgKey: 'your-org-key' })
})

const handleSignup = () => {
  narrowbeam.trackAction('signup-click')
  // ... your signup logic
}
</script>

<template>
  <button @click="handleSignup">Sign Up</button>
</template>

Next.js (App Router)

// components/analytics.js
'use client'

import { narrowbeam } from '@narrowbeam/browser'

narrowbeam.init({
  orgKey: process.env.NEXT_PUBLIC_NARROWBEAM_ORG_KEY
})

export default function Analytics() {
  return null
}
// app/layout.js
import Analytics from '@/components/analytics'

export default function RootLayout({ children }) {
  return (
    <html lang="en">
      <body>
        <Analytics />
        {children}
      </body>
    </html>
  )
}

Automatic Action Tracking

You can track clicks automatically using data attributes without writing any JavaScript:

<!-- With npm package -->
<button data-narrowbeam-action-name="cta-click">
  Get Started
</button>

<a href="/pricing" data-narrowbeam-action-name="pricing-link">
  View Pricing
</a>

When users click these elements, the action will be automatically tracked.

Configuration Options

narrowbeam.init({
  orgKey: 'your-org-key'  // Required: Your Narrowbeam organization key
})

API Reference

narrowbeam.init(config)

Initialize the Narrowbeam tracking.

Parameters:

  • config.orgKey (string, required): Your organization key

narrowbeam.trackAction(actionName)

Track a custom action.

Parameters:

  • actionName (string, required): Name of the action to track

Example:

narrowbeam.trackAction('newsletter-signup')

narrowbeam.trackPageView()

Manually track a page view. This is automatically called on initialization and route changes, but you can call it manually if needed.

Example:

narrowbeam.trackPageView()

narrowbeam.checkPageChange()

Check if the current path has changed and track a page view if needed. Useful for framework-specific routing.

Example:

// In your router
router.afterEach(() => {
  narrowbeam.checkPageChange()
})

Features

UTM Parameter Tracking

Narrowbeam automatically captures UTM parameters from the URL:

  • utm_source
  • utm_medium
  • utm_campaign
  • utm_term
  • utm_content

Single Page Application (SPA) Support

Narrowbeam automatically detects route changes in SPAs by monitoring:

  • popstate events (browser back/forward)
  • history.pushState calls
  • history.replaceState calls

Page Leave Tracking

Narrowbeam tracks when users leave pages using:

  • beforeunload event
  • pagehide event

Support

For issues and questions, please visit GitHub Issues.