Installing the SDK JS File
Step 1 — Add the Script Tag
Add the HeldSway Affiliate SDK script to the
section of main page on your website<script src="https://s3.us-east-2.amazonaws.com/cdn.rentmy.co/affiliate/prod/affiliate-sdk.min.js"></script>
Step 2 — Get Your API Key
- Go to your dashboard → Settings → API Keys
- Click “+ Create Key”
- Give the key a name (e.g.,
Production Integration) - Select the required scopes for your use case:
| Scope | Access |
|---|---|
sdk:init |
Initialize the SDK |
pageviews:write |
Track page views |
conversions:write |
Track conversions |
reports:read |
Read analytics data |
orders:read / orders:write |
Read/manage orders |
payouts:read / payouts:write |
Read/manage payouts |
settings:read / settings:write |
Read/manage settings |
- Click “Create Key” — copy and store your
api_keysecurely
Step 3 — Initialize the SDK
Call init() on every page. It must be called first, before any other SDK methods.
<script>
(async function () {
// Wait for SDK to be available
await new Promise(function (resolve) {
if (window.AffiliateSDK) return resolve();
var interval = setInterval(function () {
if (window.AffiliateSDK) {
clearInterval(interval);
resolve();
}
}, 50);
});
// Initialize with your API key
await window.AffiliateSDK.init({
apiKey: "as_XXXXYYYYZZZZ", // Replace with your actual API key
enablePageviews: true, // Set to true to auto-track page views
});
})();
</script>
⚠️ Security Note: Your
apiKey(prefixedas_) is safe to use client-side. Never expose yourapi_secretin browser code.
SDK Method Reference
| Method | Description |
|---|---|
init() |
Initialize the SDK with your API key. Must be called first. |
identify() |
Links a customer’s identity (email, userId) to the affiliate session |
trackAddToCart() |
Tracks when a user adds an item to the cart |
trackRemoveFromCart() |
Tracks when a user removes an item from the cart |
trackCheckout() |
Tracks when a user reaches the checkout page |
trackProductDetailsViewed() |
Tracks when a user views a product detail page |
trackOrder() |
Tracks a completed order. Duplicate orders are automatically prevented |
trackThankYouPageViewed() |
Tracks the thank-you / order confirmation page view |
destroy() |
Clears session, cookies, event queue, and listeners |