ablyft.push()
Send goals, page commands, listeners and consent changes to ABlyft.
ablyft.push(event) takes an object with an eventType and the parameters of that type.
It can also be called before the snippet has loaded, see queueing.
eventType | Purpose |
|---|---|
custom | Trigger a custom goal |
revenue | Trigger a revenue goal with a value |
reevaluateAudiences | Re-check audiences of experiments on active pages |
forceVariation | Force a variation for a visitor |
activatePage | Activate a page with the API trigger |
deactivatePage | Deactivate a page |
addListener | Run a function when the snippet finished its run |
enableTrackingConsent | Store that the visitor consented to tracking |
disableTrackingConsent | Store that the visitor declined tracking |
custom
Triggers a goal of type custom, identified by its API name.
| Parameter | Type | Required | Description |
|---|---|---|---|
eventType | 'custom' | Yes | |
eventName | string | Yes | API name of the goal. Unknown names are ignored silently. |
eventValue | number | No | Defaults to 0. Only meaningful for goals with the measurement type Value. |
window.ablyft = window.ablyft || [];
window.ablyft.push({
eventType: 'custom',
eventName: 'newsletter-signup',
});revenue
Triggers a goal of type revenue. Same parameters as custom; pass the revenue as eventValue, a number (not a string) in the currency you use. Without it, the value is 0.
window.ablyft = window.ablyft || [];
window.ablyft.push({
eventType: 'revenue',
eventName: 'purchase',
eventValue: 49.9, // order value
});reevaluateAudiences
Re-evaluates the audiences of all experiments on the currently active pages, for example after a data layer value or cookie changed.
ablyft.push({ eventType: 'reevaluateAudiences' });forceVariation
Forces a variation for an experiment. Queued calls of this type are applied immediately when the snippet loads, before the experiments are evaluated.
| Parameter | Type | Description |
|---|---|---|
experimentId | number | ID of the experiment |
variationId | number | ID of the variation to show |
window.ablyft = window.ablyft || [];
window.ablyft.push({
eventType: 'forceVariation',
experimentId: 12345678,
variationId: 98765432,
});The call can be placed before or after the ABlyft snippet, but it has to happen before the experiment is evaluated for the visitor, that is before the audience check and before the visitor has been assigned to a variation. It is useful for developers who test the real flow, including goals, in a browser or an automated test.
Only for visitors without an assignment
The forced variation is used when the visitor is assigned to the experiment for the first time. If this browser already has an assignment for the experiment (stored in the configured storage, see Storage & privacy), that assignment stays. Clear the storage or use a private window. The visitor still has to pass the other checks (environment, audiences, exclusion groups). Forced visitors are real participants: their data counts in your results. For a quick look at a variation without any code, use the preview mode.
activatePage
Activates a page, for example one configured with the API trigger. Identify the page by ID or API name; if pageId is given, it takes precedence.
If the page does not exist, an error is logged and an ablyftError event is dispatched.
| Parameter | Type | Description |
|---|---|---|
pageId | number | ID of the page |
pageApiName | string | API name of the page |
ablyft.push({ eventType: 'activatePage', pageApiName: 'checkout-step-2' });Setup of the page and the effect of the call: Page API.
deactivatePage
Deactivates a page. Same parameters and error behavior as activatePage. The effect depends on the page's deactivation mode, see
Page API.
ablyft.push({ eventType: 'deactivatePage', pageApiName: 'checkout-step-2' });addListener
Registers a listener that is called (without arguments) after the snippet finished a run, including runs triggered by reInit().
| Parameter | Type | Description |
|---|---|---|
listener.type | 'lifecycleEnd' | The only supported listener type |
listener.handler | function | Called without arguments |
ablyft.push({
eventType: 'addListener',
listener: {
type: 'lifecycleEnd',
handler: () => console.log('ABlyft finished its run'),
},
});There is only one handler slot. Registering a second lifecycleEnd listener replaces the first one.
enableTrackingConsent
Stores the visitor's consent (ablyft_tracking_consent with value 1) in the configured storage. Data that was held in temporary storage until now is moved to the configured storage as well.
When consent is granted for the first time, ABlyft re-initializes with reInit({ resetStates: true }).
Call this from your consent manager. See Consent manager.
// Example: call when the visitor accepts statistics cookies
ablyft.push({ eventType: 'enableTrackingConsent' });disableTrackingConsent
Stores that the visitor declined (ablyft_tracking_consent with value 0) in the configured storage.
ablyft.push({ eventType: 'disableTrackingConsent' });To read the current state, use ablyft.get('trackingConsentEnabled').