Credit the newest link until an account exists, then freeze it

Featurekamo-shared-library
Shipped
August 20, 2026 at 4:41 AM UTC
Author
Kamo
Commit
7334f30

Attribution was frozen at first touch, which gets the common case wrong: someone who follows member A's link in March and member B's in June, and only then signs up, was brought in by B. First-touch pays A for a visit that led nowhere and pays B nothing for the one that converted, and no downstream arithmetic can repair an attribution that is simply wrong. So credit now follows the newest link the visitor arrives on — for exactly as long as they are anonymous. Once an account exists it stops moving, permanently. That half matters just as much: the sponsoring member has earned it, and if a later link could still move credit then any member could take another's customer by getting them to click once, while org-created and became-paid — which land weeks after the signup — would drift to whoever was most recently clicked rather than whoever actually brought the customer in. reattributeWhileAnonymous carries the whole rule in one conditional UPDATE (different code AND signedUpAt IS NULL AND userId IS NULL), so there is no read-then-write window for two beacons, or a beacon and the signup itself, to race through. The `<>` on the code id keeps it to real moves, which lets the caller treat a return of 1 as "credit actually changed hands" and record it. markSignedUpAttributedTo settles the account and the credit in a single statement, closing the one window the ingest path cannot: the beacon is deferred to idle, so a visitor who follows a second member's link and goes straight to the register form can sign up before any beacon reports that visit. The counters stay safe because the freeze and the first conversion are the same moment — by the time any *_AT column can be stamped, attribution is already fixed for the life of the visitor. Traffic is untouched either way: visits and page requests belong to the code that served them. EVENT_TYPE gains ATTRIBUTION_MOVED so a member whose visitor moved to someone else's link can see exactly when it happened, rather than inferring it from a code id that quietly differs.

All changes

Like what you see shipping?

Every one of these updates lands in your workspace automatically. Start free and watch it grow week after week.

Start Free ForeverView Pricing