BeaconDocsDashboard

Getting started

Install the tag

One snippet in the <head> of every page. It loads in the background after your page, so it never slows anything down.

The snippet

Copy it from your project's Settings → Install in the dashboard, where your tag ID is already filled in, and paste it into the <head> of every page.

html
<script>window.beacon = window.beacon || function () { var a = arguments; return new Promise(function (r) { [].push.call(a, r); (beacon.q = beacon.q || []).push(a); }); };</script>
<script async src="https://beacon.endevre.com/b.js?id=B-XXXXXX"></script>

The first line is a tiny queue: any beacon(…) calls your code makes before the tag has loaded are kept and sent once it arrives, so you never have to wait for it. Every call returns a promise, which is how experiments, flags and live values hand back their answer. The second line loads the tag itself, about 5 KB, from Beacon's own servers.

Frameworks

Single-page apps need nothing extra: Beacon notices route changes made with the History API (Next.js, React Router, Vue Router, SvelteKit, Astro and the rest) and counts each one as a page view. In Next.js, the root layout is the natural place for it:

Next.js (App Router)
// app/layout.tsx
import Script from "next/script";

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en">
      <head>
        <Script id="beacon-queue" strategy="beforeInteractive">
          {`window.beacon = window.beacon || function () { var a = arguments; return new Promise(function (r) { [].push.call(a, r); (beacon.q = beacon.q || []).push(a); }); };`}
        </Script>
        <Script src="https://beacon.endevre.com/b.js?id=B-XXXXXX" strategy="afterInteractive" />
      </head>
      <body>{children}</body>
    </html>
  );
}

If you use TypeScript, declare the global once so calls type-check:

ts
// beacon.d.ts: lets TypeScript know about the global beacon() function
declare function beacon(command: string, ...args: unknown[]): void;

Allowed domains

Beacon only accepts data from the domains listed in the project's Settings → Details, so nobody can send events into your project from somewhere else. List each one exactly as it appears in the address bar: example.com and www.example.com are separate entries, and so is every subdomain. Add localhost (any port) if you want to see your own development visits.

What's recorded automatically

  • Page views: the path (never anything after ?) and title, plus where the visitor came from and any campaign tags.
  • Clicks on links and buttons: the element's text and, for links, where they go.
  • Page exits: how long the page was actually on screen and how far down people scrolled.

See the reference for the exact event names and properties. To leave an element out of click tracking and session replay, add data-beacon-ignore to it.

Check it works

Open your site in another tab, then Realtime in Beacon: you should appear within about ten seconds, and the project's Settings page switches to "Receiving data". If nothing arrives, check that your domain is in the allowed list and that no browser extension is blocking beacon.endevre.com.

Content Security Policy

If your site sends a Content-Security-Policy header, allow Beacon's domain for scripts and connections:

text
script-src  https://beacon.endevre.com;
connect-src https://beacon.endevre.com;
The queue line is an inline script. With a strict CSP, move it into one of your own script files or give it your nonce.