Own project · Tracking and attribution

RedTrack Tracking Platform.

Middleware that connects the checkout, RedTrack and Meta. Every sale becomes a conversion attributed to the right click, exactly once, even with duplicated or out-of-order webhooks or a destination that is down.

LAB environment running 24/7 · flow validated end to end with real test purchases

automated tests passing
319
API endpoints
24
event classifications
11
screens in the operator panel
5
01

The problem

The sales platform knows someone bought. The tracker knows which ad the click came from. Without a reliable bridge between them, campaign optimization runs on wrong data.

The sale arrives without the click

The sale webhook only carries the origin if the click id was taken all the way to checkout. Free-text parameters get mixed with real ids.

Webhooks repeat and arrive out of order

Redeliveries and refunds before approval happen. Counting twice or losing an event distorts revenue and attribution.

Not every charge is a new conversion

A subscription renewal is revenue, but not a new sale for the ad. Order bump, upsell, refund and chargeback each need their own handling.

02

How the flow works

From the ad click to the conversion event on Meta. Each color is a platform; steps marked "This project" are own code.

RedTrackCheckoutMetaThis project
  1. 1RedTrack

    Ad click

    The RedTrack tracking domain records the click and generates a 24-character click id.

    Hands overclick id in the URL
  2. 2This projectRedTrack

    Capture in the browser

    Own script reads the click id (query and cookies), fires InitiateCheckout and video milestones (play, 1, 3, 5 and 10 min) with deduplication. A network failure never blocks the checkout.

    Hands overevents + checkout click id
  3. 3Checkout

    Checkout with origin

    The click id travels in the checkout platform origin parameters up to the purchase. Hotmart is the integration in use today.

    Hands oversale webhook with the click id
  4. 4This project

    Webhook: validate, classify, store

    Token compared in constant time, schema validated with Zod, personal data redacted, event classified and stored idempotently. The response is sent before any external call.

    Hands overclassified event
  5. 5This projectRedTrack

    Server-to-server postback

    Conversion sent to RedTrack with value, type and transaction id. Timeout, 429 and 5xx go to retry with exponential backoff. 4xx errors are not retried.

    Hands overconversion attributed to the click
  6. 6RedTrackMeta

    Conversions API

    RedTrack forwards the event to Meta. Purchase, order bump and upsell go out as distinct events, with the transaction id as the deduplication key.

03

What was built

Real idempotency

Event id as primary key and a unique transaction + event pair. Duplicates go to their own table. Redelivery of a failed event retries the send without creating a new row.

Financial event classification

Purchase, order bump, upsell, downsell, renewal, refund, chargeback, cancellation, overdue and unknown. A renewal counts as revenue and is not sent as a new conversion.

Enrichment after the ACK

When recurrence data is missing, the backend queries the platform payments API after answering the webhook. The merge only fills empty fields, divergence becomes a conflict for review.

Offer mapping in the database

CRUD with optimistic locking, an append-only audit trail and an in-memory snapshot that fails closed on boot. Rollback by feature flag, no destructive migration.

Never reinterpret silently

An event already sent is never resent or reclassified automatically. A mapping change after the send becomes a visible conflict in the panel, with a preview before reprocessing.

Reconciled finance

Gross, refunds, chargebacks and net computed from events. When history is incomplete, net stays null instead of an invented zero.

Security

Session with HttpOnly cookie and CSRF token, rate limit on login and admin, strict CSP, opaque 404 and a panel that stays closed in production without a token. Responses and logs carry no personal data.

Operations and observability

Health and readiness, duplicate and retry counters, alerts for backlog, failure rate and missing webhooks. Additive, idempotent migrations and deploys gated by tests.

04

Operator panel

Interface in HTML, CSS and ES modules served by the backend itself, no framework and no bundler. The screens below use synthetic data.

Overview — Integration health, reconciled finance and operational indicators.
Integration health, reconciled finance and operational indicators.
05

Decisions and trade-offs

One source of truth per subject

The checkout platform is the financial truth, the database is the operational truth, RedTrack owns attribution and Meta only optimization.

No queue and no Redis

The volume does not justify it. Retry and enrichment run in the same process, on a single instance. The limit of this choice is documented.

Two click ids, on purpose

The page click receives engagement events. The checkout click receives the purchase. Keeping them apart avoids attributing a sale to the wrong event.

Meta stays behind RedTrack

The backend does not call the Conversions API directly. A single delivery path lowers the risk of duplicated events on Meta.

AI as advice only

The panel can ask a model for a mapping suggestion for an unknown offer. The suggestion never writes anything. Delivery stays deterministic.

06

Current state, no polish

Validated

  • Real test purchase, order bump and upsell, from click to the event on Meta
  • Idempotency, postback retry and reprocessing of unmapped offers
  • Video milestones and InitiateCheckout with browser-side deduplication
  • Three parallel campaigns with no attribution cross-contamination
  • 24/7 infrastructure on Postgres, deploys gated by typecheck and tests

Not yet

  • No client in production: this is a lab environment
  • Downsell is implemented but was never tested with a real transaction
  • Single instance: session, rate limit and snapshot live in memory
  • Private code, because it holds operational configuration

Stack

Node.jsTypeScriptFastifyZodPostgreSQLSQLiteVitestRenderRedTrackMeta CAPIHotmart API

Want to see the code or talk about the project?

The repository is private. I can walk through the architecture and the code in a call.

Get in touch

Independent project. Not affiliated with or endorsed by RedTrack, Hotmart or Meta. Names and trademarks belong to their owners.