Page API
Activate and deactivate pages from your own code with the API trigger.
A page in ABlyft defines on which URLs an experiment runs. Normally, ABlyft checks pages automatically. With the API trigger you decide yourself when a page is checked, by calling the snippet from your code. This is useful when a state of your site cannot be recognized from the URL, for example a step in a checkout that does not change the address.
For the concept of pages and URL rules, see Pages & URL targeting.
Set up a page for the API
- Open the page (in your project, under Pages) and find the section Trigger.
- In Trigger, select API (manual activation by an API / JavaScript call).
- Open Advanced Settings and check the API Name. It may contain letters, numbers, dashes and underscores and must be unique in the project. This name identifies the page in your code.
- Copy the code from API trigger code. It updates with the API name you enter.
<script>
window['ablyft'] = window['ablyft'] || [];
window['ablyft'].push({
eventType: 'activatePage',
pageApiName: 'checkout-step-2'
});
</script>checkout-step-2 is an example API name.
The API Name field is shown for every trigger, so you can also call activatePage for pages with another trigger.
The API trigger code is shown only when the trigger is API.
Activate a page
Call activatePage with the API name or the ID of the page. If you pass both, the ID is used.
// By API name
ablyft.push({ eventType: 'activatePage', pageApiName: 'checkout-step-2' });
// By ID
ablyft.push({ eventType: 'activatePage', pageId: 12345678 });When called, the snippet checks the page's URL rules and conditions as usual. If they match, the page becomes active, its pageview goals are triggered, and the experiments on the page are evaluated. If the page is already active, the call is ignored.
If the page does not exist, an error is logged to the console.
Deactivate a page
ablyft.push({ eventType: 'deactivatePage', pageApiName: 'checkout-step-2' });What happens depends on the page's deactivation mode. The reset
JavaScript of its experiments runs in the modes Reset and Force-reset. In mode Persistent, a deactivatePage
call has no effect: the page is never disabled.
Call before the snippet is loaded
push calls work before the snippet has loaded, because they are queued. See
the JavaScript API.
Reference
See activatePage / deactivatePage in the push reference.