Skip to content

feat(auth): add first-touch signup attribution - #764

Merged
unjica merged 4 commits into
developfrom
feat/signup-attribution
Oct 11, 2026
Merged

unjica merged 4 commits into
developfrom
feat/signup-attribution

Conversation

@unjica

@unjica unjica commented Oct 10, 2026

Copy link
Copy Markdown
Collaborator

New signups currently have no marketing acquisition data. This change remembers the first landing and saves UTM tags and an external referrer hostname with each new user.

  • Adds nullable User.utm_source, utm_medium, utm_campaign, utm_content, utm_term (100 characters) and referrer_host (253 characters), with no defaults or historical backfill.
  • Captures in the marketing/dashboard root layout, then forwards through the registration form and server action. Both email/password self-serve and invite registration persist inside user creation. No OAuth signup exists in this repository. Existing users are never updated.
  • Restricts UTM values to trimmed ASCII letters/digits/spaces/underscore/dot/hyphen and truncates them. Referrers become lowercase HTTP(S) hostnames only; paths, queries, credentials and ports are discarded. telemetry-tracker.com and all its subdomains are ignored. Missing, malformed, direct and consent-declined values are NULL. Optional malformed payloads do not block signup.

Consent and first-touch behavior:

The existing GA component loads only after accepted cookie consent. Although this is first-party data, acquisition measurement is optional analytics, so this implementation follows the stricter interpretation. The initial landing remains in component memory until accepted consent; only then is a 60-day SameSite=Lax cookie written (Secure on HTTPS). It is scoped to telemetry-tracker.com and its subdomains on the canonical deployment, and host-only elsewhere. Existing attribution, including an all-null direct landing, is not overwritten or refreshed. Rejection deletes the cookie and disables forwarding. The server action independently checks its authoritative consent cookie. The GA integration is unchanged.

Before consent, a full reload or another origin loses the memory-only landing. Consent remains host-specific under the existing consent system, so signup on another subdomain requires accepted consent there. Cookie expiry/deletion or another browser starts another observable first touch. The public API treats attribution as untrusted client input; direct API clients must obtain consent themselves. No new personal fields or full referring URLs are stored.

Affiliate behavior is unchanged: ref/via capture remains last-touch, retains its existing sessionStorage and optional consented cookie behavior, and is handled independently. Browser regression tests cover campaign forwarding alongside affiliate codes; the opt-in DB affiliate test now asserts both records are persisted.

Validation:

  • pnpm install --frozen-lockfile, pnpm lint, and the full pnpm test pass: 1,426 tests passed, 128 opt-in DB tests skipped.
  • API: 1,051 passed / 128 skipped; dashboard: 235 passed; core: 67; Vite plugin: 14; Node SDK: 27; Next SDK: 15; publish guards: 17.
  • pnpm --filter api build and pnpm --filter dashboard build pass.
  • Standalone tsc --noEmit retains exactly the baseline failures: 106 API test-file diagnostics and six dashboard test-file diagnostics. Compared against an archive of origin/develop with the same installed dependencies: no new diagnostics. No checks were weakened.
  • Prisma schema validates; Prisma migration diff produces the same six nullable columns as the migration.
  • Local PostgreSQL initialization was blocked by sandbox shared-memory permissions, so migration application and DB affiliate integration could not run. API route tests use mocked Prisma and cover self-serve/invite creation, malformed data and existing-user protection.
  • Full diff reviewed against origin/develop; git diff --check passes.

Daily signup aggregation (Prisma timestamps are stored in UTC; NULL includes direct, missing and consent-declined traffic):

SELECT created_at::date AS signup_day,
       utm_source, utm_campaign, count(*) AS signups
FROM "User"
GROUP BY 1, 2, 3
ORDER BY 1 DESC, 4 DESC;

Implementation details and limitations: docs/SIGNUP-ATTRIBUTION.md. No merge, deployment, publication or production data access was performed.

unjica and others added 4 commits October 10, 2026 21:43
Capture initial UTM tags and external referrer hostname after cookie consent.
Preserve attribution through self-serve and invite registration with nullable
User columns and a migration that leaves existing accounts unattributed.

Sanitize optional payloads without blocking signup, preserve affiliate behavior,
and document consent, direct traffic, retention, and aggregation semantics.
@unjica
unjica merged commit 6ac2d41 into develop Oct 11, 2026
7 checks passed
@unjica unjica mentioned this pull request Oct 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant