Integrations

Stripe Revenue Attribution

Connect your Stripe account to attribute revenue to visitor sessions. See which pages, referrers, UTM campaigns, and devices are driving your sales.

Persist mode is required for revenue attribution. It's the only way to associate a payment with a visitor, however this requires explicit consent for EU users. Learn more.

How to connect Stripe

Here's an exact step-by-step tutorial on how to integrate Stripe.

  1. Head to API keys in Stripe
  2. Create a restricted API key
  3. Select "Providing this key for another website"
  4. Name the key whatever you like ("Visitors")
  5. Add "https://visitors.now" as the URL.
  6. Hit "Create restricted key"
  7. Copy the generated API key ("rk_live_...")
  8. Head to your project's Settings
  9. Navigate to Integrations
  10. Hit the connect button for Stripe
  11. Paste it in your API key
  12. Hit "Connect"

We'll then automatically create a webhook endpoint for your Stripe account and Visitors will begin receiving transaction events from Stripe.

Enable persist mode

Without this we can't attribute transactions to real visitors. This will enable cookie-based tracking allowing you to read the visitor cookie.

Replace YOUR_TOKEN with your project token.

index.html
<script
  src="https://cdn.visitors.now/v.js"
  data-token="YOUR_TOKEN"
  data-persist>
</script>

Stripe Checkout integration

When creating a Stripe Checkout session on your server, read the visitor cookie from the incoming request and pass it as metadata to stripe.checkout.sessions.create().

app/api/checkout/route.ts
import { cookies } from "next/headers";
import Stripe from "stripe";

const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!);

export async function POST(request: Request) {
  const visitor = (await cookies()).get("visitor")?.value;

  const session = await stripe.checkout.sessions.create({
    line_items: [{ price: "price_xxx", quantity: 1 }],
    mode: "payment",
    success_url: "https://example.com/success",
    metadata: { visitor },
  });

  return Response.json({ url: session.url });
}