> ## Documentation Index
> Fetch the complete documentation index at: https://doc.trackrev.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Set up Stripe attribution end to end

> A complete walkthrough — from your first tracking link to a Stripe sale credited to the right channel.

This guide wires the whole loop together for a Stripe-powered SaaS: tracking links, the pixel, a
read-only Stripe connection, and the one line at checkout that makes attribution exact. Budget
about 15 minutes.

<Steps>
  <Step title="Create a tracking link per channel">
    Go to **Campaigns → New campaign**, set your destination (e.g. your pricing page), and tick the
    channels you'll share it on. TrackRev mints one link per channel with UTMs baked in. Full
    details: [Create links](/link-tracking/create-links).
  </Step>

  <Step title="Install the pixel on your site and app">
    Add the snippet to the `<head>` of every page — marketing site *and* app:

    ```html theme={null}
    <script async src="https://www.trackrev.io/p.js" data-id="YOUR_WORKSPACE_ID"></script>
    ```

    Then click **Check pixel** on the Integrations tab. See
    [Install the pixel](/getting-started/install-pixel).
  </Step>

  <Step title="Identify users when you know them">
    Call `identify()` on sign-up or login so an email is tied to the visitor (this is the fallback
    that catches sales without a checkout reference):

    ```js theme={null}
    window.trk?.identify("customer@example.com");
    ```
  </Step>

  <Step title="Connect Stripe with a read-only key">
    On **Integrations → Connect your revenue provider**, choose **Stripe** and use **Quick connect**
    to create a restricted key with the pre-selected read scopes (include `rak_webhook_write` for
    instant sync). Paste the `rk_…` key. See [Connect Stripe](/revenue-attribution/connect-stripe).
  </Step>

  <Step title="Pass the visitor id at checkout">
    Set the visitor id on the Checkout Session so the sale joins to the click exactly:

    ```js theme={null}
    const vid = (await cookies()).get("vid")?.value;
    const session = await stripe.checkout.sessions.create({
      mode: "subscription",
      line_items: [/* ... */],
      success_url: "https://yourapp.com/thanks",
      client_reference_id: vid, // ← the join key
    });
    ```

    More options (Payment Links, Pricing Table) in
    [Pass the visitor id to checkout](/revenue-attribution/pass-vid-to-checkout).
  </Step>

  <Step title="Verify the checkout wiring">
    On **Integrations → Verify your checkout setup**, click **Check attribution setup**. Aim for an
    **OK** — it confirms a `vid` is present and matches a tracked visitor.
  </Step>

  <Step title="Make a test sale and read the report">
    Click one of your links, complete a (test-mode) purchase passing the `vid`, and wait for the
    sync (hourly, or seconds with the webhook). The order appears under **Orders**, and
    **Channels** credits it to the right channel.
  </Step>

  <Step title="Choose your model and window">
    On **Attribution**, pick last-touch, first-touch or linear and set your window (default 30
    days). See [Attribution models](/revenue-attribution/attribution-models).
  </Step>
</Steps>

<Check>
  You now have every Stripe sale credited to the channel that earned it — and lifetime value by
  channel building as subscriptions renew.
</Check>

## Troubleshooting

<AccordionGroup>
  <Accordion title="Orders show as Unmatched">
    The `vid` isn't reaching Stripe. Confirm the pixel is on the page checkout starts from, and that
    you pass `client_reference_id: window.trk.vid`. Email matching only works if you also called
    `identify(email)`.
  </Accordion>

  <Accordion title="No orders at all">
    Check the Stripe key is valid (the verifier reports `error` if it's revoked or missing a scope),
    and click **Sync now**. First sync looks back 30 days.
  </Accordion>

  <Accordion title="Revenue is hidden">
    Revenue attribution is a paid feature — upgrade from the Free tier to reveal it. See
    [Plans & billing](/account/plans-and-billing).
  </Accordion>
</AccordionGroup>
