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

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
Order extraction is only supported on cart, checkout, and checkoutComplete.

Manual Extraction

To extract order information from an cart, checkout or order confirmation page, you can use the extractOrder method:
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 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:
import { initializeWebExtSdk } from "@sleek/web-ext-sdk";

initializeWebExtSdk(process.env.YOUR_SLEEK_CLIENT_API_KEY_HERE, {
  featureControls: {
    emitOrders: true,
  },
});
  1. Register an event listener to receive order information:
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:
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.

View TypeDoc

Browse the reference TypeDoc for the web extension SDK.