๐Ÿ—บ๏ธ MortgageCo Schema โ€” Source of Truth

Live from DB ยท loadingโ€ฆ
๐Ÿ”€ Flow ๐Ÿ”— Tracking Flow ๐Ÿ‘ฅ Affiliates ๐Ÿ“ˆ Leads Flow ๐ŸŽฏ Offers Tree ๐Ÿ“Š Buyer Reports ๐Ÿ’ฐ Revenue ๐Ÿ›’ Extras / TY Offers ๐Ÿš€ Inbound Links ๐Ÿ“Š Ad Perf ๐Ÿ“ง Email ๐Ÿ“ฑ SMS ๐Ÿค– Autopilot ๐Ÿ—๏ธ Blueprint (Rebuild) ๐Ÿ—„๏ธ Migrations
flowchart TD A[Loading...]

๐Ÿ”— How Tracking Works (Parent โ†’ Child โ†’ Buyer Postback)

Single brand: MortgageCo. Single parent offer: hefty.offers.id=32. Eleven children (ids 12-22) โ€” one per buyer/network we resell leads to. Every Meta/Google/Email click lands on go.mortgageco.com/?aff=8&oid=32&... โ€” parent oid=32 is routed to a child offer before being stored, so the parent never owns clicks directly.

1. Click ingest

Real user lands on the canonical tracking link:

https://go.mortgageco.com/?aff=8&oid=32&s1={{campaign.id}}&s2={{adset.id}}&s3={{ad.id}}&fbclid={{fbclid}}

Nginx on slaives proxies the click to the click-ingest service on port 3033. Service inserts a row into hefty.clicks (partner_id=8, offer_id=<routed child>). App layer routes parent 32 โ†’ child via pickRoutedOfferIdOrDefault(), walking hefty.offer_hierarchy. DB trigger trg_clicks_block_parent_offer enforces this at the DB layer.

2. Funnel + lead submit

User completes the multi-step funnel on go.mortgageco.com. Final POST hits https://hefty.cc/api/leads/ingest with click_id, PII (email/phone/first/last/state/zip), and Meta tracking params. Heftycc creates the hefty.leads row with click_row_id FK to the click, inheriting partner_id. PR #25 + #27 ensure body-level aff/utm_source/fbclid/numeric s1 override the organic fallback so attribution is correct even when the referrer is stripped.

3. Buyer distribution (sold path)

distributeLead() iterates hefty.buyers by priority. Each buyer's delivery_url is POSTed with the lead payload. First buyer to accept (HTTP 200 + parsed accept response) marks the lead status='sold'. Buyers in multi_sell_eligible mode also receive the lead. Each acceptance writes to hefty.lead_distributions:

lead_id, buyer_id, accepted=true, price=<negotiated>, http_status, response_time_ms

Each buyer's child offer assignment (buyer โ†” child offers.id 12-22) lives in hefty.buyers.offer_id OR hefty.partner_buyer_routing. The buyer's accepted price = gross revenue in the dashboard (lead_distributions.price).

4. Buyer postback (revenue confirmation)

When a buyer's downstream funnel converts, they fire a GET to:

https://hefty.cc/api/postback?click_id=...&offer_id=...&payout=...&transaction_id=...&status=approved

The /api/postback handler:

  1. Resolves the click via click_id (hex UUID from the original click).
  2. Resolves the child offer via offer_id (12โ€“22).
  3. Inserts hefty.offer_conversions (click_id, offer_id, payout, status='approved', transaction_id).
  4. Logs to hefty.postback_logs.

Postback payout = net revenue (what the buyer actually paid per their postback rules). Some buyers post back per-acceptance (immediate), some per-final-funded (delayed).

5. Outbound partner postback (third-party affiliates)

If the lead was sourced from an external affiliate (partners.postback_url IS NOT NULL), Heftycc fires a GET to that URL on sold-lead with {transaction_id} + {amount} placeholders substituted. Affiliates self-manage this URL via their portal at /partner โ†’ Postback Setup tab.

6. Revenue rollup

All revenue accrues to MortgageCo (parent 32) by aggregating across children:

SELECT
  (SELECT COUNT(*) FROM hefty.clicks
     WHERE offer_id IN (12,13,14,15,16,17,18,19,20,21,22)
       AND created_at::date = CURRENT_DATE) AS routed_clicks_today,
  (SELECT COUNT(*) FROM hefty.leads
     WHERE data->>'brand' = 'mortgageco'
       AND created_at::date = CURRENT_DATE) AS leads_today,
  (SELECT SUM(price::numeric) FROM hefty.lead_distributions
     WHERE accepted = true AND lead_id IN (
       SELECT id FROM hefty.leads
        WHERE data->>'brand' = 'mortgageco'
          AND created_at::date = CURRENT_DATE
     )) AS gross_revenue_today,
  (SELECT SUM(payout::numeric) FROM hefty.offer_conversions
     WHERE offer_id IN (12,13,14,15,16,17,18,19,20,21,22)
       AND status = 'approved'
       AND created_at::date = CURRENT_DATE) AS net_postback_revenue_today;

Today's snapshot (2026-04-19, captured at write-time, Pacific day):

7. Why two revenue numbers?

Quick reference โ€” partner ID map

aff=PartnerDB nameSource of clicks
8Metafb-mortgagecoFacebook + Instagram ads (primary)
11Google โ€” Try West Capitalgoogle-westcapGoogle Ads (THE ONLY Google account)
15Google in-house DEPRECATEDgoogle-mortgagecoHistorical only (retired 2026-04-19 โ€” click-ingest aliases aff=15 โ†’ partner_id=11)
4Omnisend Emailomnisend-emailEmail campaigns
12Omnisend SMSomnisend-smsOmnisend SMS sends
10SimpleTexting DECOMMISSIONEDsimpletexting-decommissionedHistorical only (retired 2026-04-19, row kept for attribution)
13MobileDripsmobiledripsNon-Verizon SMS
14Tells.cotells-coPush notifications
5OrganicorganicAnything untagged (fallback)

Quick reference โ€” child offers (buyers)

offer_idBuyer / NetworkDefault payoutModel
12AHS Warranty$15.00CPL
13ADT Security$15.00CPL
14Andersen Windows$15.00CPL
15Walk-in Tub$15.00CPL
16Quicken Loans$25.00CPA
17NAF New American Funding$25.00CPA
18Allied Move Quote$15.00CPL
19Car Insurance Masters$15.00CPL
20Lending Tree Home Equity$25.00CPA
21NerdWallet Debt ReliefRevShareRevShare
22Vivint Home Security$15.00CPL

Admin dashboard view: https://hefty.cc/dashboard โ€” shows Parent Offer hero card with rolled-up metrics + Child Offers (Buyers) table per this flow.

Affiliates (inbound traffic)

Loadingโ€ฆ

Offers Tree

Loadingโ€ฆ
Loading...
Loading...

๐Ÿš€ Inbound Affiliate Links

Loadingโ€ฆ
Loadingโ€ฆ
Loadingโ€ฆ
Loadingโ€ฆ
Loading...
Loadingโ€ฆ