virling Pricing Self-host Demo Changelog Agencies GitHub Start free trial
blog / 2026-11-25

React Paddle UTM tracking: pass the visitor ID to Paddle.js

By Devendra Variya, co-founder of Virling. Published 2026-11-25.

React Paddle UTM tracking takes one value: the visitor ID. In a single-page app it happens entirely in the browser: add the Virling script to index.html, load Paddle.js with @paddle/paddle-js, wait until window.virling.vid() returns an ID, and open checkout with customData: { virling_vid }. With no server to read a cookie, the browser is the only place the ID can come from, so the code below waits for it. Overlay and inline checkout take it the same way.

Start free trial

This post is for a Vite single-page app on Paddle Billing. For server-created transactions and hosted checkout, see Paddle checkout UTM parameters. With the App Router, see Next.js Paddle UTM tracking. A server-rendered app that reads the cookie in a loader is covered in Remix Paddle UTM tracking. The Stripe version is React Stripe UTM tracking.

Client-side routing and the campaign

A visitor lands on /?utm_source=newsletter&utm_campaign=launch, and a route link to /pricing usually leaves the query string behind, so location.search is empty by the time they click Buy. Paddle stores only what you hand to Paddle.Checkout.open, which is why Virling reads the visitor ID from the transaction’s custom_data instead of tags; the Paddle docs page has the details.

The Virling script hooks into history.pushState, replaceState and the back and forward buttons, so React Router navigations are counted without extra code. The landing pageview carries the tags and the referrer. Later route changes carry no referrer and stay in the same channel as the landing. Routes kept in the hash, such as /#/pricing, send no pageview. See single-page apps in the docs.

Step 1: add the script to index.html

Paste the tag before </head> in the index.html at the project root. Self-hosted, point src at your own Virling server.

<!-- index.html -->
<script defer src="https://app.virling.com/v.js"
  data-site="yourdomain.com"></script>

Load it once, here, not from a component. It must stay a plain external script: bundled, or with type="module", it cannot find its own data-site.

Step 2: load Paddle.js and wait for the ID

npm install @paddle/paddle-js adds Paddle’s official loader, which fetches Paddle.js from Paddle’s CDN on first use (source: Paddle, paddle-js-wrapper). Put both helpers in one file:

// src/paddle.js
import { initializePaddle } from "@paddle/paddle-js";

export function loadPaddle() {
  return initializePaddle({
    environment: import.meta.env.VITE_PADDLE_ENV,
    token: import.meta.env.VITE_PADDLE_TOKEN,
  });
}

// Waits up to two seconds; without an ID, checkout opens with no customData.
export async function visitorData() {
  for (let i = 0; i < 20 && !window.virling?.vid; i++) {
    await new Promise((r) => setTimeout(r, 100));
  }
  const vid = window.virling?.vid?.();
  return vid ? { customData: { virling_vid: vid } } : {};
}

VITE_PADDLE_ENV is sandbox or production, and VITE_PADDLE_TOKEN is the client-side token for it. Never put an API key in a VITE_ variable, because those end up in the browser bundle. Paddle says Paddle.Initialize() can be called only once on a page (source: Paddle, Paddle.Initialize). The wrapper loads the script once and switches to Paddle.Update() when Paddle.js is already initialized, so React’s double effects in Strict Mode are safe.

When the script has not loaded yet. It loads with defer, so an early click can come before it, or an ad blocker can stop it. Then window.virling has no vid, and the loop waits for it. vid() also returns null in cookieless mode and before a visitor accepts under Until consent. The helper leaves customData out in those cases, because Paddle asks for valid JSON with at least one key (source: Paddle, Paddle.Checkout.open). The sale goes through either way.

Step 3: open overlay checkout

// src/BuyButton.jsx
import { useEffect } from "react";
import { loadPaddle, visitorData } from "./paddle";

export default function BuyButton({ priceId }) {
  useEffect(() => {
    loadPaddle().catch(console.error);
  }, []);

  async function buy() {
    const [paddle, data] = await Promise.all([loadPaddle(), visitorData()]);
    paddle?.Checkout.open({
      items: [{ priceId, quantity: 1 }],
      ...data,
    });
  }

  return <button onClick={buy}>Buy</button>;
}

Overlay is the default display mode. The effect starts the download early, so the click does not wait for it. The ID is read on click, not on first render, because that is when it has had the most time to arrive. If your own code already passes customData, merge virling_vid into that object.

Step 4: or open inline checkout

Inline checkout renders a frame inside your page and usually opens on mount, so the wait matters more here. Paddle finds the container by its class name, without a dot (source: Paddle, inline checkout).

// src/InlineCheckout.jsx
import { useEffect } from "react";
import { loadPaddle, visitorData } from "./paddle";

export default function InlineCheckout({ priceId }) {
  useEffect(() => {
    let paddle;
    let gone = false;
    Promise.all([loadPaddle(), visitorData()])
      .then(([p, data]) => {
        if (gone || !p) return;
        paddle = p;
        p.Checkout.open({
          settings: {
            displayMode: "inline",
            frameTarget: "checkout-container",
            frameInitialHeight: 450,
            frameStyle: "width: 100%; min-width: 312px; background: transparent; border: none;",
          },
          items: [{ priceId, quantity: 1 }],
          ...data,
        });
      })
      .catch(console.error);
    return () => {
      gone = true;
      paddle?.Checkout.close();
    };
  }, [priceId]);

  return <div className="checkout-container" />;
}

Paddle asks for a min-width of at least 312 pixels with checkout padding on, which still fits a narrow phone if the container has little padding of its own. The cleanup calls Paddle.Checkout.close(), which removes the inline frame, when the route changes (source: Paddle, Paddle.Checkout.close). Paddle says settings can be set for each checkout, as here, or as defaults under checkout.settings when you initialize. Its displayMode note mentions frameTarget in Initialize, so if the frame does not appear, set it there too.

What changes with no server

A static build on a CDN has no loader or API route, and that shapes three things. Nothing reads the virling_vid cookie on a request, so window.virling.vid() is the only source of the ID and the wait in visitorData() is the only fallback. Paddle.js creates the transaction itself from the items you pass, using the client-side token, which is safe to ship in the bundle. Virling needs no webhook endpoint either: it reads completed transactions with its own read-only API key every minute, so there is nothing for you to host.

What you give up is setting custom_data before checkout opens, which hosted checkout links and server-created transactions need. If you add a server later for those, set custom_data.virling_vid there from the cookie and open the transaction with transactionId.

Step 5: test in the sandbox

  1. Give Virling a sandbox API key that starts with pdl_sdbx_.
  2. Set VITE_PADDLE_ENV=sandbox, a client-side token that starts with test_, and a sandbox price ID (source: Paddle, sandbox). Vite writes these into the bundle at build time, so build again after changing them, and publish to your domain or a subdomain of it, such as staging.yourdomain.com.
  3. Open a private window on a tagged link, such as https://staging.yourdomain.com/?utm_source=test&utm_medium=email, click through to another route, and run window.virling.vid() in the console to see the ID checkout will carry.
  4. Open checkout from that route and pay with one of Paddle’s test cards.
  5. Virling syncs every minute; after that, /app/yourdomain.com/payments lists the payment with the test source in the Email channel.

Nothing is recorded from vite dev on localhost or from a preview URL on a hosting provider’s domain, because only visits from your site’s domain and its subdomains are kept. Pay with a fresh email address every time, since Paddle treats a repeat buyer as the same customer and Virling then counts a renewal.

Renewals in a client-only app

Paddle bills renewals without the buyer opening your app, so no React code runs for them and no wait is needed. Virling gives every transaction with origin subscription_recurring, subscription_update or subscription_charge the channel of the customer’s first payment. With made-up numbers: $30 paid in May after a newsletter click, then renewed in June and July, puts all $90 under Email. See renewals in the docs and Paddle for SaaS for retention by channel.

Symptoms, causes and fixes

SymptomCauseFix
Every payment from the app is UnattributedPaddle.Checkout.open is called without customDataSpread the result of visitorData() into the call, as in steps 3 and 4
Only early clicks are UnattributedThe ID was read on first render, before the script loadedRead it when checkout opens, after the wait
Payments opened with transactionId are UnattributedYour server created the transaction without the IDSet custom_data.virling_vid on the server
Paddle holds the ID, yet the payment is UnattributedIt is on a customer, product or price, or that visitor has no session inside the lookback window before the paymentSet it on the transaction, and check the window
Only the first page of the app is countedThe router keeps its route in the hashSwitch to History API routes with real paths
Two pageviews per routeThe script is loaded twice, such as in index.html and a tag managerLoad it once
Nothing is recorded while developingThe script skips localhost, and visits from other domains are droppedTest on your domain or a subdomain of it
Test payments after the first get its channelPaddle sees a returning customer, and Virling counts a renewalUse a fresh email address per test

To see whether the ID reached Paddle, open the payment in Virling: if it lists no visitor ID, checkout did not carry one. Every other cause is in Unattributed revenue.

Frequently asked questions

How do I pass UTM parameters to Paddle checkout in React?

Send the visitor ID, not the tags. Once window.virling.vid() returns a value, pass it to Paddle.Checkout.open as customData: { virling_vid }. Virling already stored the UTM tags of each visit under that ID.

Does it work with inline checkout as well as overlay?

Yes. Both open with Paddle.Checkout.open and take the same customData. Inline checkout often opens on page load, so wait for the visitor ID before you open it.

What happens if the Virling script has not loaded when the buyer clicks?

The visitor ID is missing at that moment, so wait for it for up to two seconds and then open checkout anyway. A payment without the ID still counts toward revenue, as Unattributed.

Do React Router navigations lose the campaign?

No. The landing pageview records the tags, and later route changes stay in the same channel as the landing. Checkout carries the visitor ID, so the address bar does not need the tags. Hash routes are the exception: their route changes are not counted as pageviews, though the landing still is.

Do I need a backend or a webhook for this?

No. Paddle.js creates the transaction in the browser with your client-side token, and Virling reads completed transactions with a read-only API key, so a static build is enough. You need a server only to set custom_data before checkout, such as for hosted checkout links.

See which campaigns bring Paddle revenue

Virling is open source under AGPL. Self-host it free, or use the hosted version with a 14-day free trial. It connects to Stripe, Paddle, Shopify, WooCommerce, Polar, LemonSqueezy, Dodo, Creem and RevenueCat.

Start free trial See the demo