BetterRewardsDocs
Open app
Browse guides

Snippet reference

The snippet's attributes, cookie and JavaScript API, for showing who referred a visitor or filling in a discount code.

2 min read · For companies

Every option
<script
  async
  src="https://rewards.acme.com/v1/br.js"
  data-params="ref,aff"
  data-outbound="acme.app"
  data-domain="acme.com"
></script>

Attributes

AttributeDefaultWhat it does
srcrequiredYour instance's /v1/br.js. Clicks are reported to the same address.
data-paramsvia onlyExtra query parameters to read a partner code from, for links shared before betterrewards (up to 5, for example ref). Set them in Integrations → Tracking & links.
data-outboundnoneYour other domains. Links to them get ?br_click=<id>, so the click follows the visitor. Set them in Integrations → Tracking & links → Your other domains.
data-domainthe registrable domainThe cookie's domain. Rarely needed: by default the snippet uses the widest domain the browser accepts, such as acme.com for www.acme.com.
data-apithe origin of srcWhere to report clicks, if the script is served from elsewhere.
NameWhat it is
br_click (cookie)The click id, clk_ followed by 32 hex characters. First-party, SameSite=Lax, Secure on https. Lasts the program's attribution window.
?via=<code>A partner link. The snippet reports it and stores the click id it gets back.
?br_click=<id>A click carried from a short link or from your other domain. Stored as is, without a request.

With a first-click program, a stored click is kept when the visitor later follows another partner's link. Safari keeps script-set cookies for 7 days, which is why the click id belongs on the Stripe customer at signup.

JavaScript API

window.BetterRewards
// Resolves once the current address has been handled: the click id, or null.
const id = await window.BetterRewards.ready;

// The stored click id, synchronously.
window.BetterRewards.getClickId(); // "clk_…" | null

// Who referred the visitor, and the program's discount for them.
const referral = await window.BetterRewards.getReferral();
// { partner: { name: "Ada" },
//   discount: { percentOff: 20, duration: "repeating", months: 3 } | null,
//   promotionCode: { code: "ADA20", id: "promo_…" } | null } | null

// Just the partner's Stripe promotion code, to apply at checkout.
const promo = await window.BetterRewards.getPromotionCode(); // { code, id } | null

Show who sent the visitor

On your pricing page
const referral = await window.BetterRewards?.getReferral();
if (referral?.discount) {
  banner.textContent = `${referral.partner.name} gets you ${referral.discount.percentOff}% off.`;
}

Apply the partner's discount code

Pass promo.id to your server and set discounts: [{ promotion_code: id }] on the Checkout Session, or fill promo.code into your own coupon field.

The API never throws and never blocks the page: requests time out after 2 seconds, and every method resolves to null when there is no click.