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

em-content-insights

v1.2.0

Published

Privacy-first post analytics for EmDash CMS. Per-post views, read rate, time on page, and referrer tracking — all self-hosted.

Readme

em-content-insights

Privacy-first post analytics for EmDash CMS. Know how your content performs without compromising your readers' privacy.

No cookies. No fingerprinting. No third-party services. All data stays in your EmDash instance.

What you get

  • Views per post with unique visitor approximation
  • Read rate based on real scroll depth and attention time
  • Scroll depth milestones (25%, 50%, 75%, 100%)
  • Engaged views (10s+ active attention with interaction)
  • Recirculation tracking (clicks to internal links)
  • Time on page via active attention tracking (visible + focused, 60s inactivity timeout)
  • Referrer breakdown showing where your traffic comes from
  • Trend indicators comparing current period vs previous
  • Admin dashboard widget with top posts at a glance
  • Full analytics page with timeseries charts, scroll depth funnel, top posts table, and referrer pie chart

Quick start

1. Install

npm install em-content-insights

2. Register the plugin

// astro.config.mjs
import { postAnalytics } from "em-content-insights";

export default defineConfig({
  integrations: [
    emdash({
      plugins: [postAnalytics()],
    }),
  ],
});

3. Add the beacon to your layout

---
// src/layouts/Base.astro (or your base layout)
import BeaconScript from "em-content-insights/astro";
---

<html>
  <body>
    <slot />
    <BeaconScript />
  </body>
</html>

That's it. The <BeaconScript /> component inlines a lightweight tracking script (~1.5KB) that automatically detects post content and starts tracking.

Configuration

The plugin works out of the box with zero configuration. Optionally customize the path prefix:

postAnalytics({
  pathPrefix: "/blog/", // default: "/posts/"
})

Or change it at runtime from the admin UI under Settings > Post Analytics > Post URL Prefix.

How it works

Tracking

  1. The <BeaconScript /> component renders an inline script on every page
  2. On page load, it sends a view event via navigator.sendBeacon()
  3. As the reader scrolls, it sends scroll events at 25%, 50%, 75%, and 100% depth milestones
  4. After 10 seconds of active attention with interaction, it sends an engaged event
  5. When the reader has scrolled 75%+ and spent enough time reading (estimated from content length), it sends a read event
  6. If the reader clicks an internal link, it sends a recirc event
  7. When the reader leaves, it sends a ping with total active attention time

All events hit a public plugin route (POST /_emdash/api/plugins/post-analytics/track) that validates the payload, filters bots, and stores the data.

Storage

The plugin uses a hybrid storage model:

  • Raw events (events collection) preserve full granularity for future analysis
  • Daily aggregates (daily_stats collection) power fast admin queries

The admin UI reads from daily aggregates, so dashboard performance is constant regardless of traffic volume.

Privacy

| Concern | How it's handled | |---------|-----------------| | Cookies | None | | IP addresses | Hashed with a daily-rotating salt. Raw IPs are never stored. | | Fingerprinting | None | | Cross-page tracking | None. Each pageview is independent. | | Do Not Track | Honored. If navigator.doNotTrack === "1", the beacon does nothing. | | Bot filtering | User-Agent based filtering for known crawlers |

Admin UI

Dashboard widget

Shows on the EmDash admin home page:

  • Total views and visitors for the last 7 days with trend indicators
  • Top 5 posts ranked by views

Analytics page

Accessible from the admin sidebar under Post Insights:

  • Date range selector (7 / 30 days)
  • Stat cards: total views, unique visitors, read rate, avg time on page
  • Timeseries chart with views, engaged views, and reads over time
  • Scroll depth funnel chart
  • Top posts table sortable by views, visitors, read rate, and avg time
  • Referrer pie chart
  • Country breakdown (when running on Cloudflare)

API routes

All routes are available at /_emdash/api/plugins/post-analytics/.

| Route | Auth | Method | Description | |-------|------|--------|-------------| | track | Public | POST | Receives beacon events | | stats | Admin | GET | Aggregated stats. Params: pathname, days | | top-posts | Admin | GET | Ranked posts. Params: days, limit |

Requirements

  • EmDash ^0.1.0
  • Astro ^6.0.0
  • No external services or API keys required

Development

git clone https://github.com/facuzarate04/em-content-insights.git
cd em-content-insights
npm install
npm test

Running tests

npm test           # single run
npm run test:watch # watch mode

Project structure

src/
  index.ts                # Plugin descriptor (build time)
  sandbox-entry.ts        # Plugin definition: hooks, routes, admin UI (runtime)
  beacon.ts               # Client-side tracking script generator
  astro/
    BeaconScript.astro    # Drop-in Astro component for the tracking beacon
  __tests__/              # Vitest test suite

Capabilities

| Capability | Purpose | |-----------|---------| | read:content | Resolve post titles for admin display | | network:fetch | Reserved for future license validation | | page:inject | Auto-inject beacon via page:fragments (when supported by EmDash runtime) |

License

AGPL-3.0