Install Tracking Script
Use the script from setup step 4.
<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>
Replace YOUR_ACCOUNT_ID with your account ID.
Add Stripe Checkout Attribution
Most Stripe-hosted setups only need the script on the same published page as the Stripe checkout link or element.
Payment Link
Use this path if your site links to a Stripe Payment Link. Existing https://buy.stripe.com/... links can stay unchanged:
<a href="https://buy.stripe.com/your_payment_link">Buy now</a>
Buy Button or Pricing Table
Keep the Stripe element on the same page as the AffiliateBase script:
<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>
Custom or Backend-created Checkout Sessions
If your server creates Checkout Sessions, submit the referral ID to your server first:
<form action="/checkout" method="post" data-affiliatebase data-affiliatebase-param-name="referral_id">
<button type="submit">Start checkout</button>
</form>
Then set client_reference_id server-side when creating the Stripe Checkout Session. Mirror the same generated referral ID into affiliatebase_referral_id metadata where your Checkout mode supports it:
referral_id = params[:referral_id].presence
referral_metadata = { affiliatebase_referral_id: referral_id }.compact
checkout_params = {
success_url: "https://example.com/success",
cancel_url: "https://example.com/cancel",
line_items: [{ price: "price_xxx", quantity: 1 }],
mode: "subscription"
}
checkout_params[:client_reference_id] = referral_id if referral_id.present?
checkout_params[:metadata] = referral_metadata if referral_metadata.present?
checkout_params[:payment_intent_data] = { metadata: referral_metadata } if referral_metadata.present?
checkout_params[:subscription_data] = { metadata: referral_metadata } if referral_metadata.present?
Do not use the public ?via token as client_reference_id. Stripe should receive the generated referral ID created by the tracking script.
Canonical Attribution Parameter
The tracking flow is built around ?via=TOKEN.
Example:
https://yoursite.com/pricing?via=abc123
Key Runtime Values
window.AffiliateBase.referralwindow.affiliatebase_referral
Browser state is only available in the visitor’s browser. Server-side Stripe code cannot read window.AffiliateBase unless the page submits the referral value first.
Conversion Tracking
When conversion is complete:
affiliatebase('convert', { email: 'customer@example.com' });