> This page is for version v2 (default).
> For other versions, use one of these documentation indexes:
> - v2 (default): https://developers-beta.clearpay.co.uk/v-2/llms.txt
> - v1: https://developers-beta.clearpay.co.uk/v-1/llms.txt

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://developers-beta.clearpay.co.uk/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://developers-beta.clearpay.co.uk/_mcp/server.

# Using Clearpay analytics

## Setting up Clearpay analytics collection

Clearpay analytics are collected as part of the ClearpayJS library. The Clearpay JavaScript library must be included in all pages where analytics metrics might be gathered.

To include the Clearpay JavaScript library in a page, add the following `<script>` tag in the `<head>` HTML section:

**`ClearpayJS`**

```html ClearpayJS
<script src="https://portal.afterpay.com/afterpay.js"</script>
```

## Order confirmation analytics

Clearpay analytics records an `order_confirmation` event each time a customer reaches an order confirmation screen. Each order confirmation event records whether Clearpay was used, as well as the order value, currency, merchant ID, and order ID.

| Property           | Type              | Description                                                                                         |
| :----------------- | :---------------- | :-------------------------------------------------------------------------------------------------- |
| `is_afterpay_used` | boolean           | If true, Clearpay was used to pay for this order.                                                   |
| `merchant_id`      | string            | Clearpay merchant ID.                                                                               |
| `order_amount`     | string            | Value of the order that has been captured.                                                          |
| `order_currency`   | string            | The currency of the order, using [ISO 4217](https://en.wikipedia.org/wiki/ISO_4217) currency codes. |
| `order_id`         | string (optional) | Optional field containing the merchant identifier of this order.                                    |

If a GBP 100 order was completed on your site using Clearpay with an Order Number of 11443 you would use the following attributes:

```javascript
AfterPay.analyticsEvent('order_confirmation', {
	is_afterpay_used: true,
	merchant_id: '1123533532',
	order_amount: '100',
	order_currency: 'GBP',
	order_id: '11443'
});
```