AI Search — Current Implementation
Leadmetrics already has a substantial SEO and analytics foundation that AI Search visibility features can build directly on top of.
Connected Channels (SEO / Analytics)
Google Search Console
- Provider:
packages/providers/google/src/google-search-console.ts - OAuth route:
GET /google-search-console/connect,/callback,/page/select - API methods:
getStats()(clicks/impressions/CTR/avg position by date),getKeywordStats()(top 10k queries),getStatsByKeyword()(per-keyword daily trend),getPageStats(),getSearchFilter() - Dashboard UI:
apps/dashboard/src/app/(dashboard)/channels/[id]/GoogleSearchConsoleChannelDetail.tsx- Stat cards: clicks, impressions, CTR, average position (current vs prior period with delta %)
- Daily performance line chart
- Top keywords table with position column
- Date range picker + AI Insights tab
- API route:
GET /tenant/v1/channels/:id/analytics— serves all GSC data
Google Analytics (GA4)
- Provider:
packages/providers/google/src/google-analytics.ts - API methods:
getOrganicTrafficMetrics(),getOverviewMetrics(),getDailyMetrics(),getTrafficSources(),getTopPages(),getOrganicStats(),getCountryStats(),getAudienceInsights() - Dashboard UI:
apps/dashboard/src/app/(dashboard)/channels/[id]/GoogleAnalyticsChannelDetail.tsx- Sessions, users, pageviews, bounce rate, engagement stat cards
- Daily performance chart
- Traffic sources breakdown, top pages, organic traffic tab, country/city tabs
- AI Insights tab
Bing Webmaster Tools
- Provider:
packages/providers/microsoft(BingWebmasterService) - API methods: Query stats — clicks, impressions, CTR, position by keyword
- Dashboard UI:
apps/dashboard/src/app/(dashboard)/channels/[id]/BingWebmasterToolsChannelDetail.tsx- Stat cards: clicks, impressions, CTR, position
- Top keywords table
- OAuth route:
GET /bing-webmaster/connect,/callback,/page/select
AI Agent Workers (SEO)
| Agent | Queue | What it Produces | Plan |
|---|---|---|---|
| Keyword Researcher | agent__keyword-researcher | Keyword clusters: branded, core, informational, local, competitor gap, long-tail — priority table as Markdown | Free |
| Content Brief Writer | agent__content-brief-writer | Structured SEO briefs — target KW, H2/H3 outline, CTAs, internal link suggestions — fed into Blog Writer | Free |
| Site Auditor | agent__site-auditor | Technical SEO audit: crawlability, Core Web Vitals signals, metadata, schema, broken links — prioritised report | Pro |
| Backlink Researcher | agent__backlink-researcher | 20–30 backlink prospects (directories, guest posts, competitor gap sources, citations) ranked by difficulty/impact | Pro |
| Backlink Outreach Writer | agent__backlink-outreach-writer | Personalised outreach emails for individual backlink prospects | Pro |
| Topic Researcher | agent__topic-researcher | 10–15 trending content topics, grouped by theme, priority-flagged. Uses Gemma 3:4B (local Ollama) | Agency |
All workers are in packages/agents/src/workers/ and use the shared createContentWorker pipeline (BullMQ + Claude, system prompts seeded in DB).
AI Insight Workers (Analytics)
| Worker | Queue | What it Produces |
|---|---|---|
| GSC Insights | agent__gsc-insights | GSC data → Claude → SWOT JSON: strengths, weaknesses, opportunities, recommendations, narrative summary |
| GA Insights | agent__ga-insights | GA4 data → Claude → traffic trend analysis, channel mix health, high-bounce pages, organic SEO growth signal, device split |
Both workers are in packages/agents/src/workers/insights/.
On-Page SEO
The blog post detail page (apps/dashboard/src/app/(dashboard)/blog/[id]/BlogPostDetail.tsx) includes a live SEO score widget:
- Keyword in title check
- Meta description present + length check
- Word count check
- Slug check
- Rendered as a donut chart with per-item breakdown
Target keywords are displayed as tags on each blog post.
Strategy Integration
The deliverable planner includes keyword_cluster and content_brief in its deliverable catalogue, both available on the Free plan. Claude will proactively recommend and schedule these when generating a monthly marketing plan.
AI Search Visibility (Phase 1 — Live, April 2026)
DB Models
Added to packages/db/prisma/schema.prisma:
Competitor— per-tenant structured competitor list (name, domain, isActive, notes)AIVisibilityPlatform— global platform registry seeded with chatgpt/gemini/perplexity/claude; managed by superadminTenantAIVisibilityPlatform— per-tenant platform on/off toggleAIVisibilityPrompt— monitored prompts per tenant (prompt text, intent, category, isActive)AIVisibilitySnapshot— per-prompt per-platform result (isMentioned, sentiment, rawExcerpt, citedSources[], competitors[])GSCKeywordSnapshot— daily keyword position snapshots for GSC (keyword, position, clicks, impressions, CTR, snapshotDate)
BullMQ Workers
| Worker | Queue | What it Does |
|---|---|---|
| AI Visibility Seeder | agent__ai-visibility-seeder | Reads ClientContext, uses Claude to generate initial AIVisibilityPrompt records + structured Competitor rows. Triggered after context pipeline completes. |
| AI Visibility Monitor | agent__ai-visibility-monitor | Sends all active prompts to ChatGPT / Gemini / Perplexity / Claude nightly (02:00 UTC). Stores AIVisibilitySnapshot rows. Enqueues Brand Narrative Analyst on completion. |
| Brand Narrative Analyst | agent__brand-narrative-analyst | Reads all rawExcerpt snapshots for the tenant, calls Claude to extract sentiment, attributes, citedTopics, missingTopics. Stores result on AIVisibilityNarrative. |
| GSC Keyword Snapshot | jobs__gsc-keywords-snapshot | Nightly (03:00 UTC). Fetches top 100 GSC keywords for each tenant with an active GSC channel. Upserts GSCKeywordSnapshot rows. |
Workers live in packages/agents/src/workers/ (seeder + monitor) and packages/agents/src/workers/insights/ (brand-narrative) and packages/agents/src/workers/jobs/ (gsc-keywords-snapshot).
API Routes
apps/api/src/routers/ai-visibility.ts — registered at /tenant/v1/ai-visibility in both app.ts and index.ts.
| Method | Path | What it Does |
|---|---|---|
GET | /prompts | List tenant’s monitored prompts |
POST | /prompts | Add a new prompt |
PATCH | /prompts/:id | Toggle active, edit text/category/intent |
DELETE | /prompts/:id | Delete prompt + cascade snapshots |
GET | /snapshots | Latest snapshot per prompt per platform |
GET | /snapshots/history | Historical snapshots for trend charts |
POST | /run | Trigger on-demand visibility check |
POST | /seed | Trigger seeder worker for this tenant |
GET | /platforms | List platforms with tenant’s enabled state |
PATCH | /platforms/:platformId | Toggle platform on/off for tenant |
apps/api/src/routers/competitors.ts — registered at /tenant/v1/competitors.
| Method | Path | What it Does |
|---|---|---|
GET | / | List all competitors (active + inactive) |
POST | / | Add a competitor manually |
PATCH | /:id | Edit name / domain / isActive / notes |
DELETE | /:id | Remove competitor |
Dashboard Pages
/settings/competitors— list competitors, add/edit/delete. Available to DMs and clients./ai-search— overview page with per-platform score cards, prompt results table, “Run Now” trigger. (Phase 1 — in progress)
Env Vars Added
GOOGLE_GENERATIVE_AI_KEY= # direct Gemini API (separate from GSC/GA4 OAuth)
PERPLEXITY_API_KEY= # Perplexity API
ANTHROPIC_API_KEY= # already existed; now also used by monitor workerKnown Gaps in Current Implementation
| Gap | Status | Notes |
|---|---|---|
| No keyword position history stored | ✅ Fixed April 2026 | GSCKeywordSnapshot model + nightly gsc-keywords-snapshot job built |
| No rank change alerts | Pending | Alert notification triggers not yet wired into the snapshot job |
| No dedicated SEO dashboard page | Partial | /seo/keywords, /seo/keyword-groups, /seo/link-building exist; no unified /seo overview |
| Backlink and topic agents have no dedicated UI | Partial | /seo/link-building exists; topic agent has no page |
| No AI search visibility tracking | ✅ Fixed April 2026 | Phase 1 complete — monitor worker + seeder + dashboard built |
| No structured competitor model | ✅ Fixed April 2026 | Competitor DB model + API + /settings/competitors page |
| No competitor gap analysis | Pending | Phase 2 — queries and dashboard page not yet built |
| GSC channel detail position history chart | Pending | Phase 3 — GSCKeywordSnapshot data exists; chart UI not yet added |