Phase 4: Email Intelligence

Transforming email data into sales velocity — value delivered for JuxtMedia Sales Agent

From: Jonathan Gatlit, Chief Architect Date: March 11, 2026 For: Adam Howard, Sales Manager
All Features Deployed

What Phase 4 Delivered

Six features across 4 PRs + 1 hotfix — surfacing Gmail email activity data throughout the entire dashboard, transforming it from a daily briefing-only feature into a real-time sales velocity tool.

6
Features Shipped
4+1
PRs + Hotfix
51
Active Leads
44
Emails Ingested

Before vs. After Phase 4

Capability Before After
Lead Prioritization Sort by score (static, never changes) Sort by last activity (dynamic, real-time)
Email Visibility Morning briefing only (daily) Real-time on every lead + contacts view
Engagement Indicators None Color-coded badges on leads + contacts
Email Context Switch to Gmail manually Full email bodies with threaded history on lead detail page
Contact Overview Per-lead only, no cross-lead view Standalone cross-lead contacts view
Pipeline Automation Manual stage changes only Inbound email triggers stage suggestions
Briefing Accuracy Missed early-stage email matches All active stages tracked correctly

Pipeline Visibility — Last Activity Dashboard

The Leads table now surfaces real-time engagement signals. The most active leads automatically appear first, with email count badges showing engagement volume at a glance.

What Changed

"Imported" column → "Last Activity" — Computed from the most recent timestamp across email activity, stage changes, research completions, and lead updates using SQL GREATEST() aggregation.

Email Count Badges — Green (1-5 emails), amber (6+ emails), hidden (0 emails). Visible next to every company name.

Default Sort — Changed from score DESC to last_activity DESC. Most active leads surface automatically.

Last Activity Computation Pipeline

Conversation Context — Lead Detail Email History

Full email conversation history right on the lead page. No more switching to Gmail to review relationship context before outreach.

What Changed

Email Activity Section — Collapsible section between Contacts and Research Findings on every lead detail page.

Full Email Bodies — Complete plain-text email content with per-email "Show full email" / "Show less" expand/collapse. Full subject lines displayed without truncation.

Thread Grouping — Emails grouped by thread_id, threads sorted newest-first, emails within threads sorted oldest-first (conversation order).

Direction Badges — Blue "Outbound" with arrow-right, purple "Inbound" with arrow-left.

State Persistence — Expand/collapse preference saved to localStorage, survives page refreshes.

Hotfix (Issue #19) — Gmail API initially fetched metadata-only (200-char snippets). Upgraded to full message fetch with recursive MIME body extraction. Backfilled 40/44 existing emails with complete content.

Email Thread Retrieval Flow

Contact Intelligence — Cross-Lead Contacts View

A unified view of all contacts across all leads with email traffic volume indicators. See who's actively communicating and who's gone quiet — without drilling into individual leads.

What Changed

New /contacts Route — Standalone contacts table accessible from main navigation (between Leads and Briefing).

4-Tier Traffic Badges — Gray "—" (0 emails), blue (1-5), purple (6-15), green (16+). Counts both inbound and outbound.

Enrichment Status — Unlock icon for enriched contacts (with photos), lock icon for unenriched. Sort by traffic or enrichment.

Contact Email Traffic Aggregation

Workflow Automation — Stage Suggestions

When a queued or researched lead starts engaging via email, the system automatically detects it and suggests advancing them in the pipeline. No more manual monitoring.

What Changed

Inbound Email Detection — Hourly Celery task scans leads in queued/researched stages for inbound email activity.

Stage Suggestion Component — Appears at the top of Lead Detail page with suggested stage, reason text, and Accept/Dismiss buttons.

Accept Flow — Updates lead stage to "contacted", sets next_contact_date based on stage cadence, logs full stage history with changed_by="system_suggestion".

Conservative Logic — Only triggers for early-stage leads with inbound (not outbound) emails. Suggests, never auto-advances.

Stage Suggestion Workflow

Briefing Accuracy — Tracked Deals Fix

The morning briefing now correctly categorizes all known-lead emails, regardless of pipeline stage.

The Problem

The briefing's tracked_deals section only included leads in contacted or qualified stages. Leads in queued or researched stages with matched emails showed as "untracked" — even though they ARE tracked leads in the system.

Production Impact: 7 emails matched to 3 leads, but tracked_deals showed 0. All matched leads were in early stages.

The Fix

Single-line change: broadened the stage filter from ['contacted', 'qualified'] to ['queued', 'researched', 'contacted', 'qualified']. Only closed leads are now excluded.

Impact on Sales Velocity

Phase 4 directly impacts three of the four variables in the sales velocity equation.

Sales Velocity = (# Opportunities × Win Rate × Deal Size) ÷ Sales Cycle Length
Numerator
# Opportunities ↑
Stage Suggestions surface leads ready to advance.
Contact Intelligence reveals warm contacts across leads.
Numerator
Win Rate ↑
Email History provides full conversation context.
Traffic Badges guide outreach targeting by engagement.
Denominator
Cycle Length ↓
Last Activity Sort ensures hot leads get attention first.
Overdue Detection flags stale follow-ups immediately.
Phase 4 Sales Velocity Impact Model

Phase 5: Response Time Analytics

With email direction, timestamps, and thread data now fully surfaced, Phase 5 transforms email visibility into a coaching and optimization tool.

Target Capabilities Deferred — Q2 2026

Average Response Time — Per-lead and overall response time to inbound emails

"Going Cold" Detection — Inbound emails with no outbound follow-up within 48 hours

Cadence Consistency — Regularity scoring of outbound follow-up patterns

Sales Velocity Metrics — Time from first email to stage progression

Activation Requirements

Prerequisite Status Target
Phase 4 features stable Deployed March 11 1-2 weeks usage
Email data accumulation 44 emails ingested 100+ emails (2-4 weeks)
Configuration feedback Pending Adam's usage Badge thresholds, sort preference
Phase 5 Readiness Timeline