Skip to Content
ChannelsAi SearchAI Search — Current Implementation

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)

AgentQueueWhat it ProducesPlan
Keyword Researcheragent__keyword-researcherKeyword clusters: branded, core, informational, local, competitor gap, long-tail — priority table as MarkdownFree
Content Brief Writeragent__content-brief-writerStructured SEO briefs — target KW, H2/H3 outline, CTAs, internal link suggestions — fed into Blog WriterFree
Site Auditoragent__site-auditorTechnical SEO audit: crawlability, Core Web Vitals signals, metadata, schema, broken links — prioritised reportPro
Backlink Researcheragent__backlink-researcher20–30 backlink prospects (directories, guest posts, competitor gap sources, citations) ranked by difficulty/impactPro
Backlink Outreach Writeragent__backlink-outreach-writerPersonalised outreach emails for individual backlink prospectsPro
Topic Researcheragent__topic-researcher10–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)

WorkerQueueWhat it Produces
GSC Insightsagent__gsc-insightsGSC data → Claude → SWOT JSON: strengths, weaknesses, opportunities, recommendations, narrative summary
GA Insightsagent__ga-insightsGA4 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 superadmin
  • TenantAIVisibilityPlatform — per-tenant platform on/off toggle
  • AIVisibilityPrompt — 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

WorkerQueueWhat it Does
AI Visibility Seederagent__ai-visibility-seederReads ClientContext, uses Claude to generate initial AIVisibilityPrompt records + structured Competitor rows. Triggered after context pipeline completes.
AI Visibility Monitoragent__ai-visibility-monitorSends all active prompts to ChatGPT / Gemini / Perplexity / Claude nightly (02:00 UTC). Stores AIVisibilitySnapshot rows. Enqueues Brand Narrative Analyst on completion.
Brand Narrative Analystagent__brand-narrative-analystReads all rawExcerpt snapshots for the tenant, calls Claude to extract sentiment, attributes, citedTopics, missingTopics. Stores result on AIVisibilityNarrative.
GSC Keyword Snapshotjobs__gsc-keywords-snapshotNightly (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.

MethodPathWhat it Does
GET/promptsList tenant’s monitored prompts
POST/promptsAdd a new prompt
PATCH/prompts/:idToggle active, edit text/category/intent
DELETE/prompts/:idDelete prompt + cascade snapshots
GET/snapshotsLatest snapshot per prompt per platform
GET/snapshots/historyHistorical snapshots for trend charts
POST/runTrigger on-demand visibility check
POST/seedTrigger seeder worker for this tenant
GET/platformsList platforms with tenant’s enabled state
PATCH/platforms/:platformIdToggle platform on/off for tenant

apps/api/src/routers/competitors.ts — registered at /tenant/v1/competitors.

MethodPathWhat it Does
GET/List all competitors (active + inactive)
POST/Add a competitor manually
PATCH/:idEdit name / domain / isActive / notes
DELETE/:idRemove 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 worker

Known Gaps in Current Implementation

GapStatusNotes
No keyword position history stored✅ Fixed April 2026GSCKeywordSnapshot model + nightly gsc-keywords-snapshot job built
No rank change alertsPendingAlert notification triggers not yet wired into the snapshot job
No dedicated SEO dashboard pagePartial/seo/keywords, /seo/keyword-groups, /seo/link-building exist; no unified /seo overview
Backlink and topic agents have no dedicated UIPartial/seo/link-building exists; topic agent has no page
No AI search visibility tracking✅ Fixed April 2026Phase 1 complete — monitor worker + seeder + dashboard built
No structured competitor model✅ Fixed April 2026Competitor DB model + API + /settings/competitors page
No competitor gap analysisPendingPhase 2 — queries and dashboard page not yet built
GSC channel detail position history chartPendingPhase 3 — GSCKeywordSnapshot data exists; chart UI not yet added

© 2026 Leadmetrics — Internal use only