Stripe Checkout integration
Sergiu avatar
Written by Sergiu
Updated over a week ago

FirstPromoter allows you to track leads and sales directly through the Stripe Checkout system. You can do this by passing the visitor tracking id in the checkout object that you send to Stripe.

You can find the visitor tracking id ( tid ) inside the "_fprom_trackโ€ cookie that is set on your website when you access it with a valid referral link or by accessing $FPROM.data.tid object which is initialized when our visitor tracking script is loaded.


There are 2 ways in which you can integrate the tracking, depending what type of checkout you're using.

Tracking through the Stripe Checkout in Javascript

This option is for cases where you make the Checkout through Javascript client side.
โ€‹
Make sure you have our visitor tracking script inserted on the page where you're retrieving the checkout session id.

Append the clientReferenceId to the redirectToCheckout function params and pass the tid variable taken from window.$FPROM.data.tid.

function getFPTid(){
return window.$FPROM && window.$FPROM.data.tid
}
...
stripe.redirectToCheckout({
...
successUrl: 'https://www.example.com/checkout?result=success',
cancelUrl: 'https://www.example.com/checkout/?result=cancel',
clientReferenceId: getFPTid()
});
});

Tracking through the Stripe API on the backend

If you're using Stripe API to create the checkout session you can pass the _fprom_track cookie value to the session using client_reference_id parameter.

For NodeJS, it will look something like this:

...
var cookieParser = require('cookie-parser');
...
app.use(cookieParser());
...
app.post('/create-checkout-session', async (req, res) => {
const tid = req.cookies['_fprom_track'];

const session = await stripe.checkout.sessions.create({
...
success_url: 'https://example.com/success',
cancel_url: 'https://example.com/cancel',
client_reference_id: tid
})

res.json({ id: session.id });
});

Testing

To test this integration:

  • make sure you have visitor tracking scripts inserted on your website

  • make sure you have Stripe connected. You can go to Settings (top-right buton) > Integrations > View integrations > Stripe to check the connections. You can also use Stripe Test mode by disconnecting first the existing stripe connection, enabling test mode switch and connecting again.

  • create a promoter and grab its referral link

  • open the referral link on an incognito window and do a test sale

  • check the leads or customers sections to see if the customer got tracked

Did this answer your question?