Enable events in your snippet
The standard Kiflo snippet does not include event support by default. To enable it, replace your existing snippet with the extended version below, which adds acallbacks array and an on function:
callbacks: []) and line 5 (on: function(...)). Everything else stays the same. Replace YOUR_API_KEY with your actual API key from Kiflo’s Integration settings.
Place this extended snippet in the
<head> of your page, just as you would the standard snippet. The kjs variable is what you call .on(...) on to register event listeners.Subscribing to events
Once the extended snippet is in place, callkjs.on(eventName, callback) to subscribe. You can subscribe to as many events as you need, and register multiple listeners for the same event.
Event: ready
The ready event fires every time the Kiflo JS snippet finishes loading on the page. It is always raised — whether or not the visitor arrived through a partner referral link. Use this event when you need to run code that depends on the SDK being available, regardless of whether a tracking cookie exists.
Parameters:
string | undefined
The referral tracking code stored in the browser cookie, or
undefined if no tracking cookie is present for the current visitor.Event: cookie.ready
The cookie.ready event fires only when a referral tracking cookie is available — either because it was already set on a previous visit, or because it was just written for the first time as the current page loaded. It will not fire if the visitor has no partner referral cookie.
Parameters:
string
The referral tracking code from the browser cookie. This value is always a non-empty string when
cookie.ready fires.Because
cookie.ready only fires for visitors with an active referral cookie, it will not run for organic visitors who arrived directly. If you need to handle both cases, use ready instead.Choosing the right event
Full example: inject tracking code into a form
kifloTrackingCode is included in the POST body. Pass its value to the Kiflo REST API from your server to attribute the new customer to the correct partner.