Stripe Payment Links
The simplest Selgeo integration -- no backend code required. The tracking snippet automatically rewrites Stripe Payment Links on your page to include the click_id, and Selgeo reads it from the Stripe webhook when the customer pays.
API Version: v1
Prerequisites
- The Selgeo snippet is installed on your website (Snippet Setup)
- You use Stripe Payment Links (
https://buy.stripe.com/...URLs) on your site - Your Stripe account is connected to Selgeo in the dashboard (Settings > Stripe)
How it works
┌──────────────────────────────────────────────────────────────────────┐
│ 1. Visitor clicks partner link: │
│ https://your-site.com/pricing?ref=abc123 │
│ │
│ 2. Snippet registers click, stores click_id in sessionStorage │
│ │
│ 3. Snippet detects Stripe Payment Link on page: │
│ <a href="https://buy.stripe.com/test_xyz">Buy Now</a> │
│ │
│ 4. Snippet rewrites the link: │
│ <a href="https://buy.stripe.com/test_xyz?client_reference_id= │
│ CLICK_ID">Buy Now</a> │
│ │
│ 5. Customer clicks link, pays on Stripe │
│ │
│ 6. Stripe sends webhook with client_reference_id → Selgeo matches │
│ it to the click and attributes the conversion to the partner │
└──────────────────────────────────────────────────────────────────────┘
The entire flow is automatic. You only need to:
- Install the snippet.
- Put Stripe Payment Links on your page.
- Connect Stripe to Selgeo.
Setup
Step 1: Install the snippet
If you haven't already, add the tracking snippet to your site:
<script
async
src="https://cdn.selgeo.com/v1/selgeo.js"
data-merchant="pk_test_YOUR_KEY"
></script>
See Snippet Setup for full details.
Step 2: Add Stripe Payment Links to your page
Use Stripe Payment Links as you normally would. For example:
<a href="https://buy.stripe.com/test_abc123">Subscribe to Pro Plan</a>
<a href="https://buy.stripe.com/test_def456">Subscribe to Enterprise Plan</a>
The snippet detects any <a> tag whose href starts with https://buy.stripe.com and rewrites it when a click_id is stored.
Step 3: Connect Stripe
In the Selgeo dashboard, go to Settings > Stripe and connect your Stripe account. This allows Selgeo to receive Stripe webhooks and match client_reference_id to partner clicks.
What the snippet rewrites
The snippet adds the client_reference_id query parameter to Stripe Payment Link URLs:
Before:
https://buy.stripe.com/test_abc123
After (when a click_id is stored):
https://buy.stripe.com/test_abc123?client_reference_id=f47ac10b-58cc-4372-a567-0e02b2c3d479
If no referral click was recorded in the current session (no click_id in sessionStorage), the links are left unchanged. Non-referred customers see the original URL.
Dynamic links
The snippet uses a MutationObserver to watch for new Payment Links added to the page after initial load. This handles:
- Single-page applications -- links rendered after route changes
- Lazy-loaded content -- links that appear after scroll or user interaction
- A/B testing tools -- links injected by client-side experiments
New links are rewritten automatically as they appear in the DOM. No additional code is needed.
Merchant override protection
If you set client_reference_id on a Payment Link yourself (e.g., to pass your own customer ID), the snippet will not overwrite your value:
<!-- Your custom client_reference_id is preserved -->
<a href="https://buy.stripe.com/test_abc123?client_reference_id=my_customer_123">
Subscribe
</a>
If you need to pass both your own reference and the Selgeo click_id, consider using the Stripe Metadata approach instead, where you have full control over what data is attached to the Stripe object.
Testing
- Create a tracking link in the Selgeo dashboard.
- Visit your site using the tracking link:
https://your-site.com/?ref=YOUR_TEST_REF - Inspect the Payment Link -- right-click the link and select "Inspect" or "Copy Link Address". Verify that
client_reference_idhas been appended. - Click the Payment Link and complete the purchase using Stripe test card
4242 4242 4242 4242. - Check the dashboard -- the conversion should appear in Analytics, attributed to the partner.
Debug mode
Add data-debug to the snippet tag to see rewrite activity in the console:
[selgeo] Stripe payment link rewritten https://buy.stripe.com/test_abc123?client_reference_id=f47ac10b-...
Limitations
- Only
buy.stripe.comlinks are detected. If you proxy Stripe Payment Links through your own domain, the snippet cannot detect them. Use Stripe Checkout or Stripe Metadata instead. - The visitor must arrive via a tracking link first. If there is no
click_idinsessionStorage, no rewrite happens. - Tab-scoped session. The snippet stores the
click_idinsessionStorage, which is tab-scoped. Once Payment Links on the current page are rewritten, theclient_reference_idis embedded in the URL — opening a rewritten link in a new tab works fine. However, if the visitor opens your site itself in a new tab (e.g., from a bookmark), the snippet will not have aclick_idto rewrite links on that page.
Next steps
- Stripe Checkout -- if you create Checkout Sessions server-side
- Stripe Metadata -- use Checkout Session metadata instead of
client_reference_id - Conversion API -- for non-Stripe conversions