Stedefast

Modules

Analytics

1 min read

The analytics module integrates Cloudflare Web Analytics for privacy-friendly page view tracking, plus a custom events system for tracking user interactions.

Installation

pnpm add @stedefast/module-analytics

Setup

// stedefast.config.ts
import { defineConfig } from "@stedefast/core";
import { AnalyticsModule } from "@stedefast/module-analytics";

export default defineConfig({
  // ...
  modules: [
    AnalyticsModule({
      beaconToken: "YOUR_CF_WEB_ANALYTICS_TOKEN",
    }),
  ],
});

Getting a beacon token

  1. Go to the Cloudflare dashboard → Web Analytics
  2. Add your site and copy the beacon token
  3. Set it in your config or as CF_ANALYTICS_TOKEN in .dev.vars

What gets tracked

Cloudflare Web Analytics tracks page views with no cookies and no cross-site tracking. Data is aggregated and available in your Cloudflare dashboard.

The module's static export writes a summary to dist/data/analytics/summary.json at build time — this powers the analytics view in the admin panel.

Custom events

Track custom events from islands or templates:

// In an island component
import { trackEvent } from "@stedefast/module-analytics/hooks";

trackEvent("download", { file: "resume.pdf" });

Custom events appear in the admin analytics view grouped by event name.

Privacy

  • No cookies set
  • No cross-site tracking
  • No PII collected
  • Fully compliant with GDPR and CCPA
  • Data processed by Cloudflare, not sent to third parties