Use the startCouponAutoApply(codes: string[]) method provided by the SDK to start the coupon application on a page.
Copy
<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>
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.