> ## 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 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 SDK. If you haven't, please refer to the [SDK integration guide](/js-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:

<CodeGroup>
  ```html IIFE (via <script>) theme={null}
  <script src="f.js"></script>
  <script src="sdk.iife.js"></script>
  <script>
    sleek.initializeSdk("YOUR_PUBLIC_API_KEY_HERE");

    const order = await sleek.getSdk().extractOrder(); // Returns Promise<ExtractOrderResult>
  </script>
  ```

  ```typescript CJS / ESM theme={null}
  import { initializeSdk, getSdk } from "@sleek/sdk";

  initializeSdk("YOUR_PUBLIC_API_KEY_HERE");

  const order = await getSdk().extractOrder(); // Returns Promise<ExtractOrderResult>
  ```
</CodeGroup>

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](/js-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 to set `emitPageClassification` to `true` in the SDK’s options during initialization.

<CodeGroup>
  ```html IIFE (via <script>) theme={null}
  <script src="f.js"></script>
  <script src="sdk.iife.js"></script>
  <script>
    sleek.initializeSdk("YOUR_PUBLIC_API_KEY_HERE", {
      featureControls: {
        emitOrders: true,
      },
    },
    [
      (event) => {
        // `event` is typed, so is the data of the event `event.data` based on the type of the event.
        switch (event.type) {
          case SdkEventType.ORDER_EXTRACTED:
            const order = event.data.order;
            const classification = event.data.pageClassification;
            break;
        }
      }
    ]);
  </script>
  ```

  ```typescript CJS / ESM theme={null}
  import { initializeSdk, getSdk } from "@sleek/sdk";

  initializeSdk("YOUR_PUBLIC_API_KEY_HERE", {
    featureControls: {
      emitOrders: true,
    },
  },
  [
    (event) => {
      switch (event.type) {
        case SdkEventType.ORDER_EXTRACTED:
          const order = event.data.order;
          const classification = event.data.pageClassification;
          break;
      }
    }
  ]);
  ```
</CodeGroup>

## Order data structure

The `Order` object returned by the 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, you can check
out the TypeDoc for specific event types and methods on the SDK.

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