Skip to content

Getting Started

Installation

Add the SDK script to your website's <head> section:

html
<script src="https://s3.us-east-2.amazonaws.com/cdn.rentmy.co/affiliate/prod/affiliate-sdk.min.js"></script>

URL Parameters

The SDK reads these parameters from the page URL automatically during init():

ParameterRequiredExampleDescription
refYes (for affiliate tracking)ref=HEWZRCKMAffiliate code — triggers click tracking
discountNodiscount=SUMMER20Discount code — stored in cookie for cart/checkout
utm_sourceNoutm_source=googleTraffic source
utm_mediumNoutm_medium=cpcTraffic medium
utm_campaignNoutm_campaign=spring-saleCampaign name
utm_contentNoutm_content=banner-adAd content
utm_termNoutm_term=running+shoesSearch term
gclidNogclid=Cj0KCQ...Google click ID
fbclidNofbclid=IwAR...Facebook click ID
msclkidNomsclkid=abc...Microsoft click ID

Example affiliate link:

https://example.com/product/t-shirt?ref=HEWZRCKM&discount=SUMMER20&utm_source=google&utm_medium=cpc&utm_campaign=spring-sale

Once a user clicks this link, ref and discount are stored in cookies (30 days). All subsequent pages — cart, checkout, confirmation — read from cookies automatically. No URL params needed on those pages.


Page Type 1 — Initialization Page

This is the main page (or layout) where the SDK is loaded and initialized. Call init() once here using an async IIFE with onReady to signal readiness to all other scripts on the site.

javascript
(async function () {
  try {
    await window.AffiliateSDK.init({
      apiKey: "as_XXXXYYYYZZZZ",
      enablePageviews: true,
      onReady: function () {
        window._affiliateSDKReady = true;
      },
    });
  } catch (err) {
    console.error("AffiliateSDK init failed", err);
  }
})();

Page Type 2 — Sub-pages (Cart, Checkout, Product, etc.)

All other pages must wait for the SDK to finish initializing before calling any methods. Use the _affiliateSDKReady signal set by onReady on the init page.

javascript
(async function () {
  const sdk = window.AffiliateSDK;
  if (!sdk) return;

  // Wait for SDK init to complete
  await new Promise(function (resolve) {
    if (window._affiliateSDKReady) return resolve();
    var interval = setInterval(function () {
      if (window._affiliateSDKReady) {
        clearInterval(interval);
        resolve();
      }
    }, 100);
  });

  // SDK is ready — call methods below
})();

Released under the MIT License.