Tracking Script Reference
Install snippet
<script>
(function (w, r) {
w._abq = w._abq || [];
w[r] =
w[r] ||
function () {
(w[r].q = w[r].q || []).push(arguments);
};
})(window, "affiliatebase");
</script>
<script
async
src="https://cdn.jsdelivr.net/npm/@relay-capital/affiliatebase-tracking@1.0.9/dist/track.min.js"
data-account-id="YOUR_ACCOUNT_ID"
></script>
Script attributes
| Attribute | Required | Notes |
|---|---|---|
data-account-id | Yes | Account id (data-account alias also supported) |
data-api-url | No | Override API base URL (useful for local dev) |
data-debug | No | true enables client logs |
data-affiliatebase-params | No | Comma-separated custom attribution params |
data-params | No | Alias for data-affiliatebase-params |
data-domains | No | Comma-separated domains for cross-domain referral tagging |
data-request-timeout-ms | No | Request timeout (default 8000) |
data-respect-dnt | No | true skips tracking requests when DNT is enabled |
URL parameter behavior
Priority:
?referral=<REFERRAL_ID>(preloads existing referral id)?via=<TOKEN>(canonical token parameter)- Custom params from
data-affiliatebase-params(for example?partner=<TOKEN>)
Runtime methods
affiliatebase("convert", { email: "customer@example.com" });
affiliatebase("identify", { email: "customer@example.com" }); // alias
affiliatebase("source", "affiliate_token");
affiliatebase("track", "affiliate_token"); // alias
affiliatebase("ready", () => console.log("loaded"));
affiliatebase("debug", true);
affiliatebase("set_debug", true); // alias
affiliatebase("reset");
affiliatebase("clear"); // alias
affiliatebase("referral"); // returns referral id
affiliatebase("tracked"); // returns whether attribution tracking completed
affiliatebase("state"); // returns full attribution state
Global state
window.AffiliateBase.referral;
window.AffiliateBase.affiliate;
window.AffiliateBase.campaign;
window.AffiliateBase.coupon;
window.AffiliateBase.tracked;
window.AffiliateBase.version;
window.affiliatebase_referral; // legacy alias getter
Use window.AffiliateBase.referral or affiliatebase("state") for new integrations. The legacy alias remains available for older snippets, but new Stripe Checkout code should submit the generated window.AffiliateBase.referral value to your server.
Automatic integrations
Forms
Add data-affiliatebase to a form to auto-inject a hidden referral input when attribution exists. If the active referral includes an AffiliateBase coupon, the script also injects a hidden coupon input.
<form data-affiliatebase action="/signup" method="POST">
...
</form>
Optional custom hidden field name:
<form data-affiliatebase data-affiliatebase-param-name="referral_id">
...
</form>
Stripe Buy Buttons and Pricing Tables
The script sets client-reference-id on standard Stripe Buy Button and Pricing Table elements after a referred visitor is present.
<stripe-buy-button buy-button-id="buy_btn_xxx" publishable-key="pk_live_xxx"></stripe-buy-button>
<stripe-pricing-table pricing-table-id="prctbl_xxx" publishable-key="pk_live_xxx"></stripe-pricing-table>
Stripe Payment Links
For standard https://buy.stripe.com/... and https://link.payment/... links, the script appends client_reference_id=<generated_referral_id> after a referred visitor is present. For custom Stripe-hosted or redirected Payment Link URLs, add data-affiliatebase to the anchor as an explicit opt-in where AffiliateBase owns client_reference_id.
<a href="https://buy.stripe.com/...">Buy</a>
<a data-affiliatebase href="https://link.payment/...">Buy</a>
Cross-domain tagging
With data-domains="example.com,checkout.example.com", matching external links are tagged with referral=<referral_id>.
Browser events
AffiliateBase.initializedAffiliateBase.trackedAffiliateBase.reset
Example:
window.addEventListener("AffiliateBase.tracked", (event) => {
console.log(event.detail.referral);
});
Local development
Point the script at your local API:
<script
async
src="/track.js"
data-account-id="YOUR_ACCOUNT_ID"
data-api-url="http://localhost:3000"
data-debug="true"
></script>