Stripe API Integration
Pass referral IDs through the Stripe API for affiliate tracking
Stripe API Integration
For custom checkout flows, you can pass the referral ID directly through the Stripe API.
Implementation Steps
1. Add the PromoteKit Script
Add the PromoteKit script to your website. It should be on both your landing page (where referrals arrive) and your checkout page.
The script works across subdomains, so you can use it on both yoursite.com and app.yoursite.com.
2. Retrieve the Referral ID
After the script loads, you can access the referral ID:
JavaScript/TypeScript: Use window.promotekit_referral
PHP: Use $_COOKIE['promotekit_referral']
3. Pass to Stripe
Include the referral ID in the metadata when creating a checkout session or subscription:
const session = await stripe.checkout.sessions.create({
success_url: 'https://example.com/success',
cancel_url: 'https://example.com/cancel',
metadata: {
promotekit_referral: req.body.referral,
},
line_items: [
{ price: 'price_1OBQlV2eZvKYlo2CDL02DbMx', quantity: 1 },
],
mode: 'subscription',
});
Manual Signup Tracking
For tracking users who sign up before they pay, use the refer function:
window.promotekit.refer(email, stripe_customer_id)
| Parameter | Required | Description |
|---|---|---|
email | Yes | Customer's email address |
stripe_customer_id | No | Stripe customer ID (if available) |
This allows you to attribute the referral even before payment occurs.