Remix Paddle checkout UTM tracking: pass the visitor ID
By Devendra Variya, co-founder of Virling. Published 2026-11-26.
Remix Paddle checkout UTM tracking is easier than in a browser-only app, because a server sits in front of every page. The Virling script sets a first-party virling_vid cookie, the browser sends it with each request, and your loader or action reads it from the Cookie header and puts it on the Paddle transaction as custom_data.virling_vid. Virling credits the payment to the visits stored under that ID, with their UTM tags.
The code is for Remix v2 on Paddle Billing, with a section for React Router v7 framework mode, which is where Remix development continues. A client-only app with no server is covered in React Paddle UTM tracking. The Stripe version is Remix Stripe UTM tracking, and where the values appear inside Paddle is in Paddle checkout UTM parameters.
How the payment finds the visit
The UTM tags stay in the landing URL, which Paddle never sees, so a transaction with no visitor ID is Unattributed. Virling reads virling_vid from the transaction’s custom_data and joins it to the visits recorded under that ID; the Paddle docs page has the details.
Step 1: add the script to the root route
Put the tag in the <head> in app/root.tsx, next to <Meta /> and <Links />. It is rendered into every page, and client-side navigation is counted on its own, so load it once here. A self-hosted Virling serves v.js from your own server address instead.
// app/root.tsx
<head>
<Meta />
<Links />
<script defer src="https://app.virling.com/v.js"
data-site="yourdomain.com"></script>
</head>The script sets the first-party virling_vid cookie on your domain and records the UTM tags of each visit against it. The cookie is created in the browser, so the server sees it from the second request on.
Step 2: read the cookie in a loader and open checkout
The @paddle/paddle-js package (npm install @paddle/paddle-js) injects Paddle.js from Paddle’s CDN and resolves to the Paddle instance once it is ready (source: Paddle, paddle-js-wrapper). The loader reads the cookie from the request’s Cookie header and hands it to the page, with the client-side token:
// app/routes/pricing.tsx
import { useEffect, useState } from "react";
import type { LoaderFunctionArgs } from "@remix-run/node";
import { useLoaderData } from "@remix-run/react";
import { initializePaddle, type Paddle } from "@paddle/paddle-js";
declare global {
interface Window { virling?: { vid?: () => string | null } }
}
export async function loader({ request }: LoaderFunctionArgs) {
const vid = request.headers.get("Cookie")
?.match(/(?:^|;\s*)virling_vid=([^;]+)/)?.[1] ?? null;
return {
vid,
token: process.env.PADDLE_CLIENT_TOKEN!,
sandbox: process.env.PADDLE_ENV === "sandbox",
};
}
export default function Pricing() {
const { vid, token, sandbox } = useLoaderData<typeof loader>();
const [paddle, setPaddle] = useState<Paddle>();
useEffect(() => {
initializePaddle({ environment: sandbox ? "sandbox" : "production", token })
.then(setPaddle)
.catch(console.error);
}, [token, sandbox]);
function buy() {
// The loader has no cookie when this page is the landing page.
const id = vid ?? window.virling?.vid?.();
paddle?.Checkout.open({
items: [{ priceId: "pri_...", quantity: 1 }],
...(id ? { customData: { virling_vid: id } } : {}),
});
}
return <button onClick={buy} disabled={!paddle}>Buy</button>;
}initializePaddle touches window, so it runs in an effect, never in the loader or during server rendering. The client-side token is meant for the browser; never return an API key from a loader, because loader data is sent to the page. Paddle allows one Paddle.Initialize() per page (source: Paddle, Paddle.Initialize), and on later calls the wrapper uses Paddle.Update() instead, so navigating back to /pricing does not break checkout.
When the cookie is missing. If /pricing is the first page of the visit, its loader ran before the script set the cookie, so the click falls back to window.virling.vid(). That returns null in cookieless mode and before a visitor accepts under Until consent, and an ad blocker can stop the script. Paddle rejects a customData object with no keys (source: Paddle, Paddle.Checkout.open), so the spread adds it only when there is an ID, and a sale without one still completes, as Unattributed.
The loader’s data now differs per visitor. If a CDN caches /pricing, send Cache-Control: private for it from a headers export, or one visitor’s ID can reach another.
Step 3: or create the transaction on the server
A Remix action runs on the form post, and by the time the buyer submits, the script has normally set the cookie, so the action does not have the landing-page gap the loader has. Create the transaction there with custom_data, using an API key that has transaction.write:
// app/routes/pricing.tsx
import type { ActionFunctionArgs } from "@remix-run/node";
export async function action({ request }: ActionFunctionArgs) {
const vid = request.headers.get("Cookie")
?.match(/(?:^|;\s*)virling_vid=([^;]+)/)?.[1];
const res = await fetch(`${process.env.PADDLE_API_URL}/transactions`, {
method: "POST",
headers: {
authorization: `Bearer ${process.env.PADDLE_API_KEY}`,
"content-type": "application/json",
},
body: JSON.stringify({
items: [{ price_id: "pri_...", quantity: 1 }],
...(vid ? { custom_data: { virling_vid: vid } } : {}),
}),
});
if (!res.ok) throw new Response("Paddle error", { status: 502 });
const { data } = await res.json();
return { transactionId: data.id as string };
}PADDLE_API_URL is https://api.paddle.com, or https://sandbox-api.paddle.com with a sandbox key. This key stays on the server and is not the read-only key you give Virling, which cannot create transactions. Post to the action with useFetcher and open the result in Paddle.js:
const fetcher = useFetcher<typeof action>();
useEffect(() => {
const id = fetcher.data?.transactionId;
if (id) paddle?.Checkout.open({ transactionId: id });
}, [fetcher.data, paddle]);
return (
<fetcher.Form method="post">
<button disabled={!paddle}>Buy</button>
</fetcher.Form>
);Create it in the action, not a loader, so a <Link prefetch> or a crawler does not make transactions nobody asked for.
Hosted checkout links
Hosted checkout links send the buyer to a page on Paddle’s domain. Paddle documents query parameters such as price_id and transaction_id for them, but not custom_data (source: Paddle, hosted checkout), and the Virling script does not add the visitor ID to Paddle checkouts by itself, so a plain hosted link gives an Unattributed payment. With the action from step 3, return a redirect to your hosted link with ?transaction_id= and the new ID instead of opening Paddle.js; the custom data is already on the transaction.
In React Router v7
In framework mode the loader, action and checkout code stay the same. Import Route from ./+types/pricing, type the arguments as Route.LoaderArgs and Route.ActionArgs, read the data from the component’s loaderData prop instead of useLoaderData, and import useFetcher and redirect from react-router instead of @remix-run/react and @remix-run/node:
import { useFetcher } from "react-router";
import type { Route } from "./+types/pricing";
export async function loader({ request }: Route.LoaderArgs) { /* same */ }
export async function action({ request }: Route.ActionArgs) { /* same */ }
export default function Pricing({ loaderData }: Route.ComponentProps) {
const { vid, token, sandbox } = loaderData;
// same as above
}Renewals need no loader
Paddle charges renewals itself, so no loader or action runs and no cookie is read for them. Virling marks transactions with origin subscription_recurring, subscription_update or subscription_charge as renewals and gives them the channel of the customer’s first payment, so the custom_data your server sets only has to be right on that first one. See renewals in the docs.
Test it in the Paddle sandbox
- In Virling, connect a sandbox API key that starts with
pdl_sdbx_, withtransaction.readandadjustment.read(Paddle docs). - Set
PADDLE_ENV=sandbox, a client-side token that starts withtest_inPADDLE_CLIENT_TOKEN, and a sandbox price ID (source: Paddle, client-side tokens). For step 3, also setPADDLE_API_URLto the sandbox API andPADDLE_API_KEYto a second sandbox key withtransaction.write. - Deploy to your domain or a subdomain of it, such as
staging.yourdomain.com, open a private window onhttps://staging.yourdomain.com/?utm_source=test&utm_medium=email, then follow a link to/pricing. - Click Buy and pay once with the test card
4242 4242 4242 4242, any name and a future expiry date (source: Paddle, test cards). In the Paddle sandbox dashboard, the transaction should listvirling_vidunder custom data. - About a minute later, after Virling’s next sync, the payment appears at
/app/yourdomain.com/paymentsunder thetestsource and the Email channel.
The dev server on localhost records nothing, because the script is silent there and visits are kept only from the site’s domain and its subdomains. Each test needs its own email address, or Paddle sees a returning customer and Virling counts a renewal. A site has one Paddle connection, and sandbox payments stay in your reports after you switch to a live key. If a step fails, see test your setup.
Common mistakes
| What you see | Cause | Fix |
|---|---|---|
| No Paddle.js payment has a channel | Paddle.Checkout.open gets no customData | Spread the ID into the call, as in step 2 |
Payments that start on /pricing are Unattributed | The loader ran before the cookie existed, and there is no browser fallback | Fall back to window.virling?.vid?.() on click, or use the action |
window is not defined on the server | Paddle.js is initialized during rendering or in the loader | Initialize it in useEffect |
| The action gets a 403 from Paddle | The key lacks transaction.write, or it is the read-only key | Use a separate key with write access on the server |
| Paddle lists draft transactions nobody bought | The transaction is created in a loader, which prefetching and crawlers run | Create it in the action |
| Hosted checkout payments are Unattributed | Hosted links carry no custom data | Create the transaction in the action, then pass transaction_id |
| A payment is credited to someone else’s visit | A CDN cached /pricing with another visitor’s loader data | Send Cache-Control: private from headers |
Every other cause is in Unattributed revenue. The Paddle integration page shows what you get per channel once payments are joined.
Frequently asked questions
How do I pass UTM parameters to Paddle checkout in Remix?
Send one cookie value instead of the tags. Read virling_vid from the request in a loader or action, and set it as customData in Paddle.js or as custom_data on a transaction your server creates. The UTM tags of each visit are already stored in Virling under that ID.
Why is the cookie missing in my loader?
The script creates the cookie in the browser, so the server sees it from the second request on. If the pricing page is the first page of the visit, its loader runs before the cookie exists. Fall back to window.virling?.vid?.() when the buyer clicks.
Can I add custom data to a Paddle hosted checkout link?
Paddle documents no custom_data parameter for hosted checkout links. Create the transaction in a Remix action with custom_data: { virling_vid }, then pass its ID as transaction_id in the hosted checkout URL.
Does it work in React Router v7?
Yes. The loader, action and checkout code are the same in framework mode. Type them with Route.LoaderArgs and Route.ActionArgs, read the data from the loaderData prop instead of useLoaderData, and import from react-router.
Should I create the Paddle transaction in a loader or an action?
In an action. Loaders also run for link prefetching and for crawlers, so a loader would create transactions nobody asked for, while the form post that runs the action carries the buyer's cookie.
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.