SPB Git
562 B · 8 lines tsx
1"use client";2import { useEffect } from "react";3/** Records one page view per visitor per day (server-side de-duplicated, bots excluded). Sends nothing else. */4export function ViewBeacon({ slug }: { slug: string }) {5  useEffect(() => { try { navigator.sendBeacon?.("/api/events", new Blob([JSON.stringify({ kind: "view", slug })], { type: "application/json" })) ?? fetch("/api/events", { method: "POST", body: JSON.stringify({ kind: "view", slug }), headers: { "Content-Type": "application/json" }, keepalive: true }); } catch {} }, [slug]);6  return null;7}8
Files · 734affbc3f56470ca2e43d159e14b200279bfbfc
Menu

Theme