Stripe + Web Tracking
Last updated: 2026-05-13
Get attribution tracking live in 5 minutes. DATALYR helps SaaS companies track users from ad click to signup to paid subscription, so you can measure real ROAS and feed accurate conversion data back to your ad platforms.
Quick start guides: JavaScript / HTML · React / Next.js
Step 1: Create your DATALYR account
- Sign up at datalyr.com/signup
- Go to Settings → API — copy your API key (starts with
dk_)
Step 2: Install the Web SDK
The Web SDK tracks visitors across your marketing site, signup flow, and app so we can connect the full journey from ad click to paid customer.
- HTML: follow the setup guide
- React / Next.js: follow the setup guide
Install the SDK on every page — your marketing site, signup page, onboarding flow, and logged-in app. This is what lets DATALYR stitch the full user journey together.
Step 3: Identify your users
Call identify()with the user’s email after signup or login. This is critical for SaaS — it’s how DATALYR connects an anonymous visitor who clicked your ad to the paying customer in Stripe.
- Call
identify()on signup, login, and any session restore - Pass the user’s email at minimum
- If you have a user ID, pass that too
Step 4: Connect Stripe
Connect Stripe to DATALYR so we can track revenue events — new subscriptions, renewals, upgrades, downgrades, cancellations, and refunds. Just connect your Stripe account through our Stripe Connect integration — no manual webhooks needed.
- Go to Sources → Stripe → Connect
- Authorize DATALYR with your Stripe account
- That’s it — revenue data starts flowing automatically
What DATALYR tracks from Stripe:
- New subscriptions and one-time purchases
- Renewals and billing cycle events
- Upgrades and downgrades
- Cancellations and churn
- Refunds (negative revenue)
- Failed payments and dunning events
Step 5: Pass the visitor ID to Stripe Checkout
Connecting Stripe is enough to get revenue data flowing. To get the highest-quality attribution (90%+ match rate vs 70-85% with email alone), pass the DATALYR visitor ID through Stripe so the webhook can link the purchase directly back to the browser session — no email lookup required.
Read the visitor ID from the SDK client-side, then pass it into your Stripe call server-side. DATALYR’s webhook accepts it via either Stripe’s canonical client_reference_id slot or a datalyr_id metadata key.
// client-side, before kicking off the Stripe call
const visitorId = datalyr.getVisitorId();Stripe Checkout (hosted): pass via client_reference_id— Stripe’s canonical attribution slot.
stripe.checkout.sessions.create({
client_reference_id: visitorId,
line_items: [...]
});Stripe Elements / PaymentIntent: pass via metadata.
stripe.paymentIntents.create({
amount,
currency,
metadata: { datalyr_id: visitorId }
});Subscriptions: set metadata: { datalyr_id: visitorId } on the Subscription — it auto-propagates to every future invoice, so renewals stay attributed.
This turns the attribution chain from “hope the email matches” into a direct pointer. It’s a one-line change and it’s the single biggest lever on attribution quality for SaaS.
Step 6: Connect your ad platforms
Connect your ad platforms so DATALYR can match ad spend to revenue and give you accurate ROAS, and so we can send conversion events back server-side.
- Meta (Facebook / Instagram)
- Google Ads
- TikTok
- Other: reach out at hello@datalyr.com
Step 7: Set up conversion rules
Configure conversion rules to send the right events back to your ad platforms so they can optimize for your highest-value users — not just signups, but actual paying customers.
- Go to Conversions → Add Rule
- Pick your trigger event (e.g.
subscription_created,payment_succeeded), choose your ad platform, and set the conversion value - Hit Save — it’s live immediately
Step 8: Verify it's working
- Set
debug: truein the SDK — you should see events logging in your console - Create a test account and go through your signup flow
- Open Live in your dashboard — events should appear within seconds
- Make a test purchase (Stripe test mode) and confirm the revenue event shows up
Best practices
- Use the Stripe Connect integration for all revenue tracking — do not track purchases or subscription events client-side through the SDK. Revenue should come through Stripe only.
- The SDK’s job is attribution (where did this user come from?) and Stripe’s job is revenue (what did they actually pay?). DATALYR connects them automatically via visitor ID / user ID matching.
- Always call
identify()as early as possible after the user is known — this is the single most important thing for accurate attribution in SaaS. - Pass
datalyr.getVisitorId()into every Stripe Checkout / PaymentIntent / Subscription create call. This is what takes attribution from 70-85% (email-only) to 90%+ (direct ID match). One line, biggest lift in the entire guide. - Track key funnel events through the SDK: page views, signup started, signup completed, onboarding steps, feature usage. These help you understand where users drop off, not just who converts.
- Optimize your ad platforms for subscription events, not signups. Sending
subscription_createdorpayment_succeededas your primary conversion gives ad platforms much better signal than optimizing for free signups.
Why server-side revenue tracking matters
- User signs up for a free trial → SDK fires “signup” → trial never converts → you counted a “conversion” that never paid
- User enters payment info → client fires before Stripe confirms → card declines → phantom revenue
- User gets a refund → SDK already counted it → revenue is inflated
Stripe Connect fixes this:
- Stripe only sends events after the payment is confirmed
- Refunds come through as negative revenue automatically
- Trial starts vs actual conversions are distinct events
- Upgrades, downgrades, churn — all accurate and automatic