Stripe Payment Links
Track revenue from Stripe Payment Links.
Stripe Payment Links
Stripe Payment Links let you accept payments without writing server-side code. However, Payment Links have significant limitations for revenue attribution.
Limited attribution support. Stripe Payment Links do not support custom
metadata, and the EngageTrack backend currently only reads
metadata.engagetrack_visitor_id and metadata.engagetrack_session_id from
checkout sessions for attribution — it does not read the
client_reference_id field. This means revenue from Payment Links will
appear in your dashboard but will not be attributed to specific marketing
sources. For full attribution support, use the Stripe Checkout
API instead.
How It Works
- You create a Payment Link in the Stripe dashboard
- After payment, Stripe sends a
checkout.session.completedwebhook to EngageTrack - EngageTrack records the revenue, but since Payment Links cannot carry EngageTrack metadata, the payment will not be attributed to a specific traffic source
Step 1: Create the Payment Link
Create a Payment Link in the Stripe Dashboard → Payment Links. Copy the URL — it will look like:
https://buy.stripe.com/aBC123dEfGhI
Step 2: Add the JavaScript Snippet
Add this script to the page where the Payment Link appears. It dynamically appends the EngageTrack IDs to all Stripe Payment Links on the page:
<a href="https://buy.stripe.com/aBC123dEfGhI" class="stripe-payment-link">
Buy Now
</a>
<script>
document.addEventListener("DOMContentLoaded", function () {
const visitorId = window.engagetrack?.getVisitorId() || "";
const sessionId = window.engagetrack?.getSessionId() || "";
document.querySelectorAll('a[href*="buy.stripe.com"]').forEach((link) => {
const url = new URL(link.href);
url.searchParams.set("client_reference_id", visitorId);
url.searchParams.set(
"prefilled_email",
url.searchParams.get("prefilled_email") || "",
);
// Store session ID in the URL for EngageTrack to read
url.searchParams.set("engagetrack_session_id", sessionId);
link.href = url.toString();
});
});
</script>Or if you prefer a single link with manual construction:
const visitorId = window.engagetrack?.getVisitorId() || "";
const sessionId = window.engagetrack?.getSessionId() || "";
const paymentLink = `https://buy.stripe.com/aBC123dEfGhI?client_reference_id=${visitorId}&engagetrack_session_id=${sessionId}`;
window.location.href = paymentLink;Although client_reference_id is passed through to the checkout session by
Stripe, EngageTrack does not currently read this field for attribution.
The snippet below is provided for reference, but it will not result in
attributed revenue. Use the Stripe Checkout
API for full attribution.
Step 3: Set Up the Webhook
Follow the same webhook setup as Stripe Checkout:
- Go to Stripe Dashboard → Developers → Webhooks
- Click Add endpoint
- Enter the webhook URL:
https://api.engagetrack.net/api/v1/webhooks/revenue/stripe/{YOUR_SITE_PUBLIC_ID}
- Select
checkout.session.completedandcharge.refundedevents - Click Add endpoint
Limitations
Payment Links have some limitations compared to the Checkout Sessions API:
| Feature | Checkout API | Payment Links |
|---|---|---|
| Custom metadata | Full support (key/value pairs) | Limited to client_reference_id |
| Subscription metadata | Supported via subscription_data | Not supported |
| Session ID tracking | Direct metadata field | URL parameter (less reliable) |
| Server-side control | Full | None |
For subscriptions, Payment Links do not carry metadata forward to future invoices. Only the initial payment will have attribution data. If you need subscription revenue tracking, use the Checkout Sessions API instead.
Verify
- Open your site and inspect a Stripe Payment Link — the URL should include
client_reference_idandengagetrack_session_idparameters - Click the link and complete a test purchase using card
4242 4242 4242 4242 - Check your EngageTrack dashboard → Revenue tab for the payment
- Verify the payment is attributed to the correct traffic source
If the payment appears but without source attribution, the visitor ID was not passed correctly. Check that:
- The EngageTrack SDK is loaded before the snippet runs
window.engagetrack.getVisitorId()returns a non-empty string- The URL parameters are present when clicking the link