A lead source attributor on AWS for a few dollars a month
Somebody asks which of the marketing spend is working. The answer that comes back is a pie chart, and the pie chart is wrong in a specific way: it shows a hundred per cent of enquiries divided between sources, when in reality a large share came from somewhere nobody can see. This post walks through a small system that answers the question and shows its working.

Key takeaways
- Capture the whole path, not one label. The rule is applied at report time, not at capture.
- Stitching repeat visits is where most of the accuracy comes from.
- State the credit rule on the report itself. Last click is fine; hiding it is not.
- The unattributable share is a headline number, not a footnote.
- Designed on AWS for about $2 a month.
The whole system on one page
Before any code, here is the shape of what we are designing.
- Compute
- Networking
- Analytics
- Front-end & mobile
- People
The one decision that matters
Most attribution setups collapse the path to a single source at the moment the enquiry arrives: a source column on the lead record, filled from whatever the last referrer was. It is simple, it is what every CRM does by default, and it destroys information irreversibly. Once the column says “google”, nobody can ever ask what happened before that.
Storing the path instead — every touch, in order, with timestamps — costs almost nothing and means the credit rule becomes a reporting choice. The same quarter can be reported last-click and first-click side by side, which is far more informative than either alone, and is impossible if the data was flattened at capture.
What runs (the inside)
- Capture. Records each arrival with its referrer, campaign parameters and landing page. Part 2 covers what is captured and what genuinely cannot be.
- Stitch. Links visits from the same person across sessions and devices, which is where most of the real accuracy lives. Part 3.
- Credit and report. Applies a named rule and publishes the result with its unattributable share in the headline. Parts 4 and 5.
One enquiry, end to end
- Compute
- Analytics
- Front-end & mobile
In plain words
Somebody hears the business mentioned on a podcast. There is no link and no tracking; they search the name and land on the site. Nine days later they come back by typing the address directly. Two days after that a retargeting ad catches them, they click it, and they fill in the enquiry form.
Under last click, the retargeting ad gets the credit, and the ad platform will report it confidently. Under first click, organic search gets it. The podcast, which is the actual reason any of this happened, appears nowhere under any rule, because it left no trace at all.
What this system does is store all four touches, report the last-click and first-click views next to each other, and put a line at the top saying that thirty-eight per cent of the quarter’s enquiries had no identifiable first source. That last line is the most honest thing on the page, and it is the one every commercial tool leaves off.
Design rules that shaped every decision
- Store the path. Never collapse it to one source at capture time.
- The credit rule is named on every report. “Last click” printed at the top, always.
- The unattributable share is a headline number, next to the totals.
- Stitching is best-effort and its confidence is recorded with it.
- Never build a cross-site profile. This links a person to their own visits, nothing more.
- A source that cannot be measured is not a source that does not work.
Why this shape
Attribution has an unusual failure mode: the output is always plausible. A pie chart of sources looks the same whether it was built from complete data or from the forty per cent that happened to be traceable, and nobody looking at it can tell which. Budgets get moved on the strength of it.
So the design is built around making the uncertainty impossible to lose. The path is kept so rules can be compared, the rule is named so the number has a definition, and the unknown share sits in the headline so it cannot quietly become zero.
The next four posts walk through each piece: how a touch is captured, how visits get stitched, how credit is assigned, and what the report actually says. One diagram per post, a cost breakdown, and an engineering reference at the end.
All posts