Results & analytics
Custom events
Some conversions do not happen on a button adfit can see: a booking that is confirmed inside a widget, a video watched to the end, a step completed in your app. A custom event lets your own code tell adfit that it happened.
The one line of code
Wherever the conversion happens on your site, call:
window.adfit.track('booking_confirmed')That is the whole interface. adfit matches the name against your goals and counts a conversion if one of them uses it.
Set it up
Create a goal with a custom event trigger
On Goals, press Add goal, name it, and choose the trigger type Custom event.
Pick an event name
Type the name into Event name. adfit builds the code line from it while you type.
Copy the line
Press Copy code under the field.
Call it on your site
Add the call where the conversion happens (see where to put the call) and publish your page.
Test it
Open your page through the campaign's test link and trigger the action once (see Test that it arrives).
Naming rules
- Lowercase letters, numbers, dots, dashes and underscores, up to 64 characters. Capital letters and spaces are not allowed.
- An event name can belong to only one goal per site. adfit tells you with Another goal already uses this event name. if you reuse one.
- Pick something you will still understand in six months, for example
booking_confirmedordemo.requested.
What adfit ignores
- Anything you pass besides the name. A second argument is dropped in the browser and never sent, so no values from your page can leak into adfit through this call.
- Names that match no goal. An event no goal uses is discarded. You can leave calls in place while you decide whether to measure them.
- Repeat calls. A goal counts once per visitor and experiment, so calling it twice does not double a result.
Calling it early is safe
You do not have to wait for adfit to finish loading. Calls made before it is ready are kept and sent as soon as it is.
Where to put the call
Anywhere your page can run JavaScript at the moment the conversion happens. Three common shapes:
On a button
<button onclick="window.adfit.track('booking_confirmed')">
Confirm booking
</button>In your own script
document.querySelector('#confirm').addEventListener('click', function () {
window.adfit.track('booking_confirmed');
});After a successful request
fetch('/api/booking', { method: 'POST', body: data })
.then(function (response) {
if (response.ok) {
window.adfit.track('booking_confirmed');
}
});On the common platforms
- WordPress: add the call with a code snippets plugin, or in your theme where the confirmation is rendered. Many form plugins fire their own JavaScript event on success that you can listen for.
- Webflow: use the custom code area of the page (or of the site) and attach a listener to the element, as in the second example above.
- Shopify: add the call in your theme where the action happens. adfit does not run inside Shopify's checkout, so measure a step on your storefront instead, for example an add to cart confirmation.
- Static HTML and Framer: put the call in the element's click handler or in an embedded script block.
Test that it arrives
Open the page through the campaign's test link
Copy it from the Targeting card of the personalization (see Targeting and the test link). The test link always shows you the personalized version.
Trigger the action
Do on the page exactly what your visitors would do.
Check that nothing errors
In your browser's developer console, calling
window.adfit.track('booking_confirmed')by hand must not raise an error. If it sayswindow.adfitis undefined, the snippet is not running on that page. See Verify your connection.
Your own test visits stay out of the results
Visits through the test link are not counted in your A/B results, so your own testing never moves a verdict. They do count towards your monthly pageview allowance like any other delivered page. To see the event in your results, let a real visitor arrive through your ad or your campaign link.
If the conversion does not show up
- Check the spelling of the name against the goal, including underscores and dots.
- Check that the goal's Tracking switch is on, and that A/B results is on if you expect it in an experiment card.
- The visitor must have matched one of your campaigns first. A conversion from a visitor adfit never assigned to a campaign is not attributed.
- Results are not instant: a conversion needs a few minutes to reach your numbers.
- Check that measurement is on for the site (see Consent and visitor tracking).
Related
- Goals: the other four trigger types that need no code at all.
- Reading A/B results: where your conversions end up.
- Troubleshooting: what to do when the snippet is not running on a page.