trakily.
All guides

Track revenue by channel with Stripe in 5 minutes

Connect Stripe with a restricted key, pass the visitor id into Checkout, and see which channels, referrers and campaigns bring paying customers.

3 min read
RevenueStripeGetting started

Most analytics stop at the signup. This guide gets you from “we had 3,000 visitors” to “X brought four customers and Google brought one” in three steps: install the script, connect Stripe, and pass one id into Checkout. Steps 1 and 2 take a couple of minutes; step 3 is a few lines of server code and makes attribution reliable.

1. Install the script

If Trakily is already on your site, skip ahead. Otherwise paste your snippet from Settings → Tracking into the <head> of every page:

<script
  defer
  data-website-id="pls_…"
  data-domain="example.com"
  src="https://trakily.com/js/script.js"
></script>

Framework-specific steps are in the install docs.

2. Connect Stripe with a restricted key

  1. 1

    In Stripe, go to Developers → API keys → Create restricted key.

  2. 2

    Give it Read access to Checkout Sessions, Invoices, Subscriptions and Charges. Optionally give Write on Webhook Endpoints so Trakily can register its webhook for you.

  3. 3

    In Trakily, open Settings → Revenue, click Connect next to Stripe, paste the key (rk_live_…) and click Connect Stripe.

What happens next

Trakily imports your whole Stripe history in the background, then keeps it current with the webhook and a sync every 15 minutes. Your past payments show up as revenue right away. Payments made before Trakily was installed can't be linked to a visit (there was no visit data), so they count toward revenue and SaaS metrics but appear as unattributed in breakdowns.

3. Pass the visitor id into Checkout

The script stores a visitor id in a first-party cookie on your domain. Read it on your server and attach it to the Checkout Session. Stripe stores it with the payment and Trakily reads it back, so the payment is linked to the right visitor even if the buyer never returns to your site after paying.

app/api/checkout/route.ts (Next.js)
// Read Trakily's ids on your server (Next.js example)
import { cookies } from "next/headers";
const jar = await cookies();
const visitorId = decodeURIComponent(jar.get("_trakily_vid")?.value ?? "").split("|")[0];
const sessionId = jar.get("_trakily_sid")?.value ?? "";

const session = await stripe.checkout.sessions.create({
  mode: "subscription",
  line_items: [{ price: "price_…", quantity: 1 }],
  success_url: "https://example.com/thanks?session_id={CHECKOUT_SESSION_ID}",
  cancel_url: "https://example.com/pricing",
  client_reference_id: visitorId,
  metadata: { trakily_visitor_id: visitorId, trakily_session_id: sessionId },
});

The session_id in the success URL is a second, independent link: when the buyer lands on your thank-you page, the script reports the checkout id. Either is enough on its own; together they cover each other.

Not on Next.js?

Any backend can read cookies. The visitor id is the part of _trakily_vid before the first |; the session id is the whole _trakily_sid value.

4. Read revenue by channel

Open the dashboard. In the Sources card:

  • Channel groups everything into Direct, Organic Search, Social, Referral, AI / LLM, Email and Paid.
  • Referrer shows the individual sites (x.com, news.ycombinator.com, chatgpt.com…).
  • Campaign shows your utm_campaign values.

Click the Revenue legend to sort by revenue, and hover a row for conversion rate and revenue per visitor. Clicking a row filters the whole dashboard to that source.

Illustrative example

A referrer with few visitors but high revenue per visitor is often worth more attention than the one with the most traffic. Compare rows on revenue per visitor, not just on visitors.

Subscriptions and renewals

Renewals inherit the visitor of the subscription's first payment, and refunds inherit the payment they refund. For channel-level MRR, churn and LTV based on each customer's first visit, open the Channels tab of the Revenue metrics card (see SaaS metrics).

Try it on your site

Trakily shows which channels bring paying customers, not just visitors. Start a 14-day free trial; no card needed.