Affiliate attribution as code you can rerun
First-touch affiliate ownership with a 12-month-lapse override, written as tested code, replayed over every customer, and synced to labels and revenue nightly.
- Shopify
- Pipedrive
- n8n
- Custom
The problem
Who brought in a customer was recorded as a tag on the order. The same customer could carry two affiliate tags. Nobody could say who owned whom once a year had passed, and 7,870 affiliate attributions could not be resolved to anyone on the roster of 882.
What we built
The rule, written down: first touch owns the customer, unless that affiliate has lapsed for twelve months, in which case the next one does. We wrote it as a function with unit tests and replayed it over the full order history. Of 98,364 customers scanned, only 32 carried two or more affiliate tags, and the function settled every one the same way on every run. 7 of 7 tests pass, and 52 of 52 recent affiliate orders checked out.
Labels come from the same source. A tag-to-label sync runs nightly, gated by an allowlist built from the roster, so a typo in a tag cannot create a label. The first full pass wrote 770 labels with 0 errors, followed by 7 clean nightly runs. Unresolved affiliate attributions fell from 7,870 to 2,362.
Revenue lands on the record too. A nightly job joins the affiliate platform's order API to the CRM person and writes current-month and last-month net revenue and order counts for 853 affiliates, diff-only, so rerunning it changes nothing that has not changed.
No AI in this build. Here's why that was right: who owns a customer is a rule, not a judgment. A function that gives the same answer on every replay is the whole point.
First-touch ownership read from order tags with a 12-month-lapse override, written as a unit-tested function and replayed over the full order history. A tag-to-label sync gated by an allowlist built from the affiliate roster, run nightly and diff-only. A nightly rollup that joins the affiliate platform's order API to CRM person records and writes current and last-month net revenue and order counts, idempotently.
Outcome
Replayed over 98,364 customers: only 32 carried two or more affiliate tags, and the rule settled each one the same way. Verified on 52 of 52 recent affiliate orders, with 7 of 7 tests passing and 25 persons reconciled by hand at 0 errors.
Who this fits
- Brands paying affiliates or partners from a tag someone typed on an order
- RevOps teams whose attribution lives in a spreadsheet formula nobody can rerun
- Anyone who needs partner revenue on the CRM record without a monthly export