Custom Events
Custom events let you record a conversion from your own JavaScript code at exactly the right moment. Instead of relying on a click or a URL change, you call avsb.track.event() yourself — inside a form submit handler, after a successful API call, when a user reaches a certain scroll depth, or at any other meaningful point in your application.
When to use custom events
Custom events are the right choice whenever a conversion cannot be captured by a click on a static element or by a URL change. Common use cases include:
- Form submissions— the "submit" event on a form fires before the server processes it, so you can track the submission attempt. Or wait for the API response to confirm success before recording the conversion.
- Purchases and checkouts — track the exact moment an order is confirmed, and pass the order total as a revenue value.
- Scroll depth — fire when a visitor scrolls to 50% or 100% of a long-form content page.
- Time on page — fire after a visitor spends 60 seconds on a page as a proxy for engagement.
- Video completions — fire when a video player emits its
endedevent. - Multi-step flows — fire when a visitor completes a specific step in a wizard or onboarding flow.
Finding the metric short ID
Every custom event metric has a numeric short ID that you use when calling avsb.track.event(). This ID is shown in the metrics list on your project's Metrics page, next to the metric name. It is also shown inside the metric detail panel when you click on a metric.
The short ID is a number — for example 12345. You will pass it as the first argument to avsb.track.event().
avsb.track.event('12345', ...) with quotes will not work. Always write avsb.track.event(12345, ...) without quotes.How to create a custom event metric
Go to the Metrics page
Click New Metric
Choose Custom as the type
Give it a name
Save the metric
Note the short ID
Calling avsb.track.event()
Place a call to avsb.track.event()in your JavaScript at the moment you want to record a conversion. The function takes two arguments: the metric's short ID and an optional data object.
1// Record a conversion for metric with short ID 123452avsb.track.event(12345);1document.querySelector('#checkout-form').addEventListener('submit', function() {2 avsb.track.event(12345, { revenue: 49.99 });3});1fetch('/api/subscribe', { method: 'POST', body: formData })2 .then(function(response) {3 if (response.ok) {4 avsb.track.event(12345);5 }6 });1var fired = false;2window.addEventListener('scroll', function() {3 if (fired) return;4
5 var scrollPct = (window.scrollY + window.innerHeight) / document.body.scrollHeight;6 if (scrollPct >= 0.5) {7 avsb.track.event(12345); // fired when visitor reaches 50% scroll depth8 fired = true;9 }10});1setTimeout(function() {2 avsb.track.event(12345); // fired after 60 seconds on page3}, 60000);Passing revenue data
When the conversion involves a monetary transaction, pass the amount as a revenue property in the second argument. This unlocks Revenue Impact calculations in your experiment results.
1avsb.track.event(12345, { revenue: 49.99 });Revenue should be a number representing the transaction amount in your primary currency. Do not pass currency symbols or formatted strings — only a plain number.
One conversion per visitor
Like all metric types in A vs B, custom events record at most one conversion per visitor. If you call avsb.track.event()multiple times for the same metric, only the first call is counted. Subsequent calls are silently ignored.