Laravel LemonSqueezy UTM tracking: checkout custom data
By Devendra Variya, co-founder of Virling. Published 2026-11-23.
Laravel LemonSqueezy UTM tracking comes down to one value. Load the Virling script in your Blade layout, leave the virling_vid cookie out of Laravel's cookie encryption, then read it with $request->cookie('virling_vid') in the controller that creates the checkout and pass it as custom data, with checkout('VARIANT_ID', custom: ['virling_vid' => $vid]) from the lemonsqueezy/laravel package. LemonSqueezy returns it in its webhook, and Virling joins the order to every visit behind that visitor ID, with the UTM tags of each.
This post covers Laravel with the lemonsqueezy/laravel package and with the LemonSqueezy API directly. The same steps in a Next.js app are in Next.js LemonSqueezy UTM tracking, and with other providers in Laravel Stripe UTM tracking and Laravel Paddle UTM tracking. For what LemonSqueezy does with custom data outside Laravel, see the general guide to LemonSqueezy UTM tracking.
Why LemonSqueezy checkout loses your UTM tags
UTM tags live on the landing URL. By the time a visitor clicks Buy they are usually a few pages in, and checkout runs on your store's lemonsqueezy.com address, so nothing from your site travels with them unless it is in the checkout. Passing one visitor ID instead of the tags keeps earlier visits and untagged ones, such as search and referrals, too.
Step 1: add the script to the Blade layout
Paste the tag before </head> in the layout every page extends, usually resources/views/layouts/app.blade.php, next to the package's @lemonJS directive if you use the checkout overlay. If you self-host, replace app.virling.com with your Virling server.
<!-- resources/views/layouts/app.blade.php --> <script defer src="https://app.virling.com/v.js" data-site="yourdomain.com"></script> @lemonJS
The script sets the first-party virling_vid cookie on your domain and records the UTM tags of each visit against it.
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 visitor ID as custom data
The package's checkout() creates the checkout through the LemonSqueezy API and takes custom data as its custom argument. Read the cookie in the controller and pass it there:
// app/Http/Controllers/BuyController.php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class BuyController extends Controller
{
public function __invoke(Request $request)
{
$custom = array_filter(['virling_vid' => $request->cookie('virling_vid')]);
return $request->user()
->checkout('VARIANT_ID', custom: $custom)
->redirect();
}
}The package adds its own billable_id and billable_type keys to the same custom data, so virling_vid sits next to them. To open the overlay instead of redirecting, return the checkout to a view and render the package's button component:
$checkout = $request->user()->checkout('VARIANT_ID', custom: $custom);
return view('billing', ['checkout' => $checkout]);
<!-- resources/views/billing.blade.php -->
<x-lemon-button :href="$checkout">
Buy now
</x-lemon-button>Plain links to STORE.lemonsqueezy.com/checkout/buy/VARIANT_ID in a Blade view need no code at all: the script adds checkout[custom][virling_vid] to every such link when the page loads and when a visitor clicks one, and never replaces a value that is already there.
Or create the checkout with the LemonSqueezy API
Without the package, create the checkout with POST /v1/checkouts and set the visitor ID in data.attributes.checkout_data.custom:
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Http;
Route::post('/checkout', function (Request $request) {
$custom = array_filter(['virling_vid' => $request->cookie('virling_vid')]);
$checkout = Http::withToken(config('services.lemonsqueezy.key'))
->withHeaders([
'Accept' => 'application/vnd.api+json',
'Content-Type' => 'application/vnd.api+json',
])
->post('https://api.lemonsqueezy.com/v1/checkouts', ['data' => [
'type' => 'checkouts',
'attributes' => ['checkout_data' => ['custom' => (object) $custom]],
'relationships' => [
'store' => ['data' => ['type' => 'stores', 'id' => 'STORE_ID']],
'variant' => ['data' => ['type' => 'variants', 'id' => 'VARIANT_ID']],
],
]])->throw()->json('data');
return redirect()->away($checkout['attributes']['url']);
})->name('checkout');The (object) cast keeps an empty custom as a JSON object when the cookie is missing. LemonSqueezy's reference for the request is create a checkout.
Step 4: connect LemonSqueezy
Create an API key in LemonSqueezy under Settings, API, and paste it into Virling. LemonSqueezy only returns checkout custom data in webhooks, so Virling registers its own webhook on each of your stores for order_created and subscription_payment_success and checks each request's X-Signature. It sits next to the webhook the package uses and does not change it. The webhook needs VIRLING_BASE_URL to be a public https:// address; without one, LemonSqueezy payments show as Unattributed. The full setup is in the LemonSqueezy docs and on the LemonSqueezy integration page.
Subscriptions and renewals
Only the first payment needs the visitor ID. Renewal invoices keep the channel of the subscription's first payment, and the first charge of a subscription is imported once, as its order; see renewals.
Check that it works
Switch your store to test mode and connect a key created there, so Virling registers its webhook in test mode. In a private window, open your site from a tagged link such as https://yourdomain.com/?utm_source=test&utm_medium=test, go to checkout and pay with a test card. Then open the payments list at /app/yourdomain.com/payments: the order should show the test source instead of Unattributed. Open it to see its journey. The full checklist is in test your setup.
Orders without a visitor ID still count toward revenue, as Unattributed. How the join works from visit to order is in how to track LemonSqueezy revenue by traffic source.
Common mistakes
- The cookie is still encrypted.
$request->cookie('virling_vid')returns null, so the checkout carries no ID. Add it to the encryption exceptions from step 2. - A redirect drops the UTM tags. If the 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 string, the visit is recorded without its tags. See UTM parameters lost after redirect.
- Checkout runs on another domain. The cookie is first-party, so the page with the Buy button has to be on the domain the script runs on, or the request does not carry it.
- No public webhook address. On a self-hosted Virling without a public
https://VIRLING_BASE_URL, no webhook is registered, so every order is Unattributed even when checkout carries the ID. - Looking for the ID in the orders API. LemonSqueezy does not return custom data when you read an order, only in webhooks. Check the order's journey in Virling instead.
Frequently asked questions
How do I pass UTM parameters to LemonSqueezy checkout in Laravel?
Pass the Virling visitor ID instead. Read it with $request->cookie('virling_vid') in the controller that creates the checkout and pass it as custom data, for example $request->user()->checkout('VARIANT_ID', custom: ['virling_vid' => $vid]). LemonSqueezy returns it in its webhook, and the Virling script records the UTM tags of every visit against that ID, so the order is joined to 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 Virling need the webhook from the lemonsqueezy/laravel package?
No. Virling registers its own webhook on each store for order_created and subscription_payment_success when you connect LemonSqueezy, next to the one the package uses. Both receive the same custom data.
Do plain checkout links need code?
No. The script adds checkout[custom][virling_vid] to every link to a lemonsqueezy.com address when the page loads and when a visitor clicks one, and never replaces a value that is already there.
Why can I not see virling_vid on my orders in LemonSqueezy?
LemonSqueezy only returns checkout custom data in webhooks, not when you read orders from the API. The webhook Virling registers needs VIRLING_BASE_URL to be a public https address.
What happens if the cookie is missing?
$request->cookie('virling_vid') returns null and array_filter leaves the key out, so the checkout is created without a visitor ID, for example when the script is blocked or runs in cookieless mode. The order still counts toward revenue, as Unattributed.
See which campaigns bring LemonSqueezy orders
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.