StarModel invitation
← Back to skills
extension
Category: Data & AnalyticsAPI key required

GSC-GA-Data-Get

Fetch Google Search Console AND Google Analytics (GA4) data and export blog SEO/performance reports to Excel. Use when the user asks to 爬取/查询 GSC、Search Console 或 GA4/Google Analytics 数据、博客 SEO 数据盘点,or sends a Google OAuth credential JSON (client_secret*.json) to hook up GSC/GA4. Handles setup automatically — installs the credential file, configures the environment (auto-installs uv and Python deps), runs OAuth, configures GA4 without gcloud — so the user's only manual steps are creating the credential and clicking Allow. Works in any agent (WorkBuddy, Codex, plain shell) through a single CLI, no MCP client required.

personAuthor: user_365cf723hubcommunity

GSC Data Get

Fetch Google Search Console data for any verified property and export formatted Excel reports (e.g. blog EN/CN comparison tables). Fully agent-agnostic: every capability is exposed as a plain CLI (scripts/gsc.py), so it runs the same in WorkBuddy, Codex, or a bare terminal — no MCP client needed.

Core promise: the user only creates a Google OAuth credential and clicks "Allow" in the browser. Everything else — uv/Python dependency auto-install, renaming/replacing the file, wiring the environment, authorizing, verifying, even GA4 setup — is automated. On a fresh machine just run bootstrap and confirm the browser prompts.

Read AGENTS.md for the agent-agnostic command reference, and references/gotchas.md before producing any report (anchor variants, cn-page detection, CTR anomaly checks).

Step 1 — User hands over a credential JSON

The user sends client_secret_xxx.apps.googleusercontent.com.json (any name). Run one command:

python <skill_dir>/scripts/gsc.py bootstrap "<path-to-json>"            # GSC only
python <skill_dir>/scripts/gsc.py bootstrap "<path-to-json>" --with-ga4 # GSC + GA4

That single command: auto-installs uv if missing → creates the work dir → installs the proxy launcher → writes the host MCP config (only when a WorkBuddy host is present) → validates and installs the credential as client_secrets.json (auto-backup of any previous file) → triggers browser OAuth → prints the visible properties → with --with-ga4: GA4 authorization (one more "Allow" click) → property auto-selection (or prints a pick list) → merges the ga4Server config.

Success marker: [login] OK — authorized, N properties visible; with --with-ga4 also GA4 就绪(属性 <ID>) or a property pick list (exit 10).

Variants:

  • JSON pasted as text → gsc.py import-secrets --text '<json>' then gsc.py login
  • Credential already installed on this machine → just gsc.py login
  • User has no credential yet → give them references/manual-guide.md (the only manual part: Google Cloud Console → enable Search Console API → create a 桌面应用 / Desktop app OAuth client → download JSON)

Reject web-type clients with guidance: the OAuth flow only works with desktop clients. Service-account JSON is accepted, but the service account email must be added as a user on each GSC property.

Step 2 — Fetch data

python <skill_dir>/scripts/gsc.py doctor     # optional: env + proxy diagnosis
python <skill_dir>/scripts/gsc.py sites      # exact site_url strings + permission
python <skill_dir>/scripts/gsc.py pages \
  --site https://example.com/ --start 2025-07-10 --end 2026-10-31 \
  --prefix en/blog/ --out pages.json
  • pages returns de-anchored URLs merged across #fragment variants (impressions/clicks summed, position impression-weighted) — never reimplement this naively.
  • --prefix without a leading slash (en/blog/): Git Bash rewrites leading-slash args into install paths and silently returns 0 rows.
  • Default range for "总数据/全历史": earliest GSC-allowed date → today; always state the actual range in the report.
  • Other dimensions (query / country / device) or indexing/sitemap checks: gsc.py query <tool_name> '<json args>', list tools with gsc.py tools.

Step 3 — Build the Excel report

Compose a spec JSON, then gsc.py xlsx spec.json.

Column conventions (established with the user):

  • Blog EN/CN: 标题 / EN(曝光、点击、CTR、平均排名) / CN(路径+同四项) / EN+CN 合计
  • Identify cn pages by parsing each EN page's hreflang alternates over the user's proxy (GET, not HEAD) — never guess /cn/ paths, never trust a manually annotated list.
  • Add 上线天数 / 日均曝光 when publish dates matter (from JSON-LD datePublished).
  • Include a 说明 sheet: date range, merge rules, caveats.
  • Deliver the file to the user.

Design notes (why it is built this way)

  • Proxy shim: hosts rewrite proxy env vars, and google-api-python-client's httplib2 only reads env at construction → every call times out. proxy_launcher.py replaces httplib2.Http with a requests-backed shim and pins the route, auto-detecting the local proxy port (GSC_PROXY overrides).
  • Dependency bootstrap: every script re-runs itself through uv run --with mcp-search-console --with openpyxl --with requests when libs are missing, so python gsc.py ... works on a fresh machine. A child process is used instead of os.execvpe (process replacement segfaults on Windows).
  • Token reuse: fetch_pages.py and gsc.py login both go through gsc_server.get_gsc_service(), so the CLI and the MCP share one cached token in user_config_dir("mcp-gsc")/token.json — the user authorizes once.
  • Portable paths: work dir = $GSC_HOME → ~/.workbuddy/gsc (existing WorkBuddy installs) → ~/.gsc-data-get (other hosts).
  • GA4 without gcloud: ga4_login.py runs the same browser OAuth with the existing client_secrets.json and writes an ADC-format ga4_adc.json (GOOGLE_APPLICATION_CREDENTIALS) — the official google-analytics-mcp only needs that file. setup_env.py installs ga4_launcher.py (same proxy shim, entry ga4_mcp.server:main) and merges a ga4Server MCP entry once the ADC exists; property comes from ga4_property_id.txt or $GA4_PROPERTY_ID.

Resources

scripts/

  • gsc.py — unified CLI (bootstrap / doctor / setup / import-secrets / login / ga4-login / sites / pages / query / tools / xlsx)
  • gsc_paths.py — path resolution, uvx discovery, dependency bootstrap
  • import_secrets.py — validate + install a credential file under the right name
  • check_env.py — environment probe (JSON output, exit codes 0/1/2)
  • setup_env.py — dirs, launcher install, MCP config merge (WorkBuddy only)
  • proxy_patch.py — shared proxy shim (requests-backed httplib2 + Session pin)
  • proxy_launcher.py — GSC server bootstrap via proxy_patch
  • ga4_launcher.py — GA4 server bootstrap via proxy_patch
  • ga4_login.py — gcloud-free GA4 ADC credential generation + verify
  • gsc_query.py — call any GSC MCP tool over stdio
  • fetch_pages.py — page-level analytics with anchor-variant merging
  • build_xlsx.py — spec-driven Excel writer

references/

  • manual-guide.md — the single manual step (credential creation) + migration
  • gotchas.md — data pitfalls; read before any report