You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With the org-level connection (#577) and per-brand property mapping (#642) in place, the system can start pulling real search demand. This issue covers the data pull only: fetching Search Console query stats for every mapped brand on the daily cycle and storing them. Feeding prompt suggestions and search-vs-AI insights are separate follow-ups on top of this table.
Scope
1. Storage
New table gsc_query_stats: brand_id, query, date, clicks, impressions, ctr, position, unique on (brand_id, query, date). RLS: org members read; the sync (service role) writes.
Numbered migration + types/supabase.ts sync.
2. Sync (server)
lib/gsc-sync.js — for each active brand with a non-null gsc_property whose org connection is connected:
Execute GOOGLE_SEARCH_CONSOLE_SEARCH_ANALYTICS_QUERY through Composio with deterministic parameters (no LLM): site_url = the brand's mapped property, last 28 days, dimensions: ['query', 'date'], search_type: 'web', row_limit: 5000, data_state: 'final', pinned toolkit version.
Upsert rows on (brand_id, query, date) in chunks; per-brand failures are logged and skipped, never abort the whole run.
Hooked into the existing daily cycle (runDailyTracking) as a non-blocking follow-up step — both the cloud internal endpoint and the self-hosted cron get it for free.
Skips cleanly when Composio env is absent (self-host default).
3. Manual trigger
POST /api/integrations/google-search-console/sync (admin/manager) — runs the sync for the caller's org immediately and returns per-brand row counts, for testing and first-time backfill.
Out of scope
Prompt-suggestion generation from these queries.
Search-vs-AI comparison surfaces.
Retention/pruning policy (can come with the first consumer).
Acceptance
After a sync, gsc_query_stats holds up to 28 days of per-query daily rows for every mapped brand; re-running is idempotent (upserts, no duplicates).
A brand without a mapped property, a disconnected org, or a self-host without Composio env is skipped without errors.
The manual endpoint returns row counts and the daily cycle triggers the same sync automatically.
Activity
feat: GSC property mapping and daily query-stats sync (#647)