Skip to main content
For plain React apps, the main goal is simple: load the AgentRef script once at the app shell and keep it available while the SPA navigates.

Before you start

  • Set the program website in AgentRef to the same root domain your React app uses.
  • Copy the exact AgentRef script snippet from Settings -> Integration.
  • If checkout happens on a sibling subdomain, install AgentRef there too.
For Vite, CRA, and most React SPAs, the cleanest setup is to add the script directly to the shared HTML shell.
<!-- public/index.html or index.html -->
<script
  defer
  src="https://www.agentref.co/api/tracking/script.js?pid=YOUR_PROGRAM_ID"
></script>
If you run React Strict Mode in development, an index.html install is usually less noisy than effect-based injection because it avoids duplicate development mounts.

Checkout compatibility in React

Checkout patternRecommendation
Stripe Payment Links, Buy Buttons, or Pricing Tables rendered by the SPASupported directly. AgentRef already observes late-rendered Stripe elements.
React app calls your own backend to create a Stripe Checkout SessionSupported, but you must forward window.AgentRef.getCheckoutMetadata() to your server. Use the Stripe guide.
Checkout jumps to a different root domainFirst-party cookies do not cross root domains automatically.

SPA-specific notes

  • AgentRef does not need to be reloaded on every route change.
  • Hosted Stripe surfaces that render after navigation are still covered because the script watches the DOM.
  • If you gate cookies behind consent, call window.AgentRef.setConsent('granted') after the visitor accepts.

Verify the installation

  1. Land on the app through a real affiliate link.
  2. Confirm agentref_cid and agentref_pid in DevTools.
  3. Add ?agentref_debug=1 and inspect the console.
  4. Complete one supported checkout flow and confirm AgentRef records the conversion.

Troubleshooting

  • The script appears multiple times in the DOM: move the install into index.html or add a duplicate guard.
  • Referral cookies are missing after a route transition: the problem is usually that the script never loaded on first render.
  • Payment Links work but custom checkout does not: that means your React frontend is fine and your Stripe backend still needs the metadata bridge.

Stripe Checkout

Bridge browser attribution into Stripe metadata.

Debug Mode

Inspect runtime state and hosted Stripe instrumentation.

Consent and GDPR

Coordinate AgentRef with your consent banner.