SEO Monitoring
by kostja94 / marketing-skills
Build an SEO data analysis system, monitor indexing/traffic/keywords/backlinks, or set up benchmarks.
Spots statistically significant drops and spikes in GA4 organic traffic and conversions, with seasonality taken into account.
Listed ·Updated
AGENT ROLE: You are an autonomous analytics agent. Execute the procedure below deterministically. Do not ask the user for confirmation between steps unless a STOP condition is reached. Emit only the JSON object defined in references/output.schema.json.
Given a GA4 property and a metric set, decide for each recent day whether each metric is anomalous relative to its own seasonality-adjusted baseline, and attribute each anomaly to the responsible dimension segment.
property_id (REQUIRED, string): GA4 property id, digits only, no "properties/" prefix.metrics (OPTIONAL, string[]): default ["sessions","conversions","totalRevenue"]. Restrict to organic where a channel filter is requested.evaluation_window_days (OPTIONAL, int): days to test for anomalies. Default 7.baseline_window_days (OPTIONAL, int): history used to build the baseline. Default 90. MUST be ≥ 8× the seasonal period (7) → minimum 56.sensitivity (OPTIONAL, enum low|medium|high): maps to robust-z threshold 4.0|3.5|3.0. Default medium.GOOGLE_APPLICATION_CREDENTIALS pointing to a service-account JSON key.
error.code = "AUTH_MISSING_CREDENTIALS" and instruct: "Set GOOGLE_APPLICATION_CREDENTIALS to a service-account key with the Analytics Data API enabled, and grant that service account at least Viewer on GA4 property {property_id}."https://www.googleapis.com/auth/analytics.readonly.POST https://analyticsdata.googleapis.com/v1beta/properties/{property_id}:runReport.403 PERMISSION_DENIED THEN STOP with error.code = "AUTH_NO_PROPERTY_ACCESS".scripts/detect_anomalies.py (it encapsulates auth, paging, backoff, and the statistics). Invoke:
python3 scripts/detect_anomalies.py --property {property_id} --metrics {csv} --eval {n} --baseline {n} --sensitivity {level}runReport calls as specified below and reproduce the statistics inline.STEP 1 — FETCH BASELINE
runReport with dateRanges = [{startDate: "{baseline_window_days}daysAgo", endDate: "yesterday"}], dimensions = ["date"], metrics = {metrics}.channel filter requested THEN add dimensionFilter on sessionDefaultChannelGroup == "Organic Search".limit=100000 + offset until rowCount exhausted.STEP 2 — BUILD SEASONAL BASELINE (per metric)
median and MAD (median absolute deviation). Robust sigma = 1.4826 * MAD.MAD == 0 for a group THEN set robust sigma = 1.4826 * mean(|x - median|); IF still 0 THEN mark that group insufficient_variance and skip anomaly scoring for it.STEP 3 — SCORE EVALUATION WINDOW
evaluation_window_days and each metric M:
robust_z = (value_D - weekday_median) / weekday_sigma.abs(robust_z) >= threshold(sensitivity) THEN flag anomaly; direction = "drop" if negative else "spike".STEP 4 — ATTRIBUTE (only for flagged days)
runReport for date D with dimensions = ["sessionDefaultChannelGroup","landingPagePlusQueryString","deviceCategory"], metrics=[M], orderBys desc by M, limit=25.drivers.STEP 5 — EMIT
references/output.schema.json. Sort anomalies by abs(robust_z) desc.429 OR body code == RESOURCE_EXHAUSTED THEN exponential backoff: sleep min(60, 2^attempt) + jitter(0..1s), max 5 attempts, THEN STOP with error.code = "RATE_LIMITED" and include quota echoed from propertyQuota in the last response.5xx THEN retry up to 3 times with the same backoff.< 56 distinct dates THEN set status = "insufficient_history", still score with widened threshold +0.5, and set confidence = "low".skipped_metrics.value = 0 only if GA4 confirms zero rows for a fully elapsed day; IF the day is still in progress (today) THEN exclude it.Emit exactly one JSON object validating against references/output.schema.json. No prose.
scripts/detect_anomalies.py — reference implementation (auth, paging, backoff, MAD scoring).references/output.schema.json — required output contract.Not using the CLI? Copy the SKILL.md and paste it straight into ChatGPT, Claude, or any agent.