@pmeweb/analytics
v2.0.0
Published
PmeWeb first-party analytics: beacon component + forwarding shim. Counting rules live in the central pmeweb-analytics worker, NOT here.
Readme
@pmeweb/analytics
First-party, cookie-free analytics for PmeWeb sites. Two exports:
Analytics.astro— rendered once byBase.astro; inlines the beacon (pageviews, visits, events, LCP) as one inline script, no extra request. PassnotFoundon the 404 route only.forwardCollect(request, env.ANALYTICS, ctx)— routePOST /api/pmw-collectto it in the site worker. Forwards to the centralpmeweb-analyticsworker over a service binding; always returns 204.
Site wrangler.jsonc needs the service binding:
"services": [{ "binding": "ANALYTICS", "service": "pmeweb-analytics" }]Counting a conversion
Pageviews, visits, outbound/tel/mailto/CTA clicks and LCP need no wiring. Two things do, because the beacon cannot observe them for itself:
form_start— putdata-pmw-formon the<form>. Declarative; it fires on first focus.the conversion — call it from your submit handler, on success:
window.pmw?.event('form'); // a contact/lead form window.pmw?.event('newsletter'); // a newsletter signupThe
?.is required, not defensive style.window.pmwis assigned only after the beacon's opt-outs (excluded host,pmw_ignore, webdriver), so on those the object does not exist and the call correctly vanishes.
Valid types are whatever the central worker's EVENT_TYPES accepts. An unknown
one is dropped there, never thrown here — a beacon that throws on a typo breaks
the page it is measuring.
2.0.0 — the #intake-success contract is gone
v1 counted a conversion by observing the hidden attribute of an element with
the hardcoded id #intake-success. It is removed. It fitted exactly one
conversion type, and its failure mode was silence: an id that matches nothing
looks identical to a form nobody submitted, which is how three sites reported
zero conversions for weeks with working forms. Replace each sentinel reveal with
the window.pmw?.event(...) call above; the site's own success panel keeps doing
whatever it already did.
Counting rules (bot filtering, visit definition, caps) live in the central worker — a site being one version behind this package is harmless. Breaking changes to the beacon payload require a MAJOR version and a coordinated central-worker deploy.
Design: websites/docs/superpowers/specs/2026-08-21-first-party-analytics-design.md
