trackr

E-commerce

Orders, revenue, campaigns and codes in the portal, how an order finds its campaign, and what is kept after the raw events are deleted.

The portal counts a shop’s product views, carts, checkouts and orders, and shows which channels, campaigns and codes brought revenue. It keeps daily totals of them for as long as the site exists; the single events are deleted after the site’s retention (60 days by default), like the visits.

Sending events

POST /api/ecommerce/track, from the shop’s pages (the Origin must be a domain of the site) or from the shop’s server with Authorization: Bearer <forwarding secret>:

{
  "siteId": "…",
  "event_type": "purchase",
  "order_id": "1042",
  "revenue": 59.9,
  "currency": "EUR",
  "product_id": "mug-01",
  "product_name": "Mug",
  "product_category": "Kitchen",
  "product_price": 29.95,
  "quantity": 2,
  "coupon": "NOV10",
  "discount": 6,
  "ts": 1795670000000
}

event_type is product_view, add_to_cart, checkout or purchase. Send one purchase event per order, or one per line item with the same order_id; revenue is the sum of the events’ revenue. coupon is a campaign or promotion code (at most 64 characters). Do not send personal one-time codes: codes are kept in the daily totals without a time limit.

Which campaign an order belongs to

An order counts for the source of the visit it came from: the referrer and UTM parameters of the first page of the visitor’s latest session that day, the same source the channel groups of the visits use. To find the visit, the portal builds the same daily session hash as for the pageviews (from IP, User-Agent and the day’s salt) and looks up the session. Raw shop events keep that hash for the site’s retention period so the same session can enter a funnel. The daily funnel rollups store aggregate counts.

  • From the browser: works when the event comes from the browser that made the visit.
  • From the shop’s server: send the visitor’s client: { ip, ua } (as in forwarding mode), or the UTM parameters the shop kept for the order as utm: { source, medium, campaign }. The shop’s UTM parameters take precedence.
  • Not counted: a visit on one day and the order on another, or an order from a different device. The session hash changes every day and nothing is stored on the device, so such orders are listed as Unattributed. Channels and campaigns therefore always add up to the total revenue.

The attribution shows which sources orders came from, not that a campaign caused them.

Advertising costs

Enter what a campaign cost per day, and the report shows cost, roas (revenue ÷ cost) and cost_per_order next to its revenue. Admins only; costs are kept until the site is deleted.

POST /api/admin/sites/:id/costs (from the portal’s own pages, as every admin call) takes JSON { "rows": [{ "day": "2026-11-01", "source": "newsletter", "medium": "email", "campaign": "nov", "currency": "EUR", "cost": 12.5 }] } or CSV (Content-Type: text/csv) with the header day,source,medium,campaign,currency,cost (; works too), up to 400 rows a call. A row replaces the entry of the same day, campaign and currency. DELETE …/costs?from=2026-11-01&to=2026-11-30 removes days.

  • Matching: the UTM triple source, medium, campaign, compared in lower case. Newsletter and newsletter are one campaign. Leave medium and campaign empty for a campaign tagged with utm_source only.
  • Costs without orders (an untagged brand campaign, a day without a sale) appear as a campaign with revenue 0, so the spend adds up: costs.total is the sum of all entries.
  • Currency: only costs in the report currency count; other currencies are named in costs.other_currencies.
  • costs.roas is the revenue of the campaigns that have costs over their costs. Like the attribution, ROAS shows what orders came from a campaign’s visits, not what it caused.

Figures

Only sums and counts are stored per day; rates and averages are computed for the chosen period, so any period gives the same result whether its days come from single events or daily totals.

Figure Definition
Gross revenue Sum of revenue of purchase events, before refunds and returns
Orders Distinct order_id of purchase events (an event without one counts alone)
Average order Gross revenue ÷ orders
Conversion rate Orders ÷ sessions of the same source (all sessions for the total)
Abandoned carts Carts (distinct order_id added to a cart) minus orders whose order_id was added to a cart before
Discounts Sum of discount of purchase events

Rates over fewer than 30 sessions are shown pale: two orders out of five sessions are 40%, but say little.

Currencies: revenue is shown in the currency with the most revenue in the period. Orders in other currencies count as orders, but not in revenue; the dashboard names them.

Comparing periods: the dashboard compares a period with the previous one of the same length or with the same weeks a year before. Both are moved by whole weeks, so weekdays match. To judge a promotion, choose its days and compare with the previous period: the difference to that baseline is what the promotion added, not its whole revenue.

In the API: GET /api/ecommerce/:siteId?from=&to=&compare=previous (or year) adds comparison with the compared range and its figures.

Edit this page on GitHub