trakily.

Lemon Squeezy

Connect Lemon Squeezy with an API key and attribute orders and subscriptions.

Connecting Lemon Squeezy imports your payments, refunds and subscriptions into Trakily and keeps them in sync. Trakily only reads data; it never creates charges or changes anything in your Lemon Squeezy account apart from registering one webhook, if you allow it. Read Revenue attribution first if you haven't.

1. Create a api key

  1. 1

    Lemon Squeezy → Settings → API → Create API key

  2. 2

    Paste the key here (test-mode keys only see test data)

Direct link: app.lemonsqueezy.com/settings/api

Test-mode keys only see test-mode data. Every store in the account is synced, and each store gets its own webhook (Lemon Squeezy webhooks belong to one store), all signed with the same secret. Stores you create later are picked up on the next sync, every 15 minutes. If a store's webhook can't be registered, the webhook card says which one; that store still updates through the regular sync.

2. Connect it in Trakily

  1. 1

    Open your site's Settings → Revenue (owners only) and click Connect next to Lemon Squeezy.

  2. 2

    Paste the api key, then click Connect Lemon Squeezy. Trakily checks the key.

  3. 3

    The first sync imports your full history in the background. After that, Trakily pulls changes every 15 minutes, and webhooks deliver new payments within seconds.

Keys are encrypted at rest and only used to read payments. Test-mode and live keys both work; a test key only sees test data.

3. Webhook for real-time updates

Trakily registers the webhook in your Lemon Squeezy account for you when you connect, as long as the key allows it. The webhook card in Settings then says Registered automatically. It stays in your Lemon Squeezy account; delete it there if you disconnect.

Prefer to add it yourself? Tick I'll register the webhook myself when connecting, then create an endpoint in Lemon Squeezy with the URL shown in Settings and these events, and paste its signing secret into the webhook card:

Endpoint URL (your site's id is filled in on the Settings page)
https://trakily.com/api/webhooks/lemonsqueezy/pls_…
order_createdorder_refundedsubscription_createdsubscription_updatedsubscription_cancelledsubscription_expiredsubscription_payment_successsubscription_payment_refunded

4. Pass the visitor id at checkout

Lemon Squeezy checkouts accept custom data in the checkout URL. Add the visitor id as checkout[custom][trakily_visitor_id] before sending the buyer to checkout. You can add checkout[custom][trakily_session_id] the same way. Trakily reads both from the webhook's custom data and from orders.

Lemon Squeezy checkout link
// Append custom data to your checkout URL (client side)
const vid = decodeURIComponent(document.cookie.match(/_trakily_vid=([^;]+)/)?.[1] ?? "").split("|")[0];
const url = new URL("https://yourstore.lemonsqueezy.com/buy/<variant>");
url.searchParams.set("checkout[custom][trakily_visitor_id]", vid);
location.href = url.toString();

The keys are always trakily_visitor_id and trakily_session_id. The visitor id is the first part of the _trakily_vid cookie (before the first |); the session id is the _trakily_sid cookie. If the session id is missing, Trakily uses the visitor's latest session before the payment.

Success page detection

If your post-purchase redirect lands on your site with an order_id query parameter, the script reports it and the order is linked to that visitor.

Troubleshooting

  • “This Lemon Squeezy account has no stores.” Create a store first, then connect again.
  • “Webhook not registered for store …” The key can't manage webhooks for that store. Reconnect with a key from the store owner's account, or add the webhook to that store by hand with the URL and secret from Settings.
  • Payments arrive but show as unattributed. Pass the visitor id at checkout (step 4). Payments that can't be matched yet are retried every hour for 90 days, so a later identify call can still link them.
  • Nothing new since connecting. Click Sync now on the provider card. If the card says Needs attention, the error message tells you what the provider returned (for example a revoked key).