Revenue attribution with LemonSqueezy
LemonSqueezy forwards custom checkout data to its webhooks as meta.custom_data. Put the visitor id there.
1. Add the custom data
With @lemonsqueezy/lemonsqueezy.js
import { cookies } from "next/headers";
import { createCheckout } from "@lemonsqueezy/lemonsqueezy.js";
const visitorId = (await cookies()).get("dataeasy_visitor_id")?.value;
const { data } = await createCheckout(STORE_ID, VARIANT_ID, {
checkoutData: {
custom: { dataeasy_visitor_id: visitorId ?? "" },
},
});Using checkout links instead of the API? Append the custom field to the URL:
const visitorId = document.cookie.match(/(?:^|; )dataeasy_visitor_id=([^;]+)/)?.[1];
const url = new URL("https://yourstore.lemonsqueezy.com/buy/VARIANT_ID");
if (visitorId) url.searchParams.set("checkout[custom][dataeasy_visitor_id]", visitorId);
window.location.href = url.toString();2. Connect the webhook
- In DataEasy, open Website settings → Revenue and pick LemonSqueezy.
- Copy the webhook endpoint shown there. It looks like
https://dataeasy.app/api/integrations/lemonsqueezy/webhook/<website id>. - In your LemonSqueezy dashboard, create a webhook pointing to that URL and subscribe it to:
order_created,subscription_payment_success,order_refunded. - Paste the webhook signing secret back in DataEasy and save.
Webhooks are verified with the X-Signature header (HMAC-SHA256 of the body with your signing secret).