Custom events
Track clicks, sign-ups, form submissions and anything else with one function call.
Custom events show up in Events, can be used as goals and funnel steps, and can be filtered and broken down by their properties everywhere in the dashboard.
JavaScript API
stancelens("event", "signup");
// With properties (strings, numbers or booleans)
stancelens("event", "signup", { plan: "pro", seats: 5, trial: true });window.stancelens exists once the script has run. To call it earlier (in inline scripts, or before a deferred script loads), add this stub above the script tag. The tracker replays queued calls when it starts:
<script>
window.stancelens = window.stancelens || function () {
(window.stancelens.q = window.stancelens.q || []).push(arguments);
};
</script>HTML attributes (no code)
Turn on the data-tagged module on your script tag, then add data-el-event to any element: a click sends that event. Every other data-el-* attribute (or data-el-prop-*) becomes a property.
<script defer data-site="SITE_ID" data-tagged src="https://stancelens.com/e.js"></script>
<button data-el-event="signup" data-el-plan="pro">Start free</button>
<a href="/pricing" data-el-event="cta_click" data-el-location="hero">See pricing</a>On <form> elements, data-el-event fires on submit instead of click.
Naming & limits
- Event names: up to 120 characters. We recommend
snake_caseverbs likesignuporinvite_sent. Names starting with$are reserved for built-in events. - Up to 50 properties per event. Keys are cut to 100 characters and string values to 500. Values can be strings, numbers, booleans or null; nested objects are stored as JSON.
- Don't put personal data (emails, names) in properties. Use identify instead.
Built-in events
| Event | Sent by | When |
|---|---|---|
pageview | core | Page load and every SPA navigation |
$engagement | core | Visible time on a page; added to that page view's duration |
$identify | core | identify with a user ID |
$outbound | data-outbound | Click on a link to another host (url) |
$download | data-downloads | Click on a link to a file (url, ext) |
$scroll | data-scroll | Deepest scroll depth on a page (depth) |
$web_vital | data-vitals | LCP, INP, CLS, FCP and TTFB (details) |
$error | data-errors | Uncaught errors and unhandled promise rejections |
$exposure | stancelens.flag() | First time a flag resolves on a page load, false included (flag, variant) |
Modules are opt-in: see Tracker modules.
Server-side events
Send events from your backend with POST /api/v1/events. See the REST API.