Skip to content

Framework guides

Each integration starts Beacon once, only in the browser, and records pageviews from the framework’s own navigation event after the new page’s <title> is set. They take the same options as init(), except autoPageviews. Import track, identify and page from @tbdhdev/beacon-sdk anywhere.

The integrations support the current major version of each framework: React 19 (Next.js 16), Vue 3.5, Nuxt 4, SvelteKit 3 with Svelte 5, Solid 2 with Solid Router 2, Solid 1.9 with Solid Router 0.16 (SolidStart 2), TanStack Router and Start 1, and Astro 7.

Framework Import Pageviews from
React (Vite, React Router) @tbdhdev/beacon-sdk the History API
Next.js (App Router) @tbdhdev/beacon-sdk/react your page() calls
TanStack Router, TanStack Start @tbdhdev/beacon-sdk/tanstack-router router.subscribe("onRendered")
Vue 3 (Vue Router) @tbdhdev/beacon-sdk/vue router.afterEach, after the render
Nuxt 4 @tbdhdev/beacon-sdk/nuxt the page:loading:end hook
Svelte @tbdhdev/beacon-sdk the History API
SvelteKit @tbdhdev/beacon-sdk/sveltekit afterNavigate
Solid, SolidStart (Solid Router) @tbdhdev/beacon-sdk/solid useLocation() changes
Astro @tbdhdev/beacon-sdk/astro page load and astro:page-load

A client-only app can start Beacon at module scope. Automatic pageviews pick up React Router navigations.

main.tsx
import { init } from "@tbdhdev/beacon-sdk";
init({
websiteId: "your-website-uuid",
endpoint: "https://beacon.example.com/x/e",
});

Render <Beacon> from @tbdhdev/beacon-sdk/react in the root layout. It’s a client component, so the layout can stay a server component. For exact pageviews, turn autoPageviews off and record them from the router:

app/layout.tsx
import { Beacon } from "@tbdhdev/beacon-sdk/react";
import { Suspense, type ReactNode } from "react";
import { Pageviews } from "./pageviews";
export default function RootLayout({ children }: { children: ReactNode }) {
return (
<html lang="en">
<body>
{children}
<Beacon
websiteId="your-website-uuid"
endpoint="https://beacon.example.com/x/e"
autoPageviews={false}
/>
{/* useSearchParams() needs a Suspense boundary on statically rendered pages. */}
<Suspense>
<Pageviews />
</Suspense>
</body>
</html>
);
}
app/pageviews.tsx
"use client";
import { page } from "@tbdhdev/beacon-sdk";
import { usePathname, useSearchParams } from "next/navigation";
import { useEffect } from "react";
export function Pageviews() {
const pathname = usePathname();
const search = useSearchParams().toString();
useEffect(() => page(), [pathname, search]);
return null;
}

Pass the router to initBeacon() where you create it. It works with the React, Solid and Vue flavors. In TanStack Start, getRouter() also runs on the server; Beacon only starts in the browser.

src/router.tsx
import { createRouter } from "@tanstack/react-router";
import { initBeacon } from "@tbdhdev/beacon-sdk/tanstack-router";
import { routeTree } from "./routeTree.gen";
export function getRouter() {
const router = createRouter({ routeTree });
initBeacon(router, {
websiteId: "your-website-uuid",
endpoint: "https://beacon.example.com/x/e",
});
return router;
}

Install the plugin with your router. useBeacon() gives components track, identify and page.

main.ts
import { beacon } from "@tbdhdev/beacon-sdk/vue";
createApp(App)
.use(router)
.use(beacon, {
websiteId: "your-website-uuid",
endpoint: "https://beacon.example.com/x/e",
router,
})
.mount("#app");

Add the module and configure it under beacon. useBeacon() is auto-imported.

nuxt.config.ts
export default defineNuxtConfig({
modules: ["@tbdhdev/beacon-sdk/nuxt"],
beacon: {
websiteId: "your-website-uuid",
endpoint: "https://beacon.example.com/x/e",
},
});

The options are public runtime config, so they can also come from NUXT_PUBLIC_BEACON_WEBSITE_ID, NUXT_PUBLIC_BEACON_ENDPOINT and so on. Nuxt reads such a variable only for a key that exists, so list the key under beacon (for example websiteId: "").

Without SvelteKit, call init() before mounting.

main.ts
import { init } from "@tbdhdev/beacon-sdk";
import { mount } from "svelte";
import App from "./app.svelte";
init({
websiteId: "your-website-uuid",
endpoint: "https://beacon.example.com/x/e",
});
mount(App, { target: document.querySelector("#app")! });

Call initBeacon() from the root layout, during component initialization.

src/routes/+layout.svelte
<script lang="ts">
import { initBeacon } from "@tbdhdev/beacon-sdk/sveltekit";
let { children } = $props();
initBeacon({ websiteId: "your-website-uuid", endpoint: "https://beacon.example.com/x/e" });
</script>
{@render children()}

Render <Beacon> once inside the router. On Solid 2, keep it inside the <Loading> that wraps your routes so the first pageview carries the first route’s title.

import { Beacon } from "@tbdhdev/beacon-sdk/solid";
<Beacon
websiteId="your-website-uuid"
endpoint="https://beacon.example.com/x/e"
/>;

In SolidStart, render it in the root of <Router> in src/app.tsx. Solid Router handles same-origin links itself, so give file links a download attribute to have them tracked as downloads.

Add the integration. It records each page load and, with <ClientRouter />, every astro:page-load.

astro.config.mjs
import beacon from "@tbdhdev/beacon-sdk/astro";
import { defineConfig } from "astro/config";
export default defineConfig({
integrations: [
beacon({
websiteId: "your-website-uuid",
endpoint: "https://beacon.example.com/x/e",
}),
],
});

Call init() once from client-only code. Automatic pageviews follow any router that uses the History API.