# Page API

URL: https://docs.ablyft.com/developers/reference/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](https://docs.ablyft.com/guides/audiences-and-delivery/pages/).

## Set up a page for the API

1. Open the page (in your project, under **Pages**) and find the section **Trigger**.
2. In **Trigger**, select **API (manual activation by an API / JavaScript call)**.
3. 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.
4. Copy the code from **API trigger code**. It updates with the API name you enter.

```html
<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.

```js
// 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

```js
ablyft.push({ eventType: 'deactivatePage', pageApiName: 'checkout-step-2' });
```

What happens depends on the page's [deactivation mode](https://docs.ablyft.com/guides/audiences-and-delivery/pages/#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](https://docs.ablyft.com/developers/reference/javascript-api/#use-the-api-before-the-snippet-has-loaded).

## Reference

See [`activatePage` / `deactivatePage`](https://docs.ablyft.com/developers/reference/javascript-api/push/#activatepage) in the `push` reference.

## Next steps

- [SPA navigation](https://docs.ablyft.com/developers/application-integration/spa-navigation/): Single-page apps and other page triggers.
- [ablyft.push()](https://docs.ablyft.com/developers/reference/javascript-api/push/): All event types.

