Skip to content
Guide · Revenue & attribution

Server-side conversion and revenue tracking

Server-side conversion tracking means your backend, not the visitor's browser, reports that a payment happened. You send the event from the place where money is confirmed, usually a payment webhook, so the number in your analytics matches your billing system and can't be faked from the browser console.

Updated · 6 min read

When to send events from your backend

Browser events are great for clicks, page views and funnel steps. They are a poor source of truth for money, for three reasons:

  • Anyone can send them. The site ID is in your page source, so anyone can call window.linqry('purchase', {}, 999999) from the console. Linqry caps how much revenue a single browser event may claim and rejects anything above it, but a cap isn't verification.
  • They can be lost. A buyer who closes the tab on the thank-you page, or whose ad blocker blocks analytics scripts, never sends the event.
  • Some revenue never touches a browser. Subscription renewals, invoices paid by bank transfer and upgrades made by your sales team happen on the server.

So the usual split is: track behavior in the browser, and send revenue from the backend. Linqry's HTTP API accepts events authenticated with the site's write key, which only your server knows.

Get your write key

Open your site in Linqry and go to Install. Under Server-side events and revenue, reveal and copy the write key. Only the site owner and admins can see it. Store it as an environment variable such as LINQRY_WRITE_KEY, next to your site ID (LINQRY_SITE_ID), and never put it in client-side code: anyone holding it can write events to your site.

The request: POST /api/track

One authenticated POST records one event. Revenue is an integer in the smallest currency unit, so 4900 means $49.00:

curl -X POST https://linqry.com/api/track \
  -H 'authorization: Bearer YOUR_WRITE_KEY' \
  -H 'content-type: application/json' \
  -d '{
    "siteId": "YOUR_SITE_ID",
    "event": "invoice-paid",
    "url": "https://example.com/?utm_source=newsletter&utm_medium=email&utm_campaign=nov-launch",
    "referrer": "https://news.example.org/",
    "properties": { "plan": "pro" },
    "revenue": 4900
  }'

# 200 {"ok":true}

The key can also go in an x-linqry-key header. The fields that matter most here:

FieldWhat to send
siteIdRequired. Your site's UUID.
eventRequired. 1 to 64 characters: letters, digits, spaces and _ . : / -. Pick one name per kind of payment, such as invoice-paid.
revenueInteger cents (or paise, pence). Floats are rounded. Amounts are stored as sent with no currency conversion, so send one currency.
urlOptional. Must be on your registered domain, a subdomain, or an allowed host. UTM parameters in it are extracted and become the event's campaign.
referrerOptional. The external page that sent the visitor. Referrers on your own hostnames are dropped.
propertiesOptional flat object, at most 20 keys. Good for plan or billing interval; never for emails or names.

Errors come back as JSON with a code, which is what makes server-side tracking debuggable (the browser endpoint always answers 204):

StatusCodeTypical causeRetry?
400bad_inputInvalid event name, URL, properties or revenue; the message says whichNo, fix the payload
401unauthWrong write key or site IDNo
403host_not_allowedThe url is not on your site's domain or allowed hostsNo
413too_largeBody over 16 KBNo
429rate_limitedToo many requests; the response carries Retry-After: 1Yes, after a pause
500db_error or internalTemporary server problemYes, with backoff

How server-side events are attributed

This is the part most guides skip. A server-side event carries exactly the url and referrer you send, nothing more. Linqry doesn't look up the buyer's earlier browser visits to fill them in, because it can't: visitor IDs are daily hashes and your server's request doesn't come from the buyer's browser.

  • Send a landing URL with UTMs and the revenue is credited to that UTM source and its channel.
  • Send a referrer and it is credited to that referring site.
  • Send neither and the revenue is still counted in your totals, but under direct / (none).

Two more consequences follow. Visitors and buyers are counted from browser page views, so server events add revenue without inflating your visitor count. And details Linqry derives from the request itself (country, device, browser) describe your server's request, not the customer, so read revenue-by-country with that in mind when most revenue arrives server-side.

Store the landing URL and referrer at signup

To credit the right channel weeks later, capture the visitor's landing page and referrer when they first arrive, keep them until signup, and save them on the user record. One simple approach keeps them in sessionStorage until the signup form is submitted:

<script>
  // Remember the first page and referrer of this browsing session.
  try {
    if (!sessionStorage.getItem('first_touch')) {
      sessionStorage.setItem('first_touch', JSON.stringify({
        url: location.href,          // keeps ?utm_source=... intact
        referrer: document.referrer, // empty for direct visits
      }));
    }
  } catch (e) {}
</script>

<!-- On the signup form, copy it into hidden fields before submit -->
<input type="hidden" name="landing_url" id="landing_url">
<input type="hidden" name="landing_referrer" id="landing_referrer">
<script>
  try {
    var t = JSON.parse(sessionStorage.getItem('first_touch') || '{}');
    document.getElementById('landing_url').value = t.url || '';
    document.getElementById('landing_referrer').value = t.referrer || '';
  } catch (e) {}
</script>

If you'd rather not store anything, record the first payment from the browser on the confirmation page (window.linqry('purchase', { plan: 'pro' }, 4900)): that event inherits the visit's source automatically. Then send renewals from the backend and accept that they land under direct.

Example: a Stripe webhook handler

Stripe sends invoice.paid when an invoice is paid, which covers first payments and every renewal of a subscription. The invoice's amount_paid is an integer in the smallest currency unit, the same format Linqry expects. This Express handler verifies the signature, ignores duplicates, answers Stripe quickly and forwards the payment:

import express from 'express';
import Stripe from 'stripe';

const stripe = new Stripe(process.env.STRIPE_SECRET_KEY);
const app = express();

// Stripe needs the raw body to verify the signature.
app.post('/webhooks/stripe', express.raw({ type: 'application/json' }), async (req, res) => {
  let event;
  try {
    event = stripe.webhooks.constructEvent(
      req.body,
      req.headers['stripe-signature'],
      process.env.STRIPE_WEBHOOK_SECRET,
    );
  } catch (err) {
    return res.status(400).send('Invalid signature');
  }

  // Stripe may deliver the same event more than once: skip ones you've handled.
  if (await db.processedEvents.exists(event.id)) return res.sendStatus(200);

  if (event.type === 'invoice.paid' && event.data.object.amount_paid > 0) {
    // Answer Stripe first; do the forwarding in a background job.
    await jobs.enqueue('linqry-revenue', { stripeEventId: event.id, invoice: event.data.object });
  }
  await db.processedEvents.add(event.id);
  res.sendStatus(200);
});

The background job looks up the user, then posts to Linqry with the stored landing URL and referrer:

async function sendRevenueToLinqry({ invoice }) {
  const user = await db.users.findByStripeCustomer(invoice.customer); // your own lookup

  const res = await fetch('https://linqry.com/api/track', {
    method: 'POST',
    headers: {
      authorization: 'Bearer ' + process.env.LINQRY_WRITE_KEY,
      'content-type': 'application/json',
    },
    body: JSON.stringify({
      siteId: process.env.LINQRY_SITE_ID,
      event: 'invoice-paid',
      url: user?.landingUrl || undefined,      // e.g. https://example.com/?utm_source=newsletter
      referrer: user?.landingReferrer || undefined,
      properties: { plan: user?.plan ?? 'unknown', currency: invoice.currency },
      revenue: invoice.amount_paid,            // integer, smallest currency unit
    }),
  });

  if (res.status === 429 || res.status >= 500) {
    throw new Error('Linqry temporarily unavailable: ' + res.status); // let the job queue retry with backoff
  }
  if (!res.ok) {
    // 4xx other than 429: retrying won't help. Log it and move on.
    console.error('Linqry rejected revenue event', res.status, await res.text());
  }
}

The same shape works for other providers: pick the event that means 'money received' in their docs, read the amount in the smallest unit, and send it once.

Duplicates, retries and idempotency

Payment webhooks are delivered at least once, not exactly once. Stripe documents that an endpoint may receive the same event more than once, recommends logging processed event IDs, says event order isn't guaranteed, and retries failed deliveries for up to three days in live mode. Plan for that on both hops:

  1. Provider to you: record each provider event ID (like evt_...) and skip IDs you've seen, as the handler above does.
  2. You to Linqry: Linqry's API has no idempotency key, so each accepted request is stored as a new event. Retry only on 429 and 5xx, use exponential backoff, and give the request a generous timeout so you rarely retry a request that actually succeeded.
  3. Refunds: revenue can't be negative, and there is no per-event delete, so a refund isn't subtracted from Linqry's totals. If refunds matter to your reporting, track them as their own event (for example refund-issued with the amount as a property) and reconcile in your billing system.

The other endpoint: /api/revenue

Linqry also has POST /api/revenue, which records a revenue event with amount_cents and a three-letter currency. When you pass a Linqry visitor_id, it attaches the payment to that visitor's most recent event from the last 30 days, inheriting its source. Most backends don't know the daily visitor hash, so without it the call returns { "ok": true, "attributed": false } and the revenue lands under direct. If you have the landing URL, /api/track is the better fit. Details are in the revenue docs.

Check that it works

  1. Send a test event with curl

    Use the request above with a small amount and a landing URL carrying utm_source=test. A 200 {"ok":true} means it was stored; any error tells you exactly what to fix.

  2. Trigger a test payment

    In Stripe's test mode, pay a test invoice with one of Stripe's test cards, or use the Stripe CLI's stripe trigger command, to fire your webhook end to end.

  3. Look for the revenue in Linqry

    Revenue appears in the dashboard's revenue figure and channel breakdown, and on the Insights page by referrer, UTM source and country. See revenue attribution for what each view shows.

Frequently asked questions

Should I send revenue from the browser or the server?

From the server for anything you report on or reconcile, because it can't be faked and doesn't depend on the buyer's browser. A browser event on the confirmation page is simpler and inherits the visit's source automatically, so some teams send the first payment from the browser and renewals from the server. Don't send the same payment from both, or it counts twice.

Why does my server-side revenue show up as direct?

Because a server-side event carries only the url and referrer you send. Store the visitor's landing URL (with its UTM parameters) and referrer at signup and pass them with each revenue event, and the revenue is credited to that source.

What happens if my webhook retries and sends the same payment twice?

Linqry stores both, because its API has no idempotency key. De-duplicate on your side by recording the payment provider's event ID before forwarding, and only retry Linqry requests that failed with 429 or a 5xx error.

Which currency should I use?

Linqry stores amounts as sent and doesn't convert currencies, so pick one reporting currency. If you charge in several, convert to it before sending, or keep the original currency as a property for reference.

Sources

  1. Stripe Docs: Receive Stripe events in your webhook endpoint (signatures, retries, duplicates, ordering) (checked Nov 9, 2026)
  2. Stripe Docs: Using webhooks with subscriptions (invoice.paid) (checked Nov 9, 2026)
  3. Stripe API reference: The Invoice object (amount_paid) (checked Nov 9, 2026)

See your own funnels and revenue by channel

No card required · 30-day trial · No cookies