Analytics
Add one component to your layout and the dashboard shows which pages readers open, with views and visits per page and per day.
What it records
Each pageview sends the page path and a random ID for the current browser tab, kept in sessionStorage, which groups views into visits. It sets no cookies and sends nothing else: no referrer, campaign parameters, query string or scroll depth.
Single-page apps are covered: the beacon also records a view when the path changes through history.pushState, replaceState or back and forward navigation. Fetching posts at build time does not count as a view, so a page without the component shows no data rather than zero readers.
Astro
Put it in the layout every page uses:
---
import Analytics from "@jamwidgets/astro/Analytics"
---
<Analytics siteKey={import.meta.env.JAMWIDGETS_SITE_KEY} />siteKey is optional when the page has a <meta name="jamwidgets-site-key"> tag. Pass endpoint only if you run Jamwidgets somewhere other than jamwidgets.com.
React, SolidJS and plain JavaScript
Call initAnalytics once in the browser, for example in your root component's mount effect. Further calls do nothing.
import { initAnalytics } from "@jamwidgets/core"
initAnalytics({ siteKey: "your-site-key" })@jamwidgets/react and @jamwidgets/solid re-export initAnalytics. Use trackPageview({ path }) to record a single view yourself.
Page view counters
To show a running count on the page itself, use the Views widget described in the Astro guide.