The insights beacon
Mount once, track everything, never break the site.
Updated
On this page
Mounting
The tracker mounts once in the site's root layout, browser-side, with the public key:
"use client";
import { useEffect } from "react";
import { usePathname } from "next/navigation";
import { lps } from "@/lib/lps";
export default function AnalyticsTracker() {
const pathname = usePathname();
useEffect(() => {
lps.insights.init({ autoPageviews: false, autoClicks: true });
}, []);
useEffect(() => {
lps.insights.notifyRouteChange(); // SPA navigations become pageviews
}, [pathname]);
return null;
}
What it captures
- Pageviews — driven by route-change notifications in SPA frameworks (auto-pageviews exist for non-SPA pages).
- Clicks — links, buttons and
[data-track]elements automatically; opt any subtree out withdata-no-track. - Custom events and conversions —
lps.insights.track("menu_view", { category: "flower" }),lps.insights.conversion(0, { name: "lead" }). - Attribution — a persistent visitor id (localStorage) carries first-touch and last-touch UTM parameters across the whole journey: a visitor who lands on
?utm_source=googlestill attributes to google three pages later.
Delivery discipline
- Events are batched and flushed via
sendBeacon/keepalive, so navigation and tab-close don't lose the tail. - Every failure is silent. Analytics can never break the site — a down collector costs data, never a render.
- The collector endpoint (
POST /api/site/insights) accepts the public key from allowed origins only, like every other public read.
The platform dashboard reads the results per site: totals, bucketed timeseries, top pages, referrers, and UTM source/medium/campaign breakdowns.