Skip to content

Affiliate & Discounts

All method calls must be inside the async IIFE shown in the Getting Started guide for sub-pages.

Check Affiliate Status

Triggered by ?ref= in the URL. Returns true if the visitor arrived via an affiliate link (current session or within cookie window).

https://example.com/product/t-shirt?ref=HEWZRCKM
javascript
if (sdk.hasAffiliate()) {
  const code = sdk.getAffiliateCode(); // → "HEWZRCKM"
  console.log("Referred by:", code);
}

Get Discount

Triggered by ?discount= in the URL. Fetches discount details from the backend. Safe to call on any page — reads from cookie if URL param is no longer present.

https://example.com/product/t-shirt?ref=HEWZRCKM&discount=SUMMER20
javascript
if (sdk.hasAffiliate()) {
  const discount = await sdk.getDiscount();
  if (discount) {
    console.log("Code:", discount.code); // "SUMMER20"
    console.log("Type:", discount.type); // "percentage" or "flat"
    console.log("Value:", discount.value); // 20
    console.log("Min order:", discount.min_order); // 50 (minimum cart total)
    console.log("Description:", discount.description); // "Summer Sale 20% off"
  }
}

Validate Discount

No URL params — call at checkout with the code and cart total. Validates server-side.

javascript
const result = await sdk.validateDiscount("SUMMER20", cartTotal);
if (result.isValid) {
  console.log("Discount amount:", result.discountAmount); // e.g. 25.00
} else {
  console.warn("Invalid discount code or minimum order not met");
}

Released under the MIT License.