Install the Ambassly Tracking Snippet
Add this script to every public page where an affiliate referral may land. Put it in the <head> or just before </body>.
<script
src="https://ambassly.com/a.js"
data-ambassly="COMPANY_PUBLIC_ID"
async
></script>
Replace COMPANY_PUBLIC_ID with the company public ID shown in Ambassly.
What the script records
When someone lands on your site with a referral URL like this:
https://example.com/pricing?via=CREATOR123
Ambassly reads ?via=CREATOR123, stores the referral in a first-party cookie named ambassly_ref, and mirrors it in localStorage.
Ambassly also accepts ?ref=:
https://example.com/pricing?ref=CREATOR123
The stored value contains:
{
"code": "CREATOR123",
"link": "https://example.com/pricing?via=CREATOR123",
"ts": "2026-07-06T12:00:00.000Z"
}
The cookie is set for 60 days with SameSite=Lax. If a visitor clicks a different Ambassly referral link before buying, the newer click wins.
Your checkout code should read the current referral and pass the code into Stripe as client_reference_id and/or metadata.ambassly.
Read the current referral
After the script loads, it exposes:
window.Ambassly.getReferral();
Example:
<button id="buy">Buy now</button>
<script>
document.getElementById("buy").addEventListener("click", async () => {
const referral = window.Ambassly?.getReferral?.();
const response = await fetch("/create-checkout-session", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
ambassly: referral?.code ?? null
})
});
const { url } = await response.json();
window.location.href = url;
});
</script>
Safari ITP note
Ambassly uses a first-party cookie because it is the least invasive way to remember a referral on your own domain. Safari's Intelligent Tracking Prevention can cap client-set cookies to about 7 days in common referral flows.
That means a visitor who clicks an affiliate link in Safari and waits longer than Safari allows may lose client-side attribution before checkout.
The durable fix is to pass the referral code server-side as soon as you see it, then attach it to the eventual Stripe Checkout Session from your own database or session. The MVP tracking snippet still works client-side, but this Safari limit is real and should be planned for if your buyers have long consideration windows.
Test your install
- Open a private browser window.
- Visit a page on your site with a test code:
https://example.com/pricing?via=TESTCODE
- Open the browser console and run:
window.Ambassly.getReferral();
You should see an object whose code is TESTCODE.
- Confirm the first-party cookie exists:
document.cookie
.split("; ")
.find((cookie) => cookie.startsWith("ambassly_ref="));
Start a test checkout and confirm your server sends the code to Stripe as
client_reference_idand/ormetadata.ambassly.In Stripe test mode, complete the checkout and let Stripe send
checkout.session.completedto:
https://ambassly.com/api/hook/COMPANY_PUBLIC_ID
Ambassly resolves the code from client_reference_id or metadata.ambassly.