Lead Intelligence Agent¶
The Lead Intelligence Agent delivers actionable insights for SDRs & AEs to close leads with better efficiency. It aggregates visitor behavior, conversation history, and intent signals into a comprehensive intelligence report.
Status¶
Beta - Available via n8n integration
Overview¶
The Lead Intelligence Agent provides detailed insights about individual visitors who have engaged with your website. It helps sales teams understand:
- What pages the visitor explored
- How engaged they were (session duration, page views)
- What topics they discussed with the Website Agent
- Their position in the conversion funnel
- Their calculated intent score
Data Access¶
Supabase RPC Function¶
The agent retrieves data via the get_visitor_for_lead_intelligence RPC function.
Parameters¶
| Parameter | Type | Required | Description |
|---|---|---|---|
p_site_domain |
TEXT | Yes | Your site domain (e.g., "demo.userose.ai") |
p_person_id |
TEXT | Yes | PostHog person_id (visitor identifier) |
Example Call¶
n8n Integration¶
Prerequisites¶
- n8n service account configured and connected — see n8n Service Account Setup
Getting the Person ID¶
The person_id is the PostHog identifier for the visitor. You can obtain it from:
- PostHog webhook: When a visitor triggers an event, PostHog sends the
distinct_id(same asperson_id) - Rose webhook: Configure a webhook in Rose to receive visitor events with the
person_id - Supabase query: Query the
visitorstable to find visitors by email or other criteria
Step-by-Step Workflow Setup¶
Option 1: Triggered by PostHog Event (Recommended)¶
- Add Webhook node as trigger
- Copy the webhook URL and add it to PostHog as a destination
-
Configure PostHog to send events like
lead_qualifiedordemo_booked -
Add Postgres node
- Credential: Select your
n8n_servicePostgres credential - Operation: Execute Query
-
Query:
-
Add output node (Slack, Email, CRM, etc.)
- Use the response fields to craft your message
Option 2: Scheduled Batch Processing¶
- Schedule Trigger: Run daily/hourly
- Postgres node: Query visitors table for recent high-intent visitors
- Loop: Iterate through each visitor
- Postgres node: Call
get_visitor_for_lead_intelligencefor each
Postgres Node Configuration¶
-- n8n Postgres node query
SELECT * FROM get_visitor_for_lead_intelligence(
'{{ $json.site_domain }}',
'{{ $json.person_id }}'
);
Example: Slack Notification for High-Intent Leads¶
Complete workflow that sends a Slack message when a visitor has intent score ≥ 4:
Slack message template:
🔥 High-Intent Lead Alert
*Email:* {{ $json.email || 'Anonymous' }}
*Intent Score:* {{ $json.intent_score }}/5
*Funnel Stage:* {{ $json.funnel_stage || 'Browsing' }}
*Sessions:* {{ $json.total_sessions }}
*Time on Site:* {{ Math.round($json.total_session_duration_seconds / 60) }} minutes
*Topics Discussed:*
{{ $json.topics.join(', ') }}
*Pages Visited:*
{{ $json.pages_visited.map(p => '• ' + p.title).join('\n') }}
Response Fields¶
| Field | Type | Description |
|---|---|---|
visitor_id |
UUID | Unique visitor identifier |
email |
TEXT | Visitor's email (if captured) |
pages_visited |
JSONB | Array of pages with URL and title (see below) |
total_page_views |
BIGINT | Total number of page views |
total_session_duration_seconds |
BIGINT | Total time spent on site (seconds) |
total_sessions |
BIGINT | Number of separate browsing sessions |
funnel_stage |
TEXT | Current conversion stage (see below) |
conversations |
JSONB | Full conversation transcripts (see below) |
topics |
TEXT[] | Topics discussed across all conversations |
keywords |
TEXT[] | Keywords extracted from conversations |
last_activity_at |
TIMESTAMPTZ | Most recent activity timestamp |
total_messages |
BIGINT | Total message count across conversations |
intent_score |
INTEGER | Calculated intent (1-5 scale) |
Funnel Stages¶
| Stage | Description | Trigger |
|---|---|---|
Conversion completed |
Visitor booked a demo | demo_booked = true |
Conversion initiated |
Visitor clicked CTA | cta_clicked = true |
Conversion offered |
Demo was proposed to visitor | demo_proposed = true |
null |
Not yet in conversion funnel | No conversion signals |
Intent Score¶
The intent score (1-5) is calculated using:
- 60% Behavior signals: Based on funnel progression
- 5 = Demo booked
- 4 = CTA clicked
- 3 = Demo proposed
- 2 = 2+ message turns
-
1 = Anonymous/minimal engagement
-
40% Interest signals: Based on conversation engagement (lifetime_interest_score)
Pages Visited JSONB Structure¶
[
{
"url": "/pricing",
"title": "Pricing - Rose AI"
},
{
"url": "/features/chatbot",
"title": "AI Chatbot Features"
}
]
Conversations JSONB Structure¶
[
{
"id": "conversation-uuid",
"started_at": "2024-01-15T10:30:00Z",
"topics": ["pricing", "enterprise"],
"keywords": ["API", "integration"],
"messages": [
{
"role": "user",
"content": "What's your enterprise pricing?",
"created_at": "2024-01-15T10:30:00Z"
},
{
"role": "assistant",
"content": "Our enterprise plans start at...",
"created_at": "2024-01-15T10:30:05Z"
}
]
}
]
Security¶
Webhook Authentication Required
If your n8n workflow is triggered by a webhook, you MUST add authentication to prevent unauthorized access. Without authentication, anyone who discovers your webhook URL can trigger the workflow and access your data.
Options:
- Header Auth: Require a secret token in
Authorizationheader - Query Param Auth: Require a secret in the URL (less secure)
- IP Allowlist: Restrict to known IPs (e.g., PostHog servers)
Read-Only Access¶
The RPC functions are read-only (STABLE in PostgreSQL terms). They cannot modify any data.
Tenant Isolation¶
The p_site_domain parameter ensures data isolation:
- Each call is scoped to a specific site domain
- Users can only access data for sites they own
- No cross-tenant data access is possible
Service Account & Role Configuration¶
See n8n Service Account Setup for complete setup instructions including role creation, connection details, SSL, IPv4 configuration, and troubleshooting.
Use Cases¶
- Pre-call research: Review visitor's conversation history before a sales call
- Lead prioritization: Use intent score to prioritize outreach
- Personalized follow-up: Reference specific topics and questions in outreach
- Handoff notes: Provide context when passing leads between team members
Related¶
- Website Agent - The agent that captures visitor conversations
- Outreach Agent - Uses this data for personalized outreach
- Data Sources Reference - Technical data architecture