DEV Community

yulingg zhang
yulingg zhang

Posted on Fully Autonomous

Keep useful referral attribution without saving raw referrer URLs

A small web tool usually needs to answer a modest question: which sources lead to useful actions? Keeping every incoming URL is not necessary to answer it. A fixed source category can connect a landing to copying a prompt or opening a generator without retaining query strings from another site.

I maintain RetroPrompt, and this article describes a narrow implementation recently added to that project. It was prepared with AI assistance. It is an implementation note, not evidence that a particular source converts better.

Classify at the browser boundary

Start with a short list of sources you actually use. For example, recognize an exact search-engine hostname and a few publishing platforms; put other external hosts in an other_referral bucket. A missing referrer belongs in direct_unknown, because an app or privacy setting may have removed it.

Avoid substring matching. A hostname containing a familiar brand is not necessarily that service. Parse the URL, compare the hostname with an explicit list, and send only the resulting label. Keep raw referrer URLs and arbitrary UTM strings out of the event payload and browser storage.

Known UTM source tags can help when a publishing platform removes referrer information. They are still user-controlled inputs. Allowlist the tags and any campaign names separately, and validate them again on the server. Attribution labels are useful bookkeeping, not proof of authenticity or causation.

Keep the label across the journey

Classifying every page independently turns an external visitor into an internal referral as soon as they follow a link. Instead, attach the entry label to a random, short-lived tab-session identifier and reuse it for later actions in that tab.

In this implementation, the tab session expires after 30 minutes of inactivity. This does not measure a unique person or long-term retention. Two tabs can produce separate sessions; a copied tab can also behave differently from a fresh navigation. Document those limits before comparing the number with another analytics product's Visits metric.

Give the new schema a boundary

When attribution is added to an existing event table, old events have unknown historical sources. Assign them a legacy schema version instead of inventing a source. Start a fresh measured session when the browser upgrades, and keep old cached clients compatible with the receiving endpoint.

The source-to-action report can then filter for the new schema and exclude QA sessions. Count distinct sessions per action. Copying a prompt and generating an image are parallel tasks, so do not force both into one mandatory sequence.

Test the misleading cases

Test an external landing followed by internal navigation; an unknown campaign string; a hostname that merely resembles an allowed one; an expired tab session; and an opt-out followed by re-enabling measurement. Also test that your own QA traffic stays excluded after navigation.

The useful outcome is a report with understandable uncertainty. Missing attribution should remain visible, and failed telemetry must not stop someone from using the tool.

The associated project is RetroPrompt's portrait workflow. I maintain the linked site; it currently creates still portraits, not video templates.

Top comments (0)