Script tag
The script tag is the quickest way to start. It works on any site, framework or not, and needs no npm install. Copy it from the website’s Settings tab under Tracking code:
<script defer src="https://beacon.example.com/x/s.js" data-website-id="your-website-uuid" data-outbound="true"></script>Put it in the <head> of every page. Pageviews are recorded automatically, including
client-side navigations in single-page apps.
Options
Section titled “Options”Each option is a data-* attribute on the script tag. The dashboard fills them in from the
website’s settings.
| Attribute | What it does |
|---|---|
data-website-id |
Required. Without it the script does nothing. |
data-outbound |
"true" tracks clicks on links to other hosts. |
data-downloads |
"true" tracks clicks on file links. |
data-web-vitals |
"true" sends LCP, INP, CLS and TTFB. |
data-hash-routing |
"true" records /#/pricing as /pricing. |
Custom events
Section titled “Custom events”The script exposes window.beacon:
beacon.track("signup_clicked", { plan: "pro" }); // prop values: string, number or booleanbeacon.identify("user_123", { plan: "pro" }); // your own user id, kept in memory onlybeacon.page(); // record a pageview yourself, e.g. beacon.page("/virtual/path")Calls made before the script loads are lost unless you add the queue stub first. It’s under the script tag on the Tracking code card:
<script> window.beacon = window.beacon || { q: [], track(...a) { this.q.push(["track", ...a]); }, identify(...a) { this.q.push(["identify", ...a]); }, page(...a) { this.q.push(["page", ...a]); }, };</script>The script replays the queued calls once it loads.
Without JavaScript
Section titled “Without JavaScript”Any element with data-beacon-event sends an event when clicked. Each data-beacon-prop-*
attribute becomes a property:
<button data-beacon-event="signup_clicked" data-beacon-prop-plan="pro"> Sign up</button>TypeScript
Section titled “TypeScript”The TypeScript tab on the tracking code card has a beacon.d.ts with types for
window.beacon. Copy it into your project for autocomplete.
Renamed script or event path
Section titled “Renamed script or event path”If an ad blocker starts listing your script or event path, a superadmin can rename them in Settings → Tracking. Update the snippet on your sites afterwards.