Stripe

If you use Stripe for checkouts, standard client-side conversion tracking may not work because the final transaction occurs on Stripe's domain rather than your own. To track these conversions accurately, you can pass the Optibase User ID through to Stripe and use a Webhook to notify Optibase when a payment is successful.

How it works

  1. Capture: You retrieve the Optibase User ID from the browser.

  2. Forward: You pass this ID to Stripe as a client_reference_id.

  3. Notify: Stripe sends a webhook to your server upon successful payment.

  4. Convert: Your server sends a server-to-server request to Optibase to record the goal.

1. Forward the ID to Stripe

To link a Stripe session to an Optibase user, you must include the Optibase User ID in your Stripe Checkout link or API call.

If you are using pre-defined Stripe Payment Links, you can use a script to automatically append the ID to your buttons:

window.addEventListener('load', () => {
  const userId = window.optibaseTestedUserId;
  if (!userId) return;

  // Find all Stripe links and append the client_reference_id
  const links = document.querySelectorAll('a[href*="checkout.stripe.com"]');
  links.forEach(link => {
    const url = new URL(link.href);
    url.searchParams.set('client_reference_id', userId);
    link.href = url.toString();
  });
});

Using Stripe API (Server-side)

If you create Checkout Sessions via the Stripe API, include the ID in the client_reference_id parameter:

2. Set up the Webhook

Once a purchase is completed, Stripe sends a checkout.session.completed event. You need a simple webhook listener to capture this and notify Optibase.

Endpoint: https://app.optibase.io/api/script/conversionEvent

Method: POST

Example Payload

Your server should send the following JSON to Optibase:

3. Create the Conversion in Optibase

For the conversion to be recognized, create a matching conversion event in your Optibase dashboard:

  1. Go to your Project Settings > Conversions.

  2. Create a new conversion.

  3. Select Programmatic.

  4. Enter the Event Name (e.g., Stripe Purchase). This must exactly match the eventName sent by your webhook.

Recommendations

  • Global Placement: Place your JavaScript in the global header or site-wide settings to ensure the Stripe links are updated regardless of which page the user is on.

Last updated