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

  1. You create a Payment Link in the Stripe dashboard
  2. After payment, Stripe sends a checkout.session.completed webhook to EngageTrack
  3. EngageTrack records the revenue, but since Payment Links cannot carry EngageTrack metadata, the payment will not be attributed to a specific traffic source

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:

  1. Go to Stripe Dashboard → Developers → Webhooks
  2. Click Add endpoint
  3. Enter the webhook URL:
https://api.engagetrack.net/api/v1/webhooks/revenue/stripe/{YOUR_SITE_PUBLIC_ID}
  1. Select checkout.session.completed and charge.refunded events
  2. Click Add endpoint

Limitations

Payment Links have some limitations compared to the Checkout Sessions API:

FeatureCheckout APIPayment Links
Custom metadataFull support (key/value pairs)Limited to client_reference_id
Subscription metadataSupported via subscription_dataNot supported
Session ID trackingDirect metadata fieldURL parameter (less reliable)
Server-side controlFullNone

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

  1. Open your site and inspect a Stripe Payment Link — the URL should include client_reference_id and engagetrack_session_id parameters
  2. Click the link and complete a test purchase using card 4242 4242 4242 4242
  3. Check your EngageTrack dashboard → Revenue tab for the payment
  4. 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