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 with real test purchases

The problem

The sales platform knows someone bought. RedTrack knows which ad the click came from. When the bridge between them fails, the ad manager optimizes on wrong data and nobody notices right away.

The sale arrives without the click

The sale webhook only carries the origin if the click id made it all the way to checkout. A free-text parameter, UTM or coupon in place of the click id attributes nothing.

The browser pixel loses purchases

Ad blockers, browser tracking protection or a tab closed before the pixel fires. If the purchase depends on the browser, part of it disappears.

Webhooks repeat and arrive out of order

The platform redelivers the same event when it gets no answer. Without protection, one sale becomes two conversions and the ad looks more profitable than it is.

Order bumps and upsells get mixed up

Each funnel step is its own transaction. If everything goes out as one purchase, or with the same key, bump and upsell revenue either vanishes or is counted as a new sale.

Refunds and chargebacks do not subtract themselves

RedTrack records a refund as a separate conversion and does not remove it from the original sale. Without your own math, the dashboard shows gross revenue as if it were net.

Renewals and new offers mislead

A subscription renewal is revenue, but not a new sale for the ad. An offer launched without a mapping arrives with no type and lands in the wrong place, or nowhere.

What this costs

  • Budget going to the wrong ad, because the conversion landed on another click or never arrived.
  • The Meta algorithm learning from purchases that are duplicated, missing or have no value.
  • Checkout numbers and tracker numbers that do not match, and scaling decisions made in the dark.

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 that is ready 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 before anything is sent.

    Hands overclassified event
  5. 5This projectRedTrack

    Server-to-server postback

    Conversion sent to RedTrack with value, type and transaction id. Timeout, network errors, 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 arrive as distinct purchases, one per transaction, without one erasing another in deduplication.

Mind map, step by step

The same flow as this page, from the ad click to the event on Meta, drawn as a mind map and explained one branch at a time.

The summary, narrated from start to finish

The path of a sale, from the click to Meta, in about 8 minutes: I read the summary map block by block, in the same order.

Narration in Portuguese. The file is only downloaded when you press play.

Access by code

Restricted-access mind map

The full map has restricted access. The video above shows the summary; to see every detail, get in touch.

What you see once unlocked

  • An in-order walkthrough, one step at a time, in Portuguese and English
  • From the ad click to the event on Meta, no step skipped
  • What happens when something fails, and what is still unproven
  • Zoom, full screen and navigation by section
Get in touch
13
sections
2
languages

Event model

Every event has a classification rule, a destination and a key against duplicates. What should not become a conversion is stored, but not sent.

Browser

  • InitiateCheckout

    Validated end to end

    Click on the page buy button, fired by the own script.

    RedTrack
    InitiateCheckoutOn the page click id
    Meta
    InitiateCheckoutStandard event
    Duplicate key
    click id + type, once per session
  • Video milestones

    Validated end to end

    Play and 1, 3, 5 and 10 minutes watched on the VSL.

    RedTrack
    One type per milestone
    Meta
    Not sent, on purpose: too granular a signal to optimize on
    Duplicate key
    click id + type, once per session

Sale

  • Purchase

    Validated end to end

    Approved purchase of an offer mapped as main product, on the first charge.

    RedTrack
    PurchaseValue and transaction id
    Meta
    PurchaseOne per transaction
    Duplicate key
    event id + transaction/event pair
  • Order bump

    Validated end to end

    By the offer code, not by the bump flag in the payload.

    RedTrack
    orderbumpIts own transaction
    Meta
    PurchaseA distinct purchase
    Duplicate key
    event id + transaction/event pair
  • Upsell

    Validated end to end

    By the offer code.

    RedTrack
    upsellIts own transaction
    Meta
    PurchaseA distinct purchase
    Duplicate key
    event id + transaction/event pair
  • Downsell

    No real transaction yet

    By the offer code.

    RedTrack
    downsellIts own transaction
    Meta
    Defined during setup
    Duplicate key
    event id + transaction/event pair

Reversal

  • Refund

    Refund event, for any offer. Does not depend on a mapping.

    RedTrack
    refundedNew conversion on the same click, with the original value
    Meta
    refundedCustom event
    Duplicate key
    event id + transaction/event pair
  • Chargeback

    No real transaction yet

    Chargeback event, for any offer.

    RedTrack
    chargebackNew conversion on the same click
    Meta
    chargebackCustom event
    Duplicate key
    event id + transaction/event pair

Stored, not sent

  • Renewal

    Approved purchase with a recurrence number above 1. For a subscription missing that number, it is fetched from the payments API.

    RedTrack
    Not sent
    Meta
    Not sent
    Duplicate key
    event id + transaction/event pair
  • Cancellation, delay, overdue

    Subscription lifecycle events.

    RedTrack
    Not sent
    Meta
    Not sent
    Duplicate key
    event id + transaction/event pair
  • Unknown offer

    Offer code with no mapping. Never becomes a purchase by default.

    RedTrack
    Stays in the panel until mapped; then preview and reprocess
    Meta
    Not sent
    Duplicate key
    event id + transaction/event pair
  • A valid click id has 24 hexadecimal characters. A text value in the origin parameter is kept as received, but never becomes attribution: the event is stored without being sent.
  • Conversion types and the hand-off to Meta follow the mapping configured in the RedTrack Conversions API integration. Every funnel is mapped with you, with no assumed default.

Architecture and failure paths

The happy path is the solid line. Dashed boxes show what happens when something goes wrong, and where each case shows up for the operator.

RedTrack Tracking Platform architecture diagramThe ad click goes through RedTrack, which creates the click id. The page reads the click id and the checkout carries it to the sale. The sale webhook reaches this project backend, which validates token and schema, redacts personal data, classifies the event, stores it idempotently and sends the postback to RedTrack, which forwards it to the Meta Conversions API. An invalid token or payload is rejected without storing. An offer without mapping is stored as unknown and not sent. A duplicated webhook gets a 200, is recorded separately and nothing is resent. With RedTrack down, the send is retried with growing waits and, if it still fails, the event is marked as failed for a resend. This shows up in the operator panel, together with reconciled finance; alerts live in the operations summary API.Capture · browser and platformsAdMeta Ads with RedTrackparameters in the URLRedTrack clicktracking domaincreates the click idPage + scriptreads the click id; sendsInitiateCheckout, videoCheckoutcheckout click idtravels to the salesale webhookThis project · serverWebhooktoken and Zod schema,personal data redactedInvalid inputwrong token or schema:401 or 400, nothingis storedClassificationmapped offer +recurrence = 11 typesUnmapped offerbecomes unknown,is stored andnot sentIdempotent writeevent id + uniquetransaction/event pairDuplicated webhookanswers 200, logs itapart, resends nothingS2S postbackclick id, value, typeand transaction idRedTrack downretry with backoff ontimeout, network, 429, 5xx;if it still fails: panelOperator panelRedTrack failures and exhausted retriesunmapped offers and reprocessingconflicts and offer historyreconciled financeenrichment with resendDestinationsRedTrackconversion on theright click, onceMeta CAPIthrough the RedTrackintegrationPurchase, bump and upsell:Purchase, one per transaction.Refund and chargeback:custom events.
Main pathFailure path

Retry in detail: by default up to 3 attempts per send, an 8 second timeout and a wait that doubles from 500 ms. Only timeouts or network errors, 429 and 5xx are retried. If the send fails, the webhook answers 502; when the checkout platform redelivers the same event, the send is redone on the same row, without duplicating.

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, delay, overdue and unknown. A renewal counts as revenue and is not sent as a new conversion.

A click id that is a click id

Only 24 hexadecimal characters count. The preferred parameter comes first, the other is the fallback, and free text is kept as received without becoming attribution.

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, renewals, refunds, chargebacks and net computed from events. A refund and a chargeback on the same transaction subtract only once. With incomplete history, net stays null instead of an invented zero.

Operations and observability

Health and readiness, duplicate and retry counters that survive restarts, and alerts for backlog, failure rate, old pending events and missing webhooks, exposed in the operations summary API. Additive, idempotent migrations.

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, and the checkout platform redelivery works as a second chance. 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.

Refund as a new conversion

A refund does not edit the original purchase: it goes in as another type on the same click. The history of a sale approved and then returned is preserved, and refund rate becomes its own metric.

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.

What the tests prove

Automated tests with Vitest, unit and HTTP integration, with no external network: an ephemeral database and a mocked RedTrack. Deploys run typecheck and the tests before the build and migrations.

  • 01

    Webhook, idempotency and classification

    A duplicate is never stored twice, approval and refund of one transaction are two rows, a renewal never reaches RedTrack, 5xx is retried and 4xx is not.

  • 02

    Offer mapping

    CRUD with expected version, audit, Postgres and SQLite drivers, a snapshot that refuses invalid rows and a boot that aborts if the database is unreachable.

  • 03

    Panel and authentication

    Rate-limited login, expired sessions, CSRF required on mutations, security headers and pages that never contain the token.

  • 04

    Recurrence enrichment

    Lookup only after the response, a merge that only fills blanks, conflicts without overwriting and sending blocked while recurrence is pending.

  • 05

    Finance and reconciliation

    Fixtures kept out of real finance and a reversal without the original sale leaving net null.

  • 06

    Unknown offer and reprocessing

    No mapping returns 409, reprocessing twice sends once, a sent event is never reinterpreted and the preview changes nothing.

  • 07

    Browser scripts

    A double click does not duplicate the send, each video milestone fires once and a failure or timeout still leads to checkout.

  • 08

    Infra and integrations

    Postgres transactions, a readiness check that answers 503 without leaking driver errors, and the suggestion model client.

Security, item by item

Webhook
Token compared in constant time. In production without a configured token, it answers 503 instead of accepting. Events outside the allowlist are ignored.
Personal data
Buyer name, email, phone, document and address are redacted before storage. Logs use a field allowlist and the panel never returns the payload.
Panel session
HttpOnly, SameSite cookie valid for 12 hours that never carries the admin token. A per-session CSRF token on every mutation.
Rate limit
60 requests per minute per IP on admin and 10 login attempts every 5 minutes. Without a token in production, the panel answers 503 and never opens.
Headers
CSP restricted to the same origin, no framing, nosniff, no-referrer and no-store on every admin response.
Public surface
An opaque 404 that does not echo the route, and a readiness check that does not expose error text. Secrets live only in environment variables.

Operator panel

Interface in HTML, CSS and ES modules served by the backend itself, no framework and no bundler. Five screens: overview, events, offers, unknown offers and enrichment. The screens below use synthetic data.

Overview: Integration health, reconciled finance and operational indicators.
Integration health, reconciled finance and operational indicators.

Setup in your funnel

I set up and maintain this platform for operations that run on RedTrack. The base is ready: the work is connecting your funnel, mapping your offers and validating with a test purchase before switching over.

How it works

  1. 1

    Call and review

    Page, VSL, checkout, offers, order bumps and upsells, traffic sources and whatever pixel and Conversions API setup already exists.

  2. 2

    Event map

    For every event in your funnel: whether it exists, whether it counts in finance, whether it goes to RedTrack and to Meta. Only with your confirmation or a real payload.

  3. 3

    Minimum access

    Invites in the official panels, always with the lowest permission needed. No password or token over chat.

  4. 4

    Setup with a way back

    Tracking domain, webhook, offers and the page script. DNS or webhook changes only with the exact record confirmed and the rollback defined beforehand.

  5. 5

    Test purchase

    A real test purchase goes through the whole funnel. It only goes live after every point below is checked.

  6. 6

    Maintenance

    Monitoring the panel and adjusting as the funnel changes.

What is delivered

  • Tracking domain and postback configured in RedTrack
  • Page script: click id, InitiateCheckout and video milestones, if there is a VSL
  • Checkout platform webhook connected and validated
  • Offers mapped: main product, order bump, upsell and downsell
  • RedTrack conversion types linked to Meta events
  • A test purchase tracked from the click to the event on Meta
  • Access to the panel with every event, delivery status and finance

What you provide

  • Access to the RedTrack account
  • Access to the product on the checkout platform, to configure the webhook
  • The Meta pixel or dataset already in use
  • One DNS record for the tracking domain
  • The list of offers in the funnel, with their codes
  • Who approves changes and who decides to roll back, if something goes wrong

What is checked in the test purchase

  1. 01The RedTrack click creates the click id and the page reads it
  2. 02InitiateCheckout and video milestones land on the page click
  3. 03The checkout click id reaches the sale origin
  4. 04The webhook is received, classified and stored exactly once
  5. 05RedTrack accepts the postback and the conversion shows on the right click
  6. 06Order bump and upsell show up as their own conversions
  7. 07The event shows up on Meta, in Events Manager
  8. 08The panel shows the sale as sent and the finance adds up

What maintenance covers

  • New products and offers mapped before traffic runs
  • Unknown offers reviewed and reprocessed with a preview
  • Delivery failures investigated and resent
  • Operational alerts followed up
  • Reconciliation when checkout and RedTrack numbers diverge
  • Adjustments when the page, checkout or campaign change

What is not included

  • Traffic management, campaign creation and budget decisions
  • Copy, design or editing of the page and VSL, beyond the tracking script
  • Any promise of campaign results, ROAS or sales volume
  • Another tracker in place of RedTrack
  • Checkouts without a ready integration: assessed separately, before agreeing
  • Subscriptions for RedTrack and the tools you already use

I currently maintain RedTrack tracking for one client in operation. The platform was validated end to end with real test purchases, and every new setup gets close follow-up. Pricing is discussed privately, after the review.

Talk about a setup

Frequently asked questions

What if the webhook arrives twice?

The second delivery gets a 200, is logged in a duplicates table and nothing is resent to RedTrack. The key is the event id plus the transaction and event type pair. The exception is on purpose: if the first send had failed, the redelivery redoes the send on the same row.

What if RedTrack is down?

Timeouts, network errors, 429 and 5xx errors are retried with growing waits. If it still fails, the event is stored as failed, shows up in the panel and can be resent manually by the operator, through an operations API endpoint. The checkout platform redelivery also redoes the send. Nothing is lost silently.

Does it only work with Hotmart?

Hotmart is the integration that is ready today. Classification, idempotency and delivery work on an internal event model, so another checkout platform comes in as a new webhook adapter. That is assessed case by case, before agreeing.

Do I need to change trackers?

No. The platform was built for RedTrack. Your account, campaigns and reports stay where they are; what changes is that sales start reaching it reliably.

Does a refund remove the sale from RedTrack?

It does not, and that is how RedTrack itself works: the refund comes in as another conversion on the same click, with the original value. Native ROAS stays gross. Net is computed in the panel, which subtracts refund and chargeback once per transaction.

Where does my data live?

In a Postgres database that belongs to the setup. The platform is not multi-tenant, so there is no database shared with other operations. Buyer name, email, phone, document and address are redacted before storage.

What is the risk of granting access?

Access is by invite in the official panels, with the lowest permission that works, and you can revoke it at any time. API credentials go straight into the server environment variables, never over chat. DNS changes only with the exact record and rollback agreed beforehand.

What do I need to provide?

Access to RedTrack and to the product on the checkout platform, the Meta pixel or dataset in use, one DNS record, the list of offers with their codes and the contact of whoever approves changes.

What does maintenance look like?

A new offer is mapped in the panel, with a change history. Unknown offers and failed sends show up in the panel and are handled one by one, with a preview before reprocessing. Alerts live in the operations summary API. When checkout and RedTrack diverge, reconciliation shows where.

How much does it cost?

It depends on the funnel: how many offers, whether there are subscriptions, a VSL, which checkout. Pricing is agreed privately, after the review.

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

  • The platform on this page runs in a lab: its first production setup is still to come
  • Downsell and chargeback are implemented but were never tested with a real transaction
  • Alerts exist in the operations summary API, not on the panel screens, and there is no active email or chat notification yet
  • Single instance: session, rate limit and snapshot live in memory
  • Checkout integration ready today: Hotmart
  • Private code, because it holds operational configuration

Stack

  • Node.js
  • TypeScript
  • Fastify
  • Zod
  • PostgreSQL
  • SQLite
  • Vitest
  • Render
  • RedTrack
  • Meta CAPI
  • Hotmart API

Running RedTrack and want attribution to add up?

Tell me what your funnel looks like. I will reply with what it takes to set it up and what stays out of scope.

Useful to include

  • Checkout platform
  • Traffic sources
  • Offers: main, bump, upsell, downsell
  • Whether there are subscriptions or a VSL

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