Skip to content

feat(marketing): transparent lead scoring (backlog #14) - #314

Merged
NewWorldVenture merged 1 commit into
mainfrom
claude/loving-mccarthy-e1ahq8
Jul 12, 2026
Merged

NewWorldVenture merged 1 commit into
mainfrom
claude/loving-mccarthy-e1ahq8

Conversation

@NewWorldVenture

Copy link
Copy Markdown
Owner

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-scoring lead-score.ts.
  • lib/marketing/contact-score-compute.ts: gathers the signals per contact (mkt_visitors sessions/recency, mkt_touchpoints conversions, mkt_consent_events, demo_email_uses, crm_contact_profile) and upserts; recomputeContactScore / recomputeAllContactScores.
  • 0172_crm_lead_scores.sql: persisted score + band + factors jsonb ledger, indexed by score desc; admin/service-role only (RLS on, no public policy).
  • Admin /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, in SEED_ALL.sql.

Verification

  • tsc 0 · eslint 0 · npm run build green (/admin/marketing/lead-scores builds) · full vitest 2440 passed (7 new).
  • PG16-verified: migration idempotent ×2; RLS enabled + score desc index; seed 500 idempotent ×2; a ledger-sums-to-score integrity check = 0 mismatches.

Deploy note

⚠️ Apply 0172_crm_lead_scores.sql with 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

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
@vercel

vercel Bot commented Jul 12, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
familyos Building Building Preview, Comment Jul 12, 2026 7:46pm

Request Review

@NewWorldVenture
NewWorldVenture marked this pull request as ready for review July 12, 2026 19:46
@NewWorldVenture
NewWorldVenture merged commit 6294e8e into main Jul 12, 2026
1 of 4 checks passed

This branch was successfully deployed

1 active deployment
Preview — 7a921ced Deployed Jul 12, 2026 by vercel[bot]
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.

2 participants