Skip to content

Unify GSC analytics response contract and status-driven consumers#429

Open
AJaySi wants to merge 1 commit intomainfrom
codex/define-consistent-response-contract-for-get_search_analytics-ren1d4
Open

Unify GSC analytics response contract and status-driven consumers#429
AJaySi wants to merge 1 commit intomainfrom
codex/define-consistent-response-contract-for-get_search_analytics-ren1d4

Conversation

@AJaySi
Copy link
Owner

@AJaySi AJaySi commented Mar 12, 2026

Motivation

  • Ensure get_search_analytics always returns a single, predictable shape so downstream code can rely on keys rather than presence checks.
  • Replace ad-hoc early returns (auth failure, not connected, no data, verification/API errors, exceptions) with structured responses that include a status marker and empty collections.
  • Normalize cached/legacy payloads so previously cached responses conform to the new contract.
  • Simplify and harden consumers (handler, scheduler, onboarding normalizers) to use status + guaranteed keys instead of brittle key-existence logic.

Description

  • Added helper builders inside GSCService.get_search_analytics: _base_payload(status, error) and _normalize_payload(payload) that guarantee the unified contract with keys: overall_metrics.rows, query_data.rows, page_data.rows, query_page_data.rows, verification_data.rows, date_range (start/end), site_url, startDate/endDate/siteUrl aliases, status, and optional error/warning.
  • Refactored all early-return branches in get_search_analytics to return the canonical payload with appropriate status values (examples: not_connected, auth_failed, no_data, verification_failed, api_error, partial_success, success, error) and empty arrays instead of ad-hoc dict shapes.
  • Normalized successful and partial-success responses to include canonical date_range, site_url, and status and ensure cached responses are converted via _normalize_payload before being returned.
  • Updated consumers to rely on status and guaranteed keys: backend/services/analytics/handlers/gsc_handler.py now derives metrics from overall_metrics/query_data and computes connection status from status; backend/services/scheduler/executors/gsc_insights_executor.py checks status rather than presence of 'error'; onboarding normalizer normalize_gsc_analytics gates processing based on status.

Testing

  • Ran python -m compileall backend/services/gsc_service.py backend/services/analytics/handlers/gsc_handler.py backend/services/scheduler/executors/gsc_insights_executor.py backend/api/content_planning/services/content_strategy/autofill/normalizers/analytics_normalizer.py and all modified modules compiled without syntax errors.
  • No automated unit tests were added or modified as part of this change.

Codex Task

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant