Repository navigation
feat(marketing): transparent lead scoring (backlog #14) - #314
Merged
Merged
Conversation
The visitor-intelligence signals existed but there was no visible score. This
scores every CRM contact 0-100 with a fully itemized ledger — every point is
an attributable, named factor, never a black box.
- lib/marketing/contact-score.ts: pure scorer (site engagement, recency,
conversions, demo, marketing/analytics consent, profile depth, lifecycle) →
{ score, band, factors[] }, capped at 100, banded cold/warm/hot/qualified.
7 tests. Named distinctly from the existing ticket scoreLead.
- lib/marketing/contact-score-compute.ts: gathers the signals per contact
(mkt_visitors, mkt_touchpoints conversions, mkt_consent_events, demo_email_uses,
crm_contact_profile) and upserts; recompute one / all.
- 0172_crm_lead_scores: persisted score + band + factors ledger, indexed by
score; admin/service-role only (RLS on, no public policy).
- Admin /admin/marketing/lead-scores (super-admin): ranked contacts, band chips,
band stat tiles, expandable "why" ledger, and a Recompute action. Added to the
marketing sub-nav.
- seed_crm_lead_scores.sql: 500 rows across all four bands with ledgers that sum
exactly to the score, in SEED_ALL.sql.
PG16-verified: migration idempotent x2, RLS + index, seed 500 x2, ledger sums
to score (0 mismatches). tsc/eslint/build green; full suite 2440 passing.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VJBpzPzPrBbMzYFSVCQaTM
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
NewWorldVenture
marked this pull request as ready for review
July 12, 2026 19:46
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
Backlog #14 — Lead scoring, transparent score ledger (Agent, ★★☆☆☆). The status was "signals exist; no visible score." This scores every CRM contact 0–100 with a fully itemized ledger — every point is an attributable, named factor, never a black box — completing the visitor-intelligence lane (it consumes the spine from #4, the identity link from #6, and the profile from #13).
Changes
lib/marketing/contact-score.ts(pure, 7 tests):scoreContact(signals)→{ score, band, factors[] }from site engagement, recency, conversions, demo, marketing/analytics consent, profile completeness, and lifecycle. Capped at 100; banded cold / warm / hot / qualified. Named distinctly from the existing ticket-scoringlead-score.ts.lib/marketing/contact-score-compute.ts: gathers the signals per contact (mkt_visitorssessions/recency,mkt_touchpointsconversions,mkt_consent_events,demo_email_uses,crm_contact_profile) and upserts;recomputeContactScore/recomputeAllContactScores.0172_crm_lead_scores.sql: persistedscore+band+factorsjsonb ledger, indexed byscore desc; admin/service-role only (RLS on, no public policy)./admin/marketing/lead-scores(super-admin): ranked contacts, band stat tiles, band chips, an expandable "why" ledger per contact (each factor + its points, summing to the score), and a Recompute action. Added to the marketing sub-nav under Audience & Intelligence.seed_crm_lead_scores.sql: 500 rows across all four bands, ledgers that sum exactly to the score, inSEED_ALL.sql.Verification
tsc0 ·eslint0 ·npm run buildgreen (/admin/marketing/lead-scoresbuilds) · fullvitest2440 passed (7 new).score descindex; seed 500 idempotent ×2; a ledger-sums-to-score integrity check = 0 mismatches.Deploy note
0172_crm_lead_scores.sqlwith this deploy (additive + idempotent). Safe before apply: the admin page shows an empty state until the table exists.🤖 Generated with Claude Code
Generated by Claude Code