> ## Documentation Index
> Fetch the complete documentation index at: https://docs.onsleek.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Order extraction

> Specific integration instructions to enable order extraction.

Sleek’s Web Extension SDK can extract order details from pages your users are visiting. This feature allows you to capture successful transactions and order details. This documentation will guide you through the integration process.

<Warning>
  This document assumes that you have already integrated the Sleek web extension SDK into your
  extension. If you haven't, please refer to the [Web Extension SDK integration
  guide](/web-ext-sdk-reference/introduction).
</Warning>

## Enable order extraction

There are two ways to get order information from Sleek:

1. **Manual Extraction**: Extract order information from a specific tab using the `extractOrder` method
2. **Event-Based**: Subscribe to the `ORDER_EXTRACTED` event to receive order information automatically

<Info>
  Order extraction is only supported on `cart`, `checkout`, and `checkoutComplete`.
</Info>

### Manual Extraction

To extract order information from an cart, checkout or order confirmation page, you can use the
`extractOrder` method:

```javascript theme={null}
import { getWebExtSdk } from "@sleek/web-ext-sdk";

const order = await getWebExtSdk().onTab(tabId).extractOrder(); // Returns Promise<ExtractOrderResult>
```

Sleek will only return order information on pages that are classified as
`cart`, `checkout` or `checkoutComplete`. To determine the page classification,
you can use the `classifyPage` method. See the [page classification
guide](/web-ext-sdk-reference/page-classification) for more information.

### Event-Based Extraction

Alternatively, you can receive order information automatically by subscribing to the `ORDER_EXTRACTED` event. This requires two steps:

1. Enable order extraction in your SDK options:

```javascript theme={null}
import { initializeWebExtSdk } from "@sleek/web-ext-sdk";

initializeWebExtSdk(process.env.YOUR_SLEEK_CLIENT_API_KEY_HERE, {
  featureControls: {
    emitOrders: true,
  },
});
```

2. Register an event listener to receive order information:

```javascript theme={null}
import { getWebExtSdk } from "@sleek/web-ext-sdk";

getWebExtSdk().registerEventListener((event, tabDetails) => {
  if (event.type === "ORDER_EXTRACTED") {
    const order = event.data.order;
    const classification = event.data.pageClassification;
    // Handle the order information
  }
});
```

## Order data structure

The `Order` object returned by the web extension SDK contains comprehensive information about the order details:

```typescript theme={null}
type Order = {
    orderDate: string | null;
    orderNumber: string | null;
    orderTotal: string | null;
    orderSubtotal: string | null;
    orderTax: string | null;
    orderShipping: string | null;
    products: Product[] | null;
};
```

**What's next:**

Now that you have enabled order extraction in your extension, you can check
out the TypeDoc for specific event types and methods on the web extension SDK.

<Card title="View TypeDoc" icon="terminal" href="/web-ext-sdk-reference/type-doc">
  Browse the reference TypeDoc for the web extension SDK.
</Card>
