{"_id":"em-content-insights","_rev":"3-956a1a0f9f1415a1744a17d7d1ac2b29","name":"em-content-insights","dist-tags":{"latest":"1.2.0"},"versions":{"1.0.0":{"name":"em-content-insights","version":"1.0.0","keywords":["emdash","emdash-plugin","analytics","post-analytics","privacy"],"license":"AGPL-3.0-only","_id":"em-content-insights@1.0.0","maintainers":[{"name":"facuzarate04","email":"facundo.zarate97@gmail.com"}],"homepage":"https://github.com/facuzarate04/em-content-insights#readme","bugs":{"url":"https://github.com/facuzarate04/em-content-insights/issues"},"dist":{"shasum":"03f0b316478135256a8d9e4681e0146ab2c50184","tarball":"https://registry.npmjs.org/em-content-insights/-/em-content-insights-1.0.0.tgz","fileCount":6,"integrity":"sha512-KckrdXtKgnWrHSPmsZ+DMiJT5zxXcwffChyQDQn0HgpODKo2JXIvLyaeY7r+QbUT4f364YZApNrB3Qq87RfQtg==","signatures":[{"sig":"MEYCIQDfWj5sRn5BlAPUbCPs0CF0EptpycIgEcLmoZd7dmUguAIhAPhUYdexpdt2IBWsxZ76QrVRxzL814jAEpv5Jz0+yGPp","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":68898},"type":"module","engines":{"node":">=18.0.0"},"exports":{".":"./src/index.ts","./sandbox":"./src/sandbox-entry.ts"},"gitHead":"4551316b96f258a84bbb8f483cd22b5854af60d8","scripts":{"test":"vitest run","build":"tsc","test:watch":"vitest"},"_npmUser":{"name":"facuzarate04","email":"facundo.zarate97@gmail.com"},"repository":{"url":"git+https://github.com/facuzarate04/em-content-insights.git","type":"git"},"_npmVersion":"11.9.0","description":"Privacy-first post analytics for EmDash CMS. Per-post views, read rate, time on page, and referrer tracking — all self-hosted.","directories":{},"_nodeVersion":"24.14.0","_hasShrinkwrap":false,"devDependencies":{"emdash":"^0.1.0","vitest":"^4.1.2","typescript":"^5.7.0"},"peerDependencies":{"emdash":"^0.1.0"},"_npmOperationalInternal":{"tmp":"tmp/em-content-insights_1.0.0_1775141326632_0.6443796233039774","host":"s3://npm-registry-packages-npm-production"}},"1.1.0":{"name":"em-content-insights","version":"1.1.0","keywords":["emdash","emdash-plugin","analytics","post-analytics","privacy"],"license":"AGPL-3.0-only","_id":"em-content-insights@1.1.0","maintainers":[{"name":"facuzarate04","email":"facundo.zarate97@gmail.com"}],"homepage":"https://github.com/facuzarate04/em-content-insights#readme","bugs":{"url":"https://github.com/facuzarate04/em-content-insights/issues"},"dist":{"shasum":"46ee26c6162e5114fa4a390b481cc7fb8e4979a4","tarball":"https://registry.npmjs.org/em-content-insights/-/em-content-insights-1.1.0.tgz","fileCount":7,"integrity":"sha512-vbN3Z58xwZo9rumbuF0earFb/3ZtyzpGEgQtUhJREfp3OQWjvi5EruaAYGThaWGOKmROx/XK+cR1/gpMzBtAkg==","signatures":[{"sig":"MEUCIQCPgTj8jsFgJhXBiL/qLbECRnl6a+xf7pdUFnJVnRLJIgIgR1qED5TJcH/nbRGqXvaFVqHMOlCgLGQkQt5BbmYW1Ms=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":77639},"type":"module","engines":{"node":">=18.0.0"},"exports":{".":"./src/index.ts","./astro":"./src/astro/BeaconScript.astro","./sandbox":"./src/sandbox-entry.ts"},"gitHead":"483fb5351a12e2e2abf830a47a92988536e8231d","scripts":{"test":"vitest run","build":"tsc","test:watch":"vitest"},"_npmUser":{"name":"facuzarate04","email":"facundo.zarate97@gmail.com"},"repository":{"url":"git+https://github.com/facuzarate04/em-content-insights.git","type":"git"},"_npmVersion":"11.9.0","description":"Privacy-first post analytics for EmDash CMS. Per-post views, read rate, time on page, and referrer tracking — all self-hosted.","directories":{},"_nodeVersion":"24.14.0","_hasShrinkwrap":false,"devDependencies":{"emdash":"^0.1.0","vitest":"^4.1.2","typescript":"^5.7.0"},"peerDependencies":{"emdash":"^0.1.0"},"_npmOperationalInternal":{"tmp":"tmp/em-content-insights_1.1.0_1775159286974_0.24198076662032397","host":"s3://npm-registry-packages-npm-production"}},"1.2.0":{"name":"em-content-insights","version":"1.2.0","description":"Privacy-first post analytics for EmDash CMS. Per-post views, read rate, time on page, and referrer tracking — all self-hosted.","type":"module","license":"AGPL-3.0-only","exports":{".":"./src/index.ts","./sandbox":"./src/sandbox-entry.ts","./astro":"./src/astro/BeaconScript.astro"},"scripts":{"test":"vitest run","test:watch":"vitest","build":"tsc"},"repository":{"type":"git","url":"git+https://github.com/facuzarate04/em-content-insights.git"},"homepage":"https://github.com/facuzarate04/em-content-insights#readme","bugs":{"url":"https://github.com/facuzarate04/em-content-insights/issues"},"engines":{"node":">=18.0.0"},"peerDependencies":{"emdash":"^0.1.0"},"devDependencies":{"emdash":"^0.1.0","typescript":"^5.7.0","vitest":"^4.1.2"},"keywords":["emdash","emdash-plugin","analytics","post-analytics","privacy"],"gitHead":"5174f476513b03e19b4201be4b4c6bf2e43e4803","_id":"em-content-insights@1.2.0","_nodeVersion":"24.14.0","_npmVersion":"11.9.0","dist":{"integrity":"sha512-LGMusnH1D2fkFi1xibgQhZE0ZxoMa6d4g3UMpzP11ja1nEhL1e7LnUce9pnhQH2ARUvTbjNuj0ayNN9nDDRHtg==","shasum":"c1b3e22d4c077ba08bbaac9f512c54cad44ba3fc","tarball":"https://registry.npmjs.org/em-content-insights/-/em-content-insights-1.2.0.tgz","fileCount":7,"unpackedSize":79811,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIALl2SfO83yZJmjuvS+edLyk20j/EYZxBihO43gKbxxKAiEAlLrjZm89HFS5pApDy5up2FOLKq7DAPPyLXnAvM3QTEo="}]},"_npmUser":{"name":"facuzarate04","email":"facundo.zarate97@gmail.com"},"directories":{},"maintainers":[{"name":"facuzarate04","email":"facundo.zarate97@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/em-content-insights_1.2.0_1775172128301_0.6924750507649875"},"_hasShrinkwrap":false}},"time":{"created":"2026-04-02T14:48:46.519Z","modified":"2026-04-02T23:22:08.904Z","1.0.0":"2026-04-02T14:48:46.802Z","1.1.0":"2026-04-02T19:48:07.134Z","1.2.0":"2026-04-02T23:22:08.487Z"},"bugs":{"url":"https://github.com/facuzarate04/em-content-insights/issues"},"license":"AGPL-3.0-only","homepage":"https://github.com/facuzarate04/em-content-insights#readme","keywords":["emdash","emdash-plugin","analytics","post-analytics","privacy"],"repository":{"type":"git","url":"git+https://github.com/facuzarate04/em-content-insights.git"},"description":"Privacy-first post analytics for EmDash CMS. Per-post views, read rate, time on page, and referrer tracking — all self-hosted.","maintainers":[{"name":"facuzarate04","email":"facundo.zarate97@gmail.com"}],"readme":"# em-content-insights\n\nPrivacy-first post analytics for [EmDash CMS](https://github.com/emdash-cms/emdash). Know how your content performs without compromising your readers' privacy.\n\n**No cookies. No fingerprinting. No third-party services. All data stays in your EmDash instance.**\n\n## What you get\n\n- **Views** per post with unique visitor approximation\n- **Read rate** based on real scroll depth and attention time\n- **Scroll depth milestones** (25%, 50%, 75%, 100%)\n- **Engaged views** (10s+ active attention with interaction)\n- **Recirculation tracking** (clicks to internal links)\n- **Time on page** via active attention tracking (visible + focused, 60s inactivity timeout)\n- **Referrer breakdown** showing where your traffic comes from\n- **Trend indicators** comparing current period vs previous\n- **Admin dashboard widget** with top posts at a glance\n- **Full analytics page** with timeseries charts, scroll depth funnel, top posts table, and referrer pie chart\n\n## Quick start\n\n### 1. Install\n\n```bash\nnpm install em-content-insights\n```\n\n### 2. Register the plugin\n\n```typescript\n// astro.config.mjs\nimport { postAnalytics } from \"em-content-insights\";\n\nexport default defineConfig({\n  integrations: [\n    emdash({\n      plugins: [postAnalytics()],\n    }),\n  ],\n});\n```\n\n### 3. Add the beacon to your layout\n\n```astro\n---\n// src/layouts/Base.astro (or your base layout)\nimport BeaconScript from \"em-content-insights/astro\";\n---\n\n<html>\n  <body>\n    <slot />\n    <BeaconScript />\n  </body>\n</html>\n```\n\nThat's it. The `<BeaconScript />` component inlines a lightweight tracking script (~1.5KB) that automatically detects post content and starts tracking.\n\n## Configuration\n\nThe plugin works out of the box with zero configuration. Optionally customize the path prefix:\n\n```typescript\npostAnalytics({\n  pathPrefix: \"/blog/\", // default: \"/posts/\"\n})\n```\n\nOr change it at runtime from the admin UI under **Settings > Post Analytics > Post URL Prefix**.\n\n## How it works\n\n### Tracking\n\n1. The `<BeaconScript />` component renders an inline script on every page\n2. On page load, it sends a `view` event via `navigator.sendBeacon()`\n3. As the reader scrolls, it sends `scroll` events at 25%, 50%, 75%, and 100% depth milestones\n4. After 10 seconds of active attention with interaction, it sends an `engaged` event\n5. When the reader has scrolled 75%+ and spent enough time reading (estimated from content length), it sends a `read` event\n6. If the reader clicks an internal link, it sends a `recirc` event\n7. When the reader leaves, it sends a `ping` with total active attention time\n\nAll events hit a public plugin route (`POST /_emdash/api/plugins/post-analytics/track`) that validates the payload, filters bots, and stores the data.\n\n### Storage\n\nThe plugin uses a **hybrid storage model**:\n\n- **Raw events** (`events` collection) preserve full granularity for future analysis\n- **Daily aggregates** (`daily_stats` collection) power fast admin queries\n\nThe admin UI reads from daily aggregates, so dashboard performance is constant regardless of traffic volume.\n\n### Privacy\n\n| Concern | How it's handled |\n|---------|-----------------|\n| Cookies | None |\n| IP addresses | Hashed with a daily-rotating salt. Raw IPs are never stored. |\n| Fingerprinting | None |\n| Cross-page tracking | None. Each pageview is independent. |\n| Do Not Track | Honored. If `navigator.doNotTrack === \"1\"`, the beacon does nothing. |\n| Bot filtering | User-Agent based filtering for known crawlers |\n\n## Admin UI\n\n### Dashboard widget\n\nShows on the EmDash admin home page:\n- Total views and visitors for the last 7 days with trend indicators\n- Top 5 posts ranked by views\n\n### Analytics page\n\nAccessible from the admin sidebar under **Post Insights**:\n- Date range selector (7 / 30 days)\n- Stat cards: total views, unique visitors, read rate, avg time on page\n- Timeseries chart with views, engaged views, and reads over time\n- Scroll depth funnel chart\n- Top posts table sortable by views, visitors, read rate, and avg time\n- Referrer pie chart\n- Country breakdown (when running on Cloudflare)\n\n## API routes\n\nAll routes are available at `/_emdash/api/plugins/post-analytics/`.\n\n| Route | Auth | Method | Description |\n|-------|------|--------|-------------|\n| `track` | Public | POST | Receives beacon events |\n| `stats` | Admin | GET | Aggregated stats. Params: `pathname`, `days` |\n| `top-posts` | Admin | GET | Ranked posts. Params: `days`, `limit` |\n\n## Requirements\n\n- EmDash `^0.1.0`\n- Astro `^6.0.0`\n- No external services or API keys required\n\n## Development\n\n```bash\ngit clone https://github.com/facuzarate04/em-content-insights.git\ncd em-content-insights\nnpm install\nnpm test\n```\n\n### Running tests\n\n```bash\nnpm test           # single run\nnpm run test:watch # watch mode\n```\n\n### Project structure\n\n```\nsrc/\n  index.ts                # Plugin descriptor (build time)\n  sandbox-entry.ts        # Plugin definition: hooks, routes, admin UI (runtime)\n  beacon.ts               # Client-side tracking script generator\n  astro/\n    BeaconScript.astro    # Drop-in Astro component for the tracking beacon\n  __tests__/              # Vitest test suite\n```\n\n## Capabilities\n\n| Capability | Purpose |\n|-----------|---------|\n| `read:content` | Resolve post titles for admin display |\n| `network:fetch` | Reserved for future license validation |\n| `page:inject` | Auto-inject beacon via `page:fragments` (when supported by EmDash runtime) |\n\n## License\n\n[AGPL-3.0](./LICENSE)\n","readmeFilename":"README.md"}