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

# Coupon auto-apply

> Specific integration instructions to enable coupon auto-apply.

Sleek's SDK automatically inputs coupon codes into checkout and cart pages.
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>

## Check coupon page support

Use the `checkCouponPageSupport()` method to manually check whether the current page supports coupon auto-apply.
This method can only be called after the SDK's automatic page load check has completed, and can be called a maximum of 3 times per page load.

It returns a `CouponPageSupportResult` with:

* `supported` - whether the current page supports coupon entry.
* `autoApplyAvailable` - whether automatic coupon application is available on this page.

<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");

    // Must be called after the SDK's page load check has completed.
    const result = await sleek.getSdk().checkCouponPageSupport();
    console.log(result.supported); // true or false
    console.log(result.autoApplyAvailable); // true or false
  </script>
  ```

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

  initializeSdk("YOUR_PUBLIC_API_KEY_HERE");

  // Must be called after the SDK's page load check has completed.
  const result = await getSdk().checkCouponPageSupport();
  console.log(result.supported); // true or false
  console.log(result.autoApplyAvailable); // true or false
  ```
</CodeGroup>

## Start coupon auto-apply

Use the `startCouponAutoApply(codes: string[])` method provided by the SDK to start the coupon application on a page.

<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", {}, [
      (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.COUPON_SESSION_STARTED:
            console.log("Coupon auto-apply started");
            break;
          case SdkEventType.COUPON_SESSION_RESUMED:
            console.log("Coupon auto-apply resumed");
            break;
          case SdkEventType.COUPON_SESSION_UPDATED:
            console.log("Coupon auto-apply updated");
            break;
          case SdkEventType.COUPON_SESSION_COMPLETED:
            console.log("Coupon auto-apply completed");
            break;
          case SdkEventType.USER_GENERATED_CODE:
            console.log("User entered code:", event.data.code);
            break;
        }
      }
    ]);

    sleek.getSdk().startCouponAutoApply(["SAVE10"]);
  </script>
  ```

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

  initializeSdk("YOUR_PUBLIC_API_KEY_HERE", {}, [
    (event) => {
      switch (event.type) {
        case SdkEventType.COUPON_SESSION_STARTED:
          console.log("Coupon auto-apply started");
          break;
        case SdkEventType.COUPON_SESSION_RESUMED:
          console.log("Coupon auto-apply resumed");
          break;
        case SdkEventType.COUPON_SESSION_UPDATED:
          console.log("Coupon auto-apply updated");
          break;
        case SdkEventType.COUPON_SESSION_COMPLETED:
          console.log("Coupon auto-apply completed");
          break;
        case SdkEventType.USER_GENERATED_CODE:
          console.log("User entered code:", event.data.code);
          break;
      }
    }
  ]);

  getSdk().startCouponAutoApply(["SAVE10"]);
  ```
</CodeGroup>

Sleek’s SDK automatically manages the entire coupon auto-apply (CAA) process, including restarting after page reloads,
identifying the best coupon for the cart, and more. Throughout the session, the SDK emits structured events that reflect
the status and outcome of CAA. By subscribing to these events, you can build dynamic user experiences that inform users
about the current progress, coupon testing states, and any savings applied.

**What's next:**

Now that you have enabled coupon auto-apply, 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>
