Sending custom events
Once the snippet has loaded, window.upbeat sends a custom event:
upbeat("Signup");upbeat("Signup", { plan: "Pro" });| Argument | Type | Rules |
|---|---|---|
name |
string | Required and not empty. Leading and trailing spaces are removed; names longer than 100 characters are cut. |
props |
object | Optional. A plain object whose values are strings, numbers or booleans. See Properties. |
The function returns nothing and never throws. Invalid calls are ignored.
Events show in the dashboard’s Events panel and can be used in goals and funnels.
Calling it before the script has loaded
Section titled “Calling it before the script has loaded”With defer, the snippet runs after the page has been parsed. Code that runs earlier would find no window.upbeat. To queue those calls, paste this line above the snippet, once:
<script>window.upbeat=window.upbeat||function(){(upbeat.q=upbeat.q||[]).push(arguments)}</script><script defer src="https://c.upbeatanalytics.eu/s.js"></script>Calls made before the snippet loads are kept and sent right after the page view. If tracking is off for the visitor (see Do Not Track), they are dropped.
If you can’t add the queue line, check for the function before calling it:
window.upbeat?.("Signup");Examples
Section titled “Examples”A button:
<button onclick="upbeat('Download brochure')">Download</button>A form, after it was sent successfully:
form.addEventListener("submit", async (e) => { e.preventDefault(); const res = await fetch(form.action, { method: "POST", body: new FormData(form) }); if (res.ok) upbeat("Contact form sent", { topic: form.topic.value });});React or another framework:
declare global { interface Window { upbeat?: (name: string, props?: Record<string, string | number | boolean>) => void; }}
export function track(name: string, props?: Record<string, string | number | boolean>) { window.upbeat?.(name, props);}Properties
Section titled “Properties”Properties describe the event, never the person. The collector checks each property on its own, and drops the property (not the whole event) when:
- its key is empty, longer than 40 characters, or is or ends in
id,email,mail,phone,user,uid,iporname(as a whole word:user_idandnameare dropped,usernameis not); - its value isn’t a string, number or boolean, is longer than 200 characters, or looks like an email address or a phone number.
At most 10 properties are kept per event.
| Call | Kept |
|---|---|
upbeat("Signup", { plan: "Pro", seats: 5 }) |
plan, seats |
upbeat("Signup", { plan: "Pro", user_id: "u_81" }) |
plan |
upbeat("Contact", { from: "jane@example.com" }) |
none, the event alone |
upbeat("Search", { results: 0, filters: ["a"] }) |
results |
Numbers and booleans are stored as text, so 5 and "5" are the same value.
Limits
Section titled “Limits”- At most 100 custom events per page view. Further calls on the same page view are ignored, which protects your stats from runaway loops. A new page view, including a single-page-app navigation, starts again at 0.
- Events are counted per page view, never per person. See Custom events.