Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

Stripe API

For custom checkouts that call the Stripe API: pass the visitor's Humblytics view ID into Stripe metadata.

Connect Stripe first. This guide is for developers who control the code that creates Stripe payments.

How it works

The tracking script gives every visit an ID. Send that ID to Stripe as humblytics_view_id metadata, and Humblytics matches the payment to that visit. You don't need any webhooks.

Step 1: Read the view ID in the browser

const viewId = window.Humblytics.viewId;

await fetch("/api/create-checkout", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ priceId, humblytics_view_id: viewId }),
});

Step 2: Add it to Stripe metadata on your server

Add humblytics_view_id to whichever Stripe object your flow creates. Humblytics checks Checkout Sessions, Payment Intents, Invoices, Subscriptions, and Customers, and uses the first one it finds.

// Stripe Checkout
const session = await stripe.checkout.sessions.create({
  line_items,
  mode: "payment",
  metadata: { humblytics_view_id },
});

// One-time payment
const paymentIntent = await stripe.paymentIntents.create({
  amount,
  currency,
  metadata: { humblytics_view_id },
});

// Subscription
const subscription = await stripe.subscriptions.create({
  customer: customerId,
  items: [{ price: priceId }],
  metadata: { humblytics_view_id },
});

Subscriptions and repeat buyers: put the ID on the Subscription or Customer. Humblytics then applies it to future invoices and renewals from that customer too.

Troubleshooting

  • Revenue, but no attribution: in Stripe, open the payment and check its metadata for humblytics_view_id. If viewId was undefined, the tracking script hadn't loaded on the page yet.

  • Still stuck? Email support@humblytics.com.

Last updated