Reporting Conversions from Your Server

Learn how to report purchases and other conversions from your backend with the SDK's track() or POST /sdk/events, using the Server-side tracking method.

2 min read


By default a website's conversions come from the browser, through pertentoReportConversion or an analytics integration such as GA4. With the tracking method set to Server-side, they come only from your backend instead, through the SDK's track() or the HTTP endpoint POST /sdk/events.

One reporter per website

A website has exactly one reporter, so nothing is counted twice:

  • With Server-side, the browser snippet reports nothing, and pertentoReportConversion does nothing on that website.
  • With any other tracking method, the backend endpoint refuses conversions with status 409, and track() answers with the error wrong-tracking-method.

Set it under Websites, in the website's settings. Switch it when your backend is ready to report, since conversions from the browser stop as soon as it changes.

Reporting a conversion

const result = await pertento.track('purchase', {
  keys: ['new-checkout'],
  visitorId,
  attributes: { plan: user.plan },
  data: { revenue: 49.99, currency: 'EUR' },
});
if (!result.ok) console.warn(result.error.kind, result.error.message);

Revenue and currency in data are read the same way as for any other conversion. See Posting conversion events via the Tracking API for the field names and how amounts are parsed.

The rules

  • `keys` is required. List the flag keys you decided this person on, 1 to 50 of them. Pertento decides those keys again for the ID you send and credits the conversion only to the experiments the person is enrolled in, so a conversion never counts in an experiment they were never shown. Missing or invalid keys mean nothing is sent.
  • Send the same ID and attributes as the decision. A different visitor ID is a different person, and different attributes can fail a rule and drop the experiment from the conversion.
  • Only for visitors the browser has counted. A conversion counts against the visitors who loaded a page carrying the seed. Reporting one for someone who never did adds a conversion with no visitor behind it and skews the result.
  • At most once. track() makes one attempt with a 2 second timeout and never retries, because a retried purchase that had in fact arrived would be counted twice. Do not add a retry of your own. A timed-out conversion may or may not have been recorded.
  • It never throws. Check result.ok, or read pertento.lastError.

Without the SDK

POST /sdk/events takes the same thing over HTTP, with 1 to 20 events per request. See The server-side HTTP API.