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

Laravel Paddle UTM tracking: Cashier Paddle checkout

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

In a Laravel app, Paddle UTM tracking needs one value carried from the browser to the transaction: the virling_vid cookie. Load the Virling script in your Blade layout, exclude that cookie from EncryptCookies, and pass it to Cashier Paddle with customData(['virling_vid' => $vid]) when the controller builds the checkout.

Virling never needs the UTM tags inside Paddle. It reads virling_vid from the transaction's custom_data with a read-only API key and joins the payment to every visit logged under that ID, tagged or not, as the Paddle docs describe. Why the tags themselves are gone by checkout is covered in Paddle checkout UTM parameters.

Using another stack or provider? See Next.js Paddle UTM tracking, Rails Paddle UTM tracking, Laravel Stripe UTM tracking or Laravel LemonSqueezy UTM tracking.

Start free trial

Step 1: add the script to the Blade layout

Put the tag before </head> in the layout every page extends, usually resources/views/layouts/app.blade.php, next to Cashier's @paddleJS directive, which loads Paddle.js and initializes it with your client-side token. Self-hosting Virling? Point src at your own server instead of app.virling.com.

<!-- resources/views/layouts/app.blade.php -->
<script defer src="https://app.virling.com/v.js"
  data-site="yourdomain.com"></script>
@paddleJS

On every page the layout renders, the script stores a first-party virling_vid cookie and logs the visit, with its UTM tags, under that ID.

Step 2: leave the cookie out of encryption

Laravel encrypts cookies by default, and $request->cookie() returns nothing for a cookie it did not set itself. The script sets virling_vid in the browser, so exclude it. In Laravel 11 and later, in bootstrap/app.php:

->withMiddleware(function (Middleware $middleware) {
    $middleware->encryptCookies(except: ['virling_vid']);
})

In older versions, add it to $except in app/Http/Middleware/EncryptCookies.php:

protected $except = [
    'virling_vid',
];

Step 3: pass the cookie through Cashier's checkout options

Cashier Paddle's Checkout object holds the options Paddle.js receives when the button is clicked: the items, the customer, customData() and returnTo(). Read the cookie in the controller and add it there:

// app/Http/Controllers/BillingController.php
namespace App\Http\Controllers;

use Illuminate\Http\Request;

class BillingController extends Controller
{
    public function show(Request $request)
    {
        $checkout = $request->user()
            ->subscribe('pri_...', 'default')
            ->customData(['virling_vid' => $request->cookie('virling_vid')])
            ->returnTo(route('dashboard'));

        return view('billing', ['checkout' => $checkout]);
    }
}

Then render Cashier's checkout button in the Blade view. Paddle saves the custom data on the transaction when the buyer pays:

<!-- resources/views/billing.blade.php -->
<x-paddle-button :checkout="$checkout">
    Subscribe
</x-paddle-button>

For a one-off purchase, $request->user()->checkout('pri_...') returns the same checkout object, so customData() works there too. The inline <x-paddle-checkout> component takes the same $checkout.

Cashier's webhooks stay as they are

Cashier registers a /paddle/webhook route and handles events such as transaction.completed, subscription.created and subscription.updated to keep its customers, subscriptions and transactions tables in sync. Virling does not use webhooks: it pulls transactions from the Paddle API with its own read-only key, so there is no handler to add, no event to forward and no column to store the visitor ID in.

Or create the transaction from a controller

If your app creates the transaction itself through the Paddle API, set custom_data on it and return its ID. This controller reuses Cashier's API key and sandbox setting:

// app/Http/Controllers/CheckoutController.php
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Http;

class CheckoutController extends Controller
{
    public function store(Request $request)
    {
        $host = config('cashier.sandbox')
            ? 'https://sandbox-api.paddle.com'
            : 'https://api.paddle.com';

        $transaction = Http::withToken(config('cashier.api_key'))
            ->post("{$host}/transactions", [
                'items' => [['price_id' => 'pri_...', 'quantity' => 1]],
                'custom_data' => ['virling_vid' => $request->cookie('virling_vid')],
            ])
            ->throw()
            ->json('data');

        return ['transactionId' => $transaction['id']];
    }
}

// routes/web.php
Route::post('/checkout', [CheckoutController::class, 'store']);

Call the route with fetch from a page that uses the layout, sending the X-CSRF-TOKEN header because web routes check it, then open the returned ID with Paddle.Checkout.open({ transactionId }) on the Paddle.js instance @paddleJS set up. The Paddle integration page shows what Virling imports.

Subscriptions, swaps and renewals

Put the ID on the first checkout only. Renewals and plan changes made with Cashier's swap() create later transactions without it, and Virling gives those the channel of the subscription's first payment, as described in renewals.

Check that it works

Run one tagged visit and one sandbox payment as in test your setup, with a read-only Paddle API key from the sandbox, which starts with pdl_sdbx_, connected in Virling. What differs with Cashier:

  • In .env, set PADDLE_SANDBOX=true and your app's own sandbox API key, client-side token and webhook secret, and use a sandbox price ID (Cashier sandbox). @paddleJS then switches Paddle.js to the sandbox, and the controller above picks sandbox-api.paddle.com.
  • Visits on a .test address are not recorded for your site, so run the app on your domain or a subdomain of it.
  • Sign in as a new user with a new email address for each test: a later payment by the same customer is a renewal and keeps the first payment's channel.
  • Before you pay, the button's data-custom-data attribute should hold the ID from window.virling.vid(). Pay with one of Paddle's test cards, then open the transaction in the Paddle sandbox: its custom data should list virling_vid with the same ID.

A payment that reaches Paddle without the ID is still counted in revenue, under Unattributed.

Common mistakes

Open an Unattributed payment and look for Visitor under Details. If there is none, checkout did not carry the ID.

What you seeCauseFix
$request->cookie('virling_vid') is null, so the custom data holds no IDThe cookie is still encrypted as far as Laravel knows: EncryptCookies sets a value it cannot decrypt to nullAdd it to the encryption exceptions from step 2 (cookies and encryption)
Null only when the billing page is the first page of the visitCashier writes the custom data into the HTML on the server, before the script has set the cookieLink to the billing page from another page, or open checkout in the browser with window.virling?.vid?.() in customData (Paddle docs)
A subscription is saved as default instead of its own typesubscribe() sets subscription_type as custom data, and customData() replaces it (Cashier source)Use checkout('pri_...')->customData(['subscription_type' => 'team', 'virling_vid' => $vid])
Many payments carry the same visitor IDThe page with the Paddle button is cached, for example with a public cache.headers rule or at a CDN, and the ID is in its HTMLKeep that page out of shared caches (cache control middleware)
The checkout route returns 419The fetch call sent no CSRF tokenSend the X-CSRF-TOKEN header from a csrf-token meta tag in the layout (X-CSRF-TOKEN)
A RequestException with status 403 from the controllerThe key and host do not match, for example a sandbox key while PADDLE_SANDBOX is falseSandbox keys work only on sandbox-api.paddle.com (Paddle sandbox)
PADDLE_SANDBOX=true has no effectThe configuration is cached, so .env is not loadedRun php artisan config:clear (configuration caching)
The visit has no UTM tagsThe ad lands on a URL that redirects, for example to add a locale or a trailing slash, and the redirect does not keep the query stringKeep the query string. See UTM parameters lost after redirect
No visitor ID when checkout runs on another domainThe cookie is first-party, so a page on another domain does not receive itPut the page with the checkout button on the domain the script runs on, or a subdomain (link checkout to visits)
The payment has a visitor ID but is Unattributed after a test on a .test addressValet serves apps on .test, and visits are kept only when the page's host is your site's domain or one of its subdomainsTest on a subdomain of the domain in data-site (script docs)

Every other cause is in Unattributed revenue. A payment made before a fix usually stays Unattributed, so make a new one to check.

Frequently asked questions

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

Send the Virling visitor ID rather than the tags. In the controller that builds the Cashier checkout, read $request->cookie('virling_vid') and add it with customData(['virling_vid' => $vid]). The script has already logged every visit's UTM tags under that ID, so the payment joins all of them.

Why does $request->cookie('virling_vid') return null?

Laravel encrypts cookies by default and returns nothing for a cookie it did not set. Leave virling_vid out of encryption: in Laravel 11 and later with $middleware->encryptCookies(except: ['virling_vid']) in bootstrap/app.php, in older versions by adding it to $except in app/Http/Middleware/EncryptCookies.php.

Does customData() keep the Cashier subscription type?

No. subscribe() stores the type as subscription_type in the custom data, and customData() replaces that data, so Cashier saves the subscription with the type default. For another type, call checkout('pri_...')->customData(['subscription_type' => 'team', 'virling_vid' => $vid]) instead of subscribe().

Do I need to change Cashier's Paddle webhook?

No. Virling reads transactions from the Paddle API with a read-only key and never calls your /paddle/webhook route, so Cashier's handlers for transaction.completed and the subscription events stay as they are.

Can I create the transaction in a controller instead?

Yes. Post to the Paddle API's /transactions endpoint with custom_data set to ['virling_vid' => $request->cookie('virling_vid')], return the transaction ID, and open it with Paddle.Checkout.open({ transactionId }) on a page where @paddleJS runs.

Do Cashier swaps and renewals need the visitor ID?

No. Only the first checkout carries it. Renewals and swap() plan changes take the channel of the subscription's first payment.

What happens if the cookie is missing?

$request->cookie('virling_vid') returns null, so the checkout opens without a visitor ID in its custom data, for example when the script is blocked or runs in cookieless mode. The payment is still counted in revenue, under Unattributed.

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