GA4 Attribution Path Modeler
Reconstructs multi-touch conversion paths from the event-level GA4 BigQuery export and assigns credit across channels w…
Updated
Use this skill
$ npx skills add seoskills.sh/ga4-attribution-modelerAbout this skill
GA4 Attribution Path Modeler is a Analytics and Rank Tracking skill for AI agents, published in the seoskills.sh catalog. Reach for it when your work involves gA4, Search Console, event tracking, and rank monitoring. Install it with one command and it runs inside your own agent, so the work happens in your workflow, not a separate SEO tool.
SKILL.md
GA4 Attribution Path Modeler
AGENT ROLE: Autonomous attribution agent operating over the GA4 → BigQuery export. Derive per-session channels, order each converter's touchpoints, apply the credit models, and emit the JSON in references/output.schema.json. This skill REQUIRES the BigQuery export to be enabled; it does not use the GA4 UI attribution.
OBJECTIVE
Quantify how much conversion value each acquisition channel earns under multiple attribution models, and surface the gap between last-click and multi-touch credit for Organic Search specifically.
INPUTS
project(REQUIRED): GCP project holding the export.dataset(REQUIRED): GA4 export dataset, e.g.analytics_123456789.conversion_events(REQUIRED): array of event names counted as conversions, e.g.["purchase","generate_lead"].lookback_days(OPTIONAL, default 30): touchpoint window before each conversion.value_source(OPTIONAL, enumevent_value|purchase_revenue|count): defaultpurchase_revenueforpurchase, elsecount.
AUTHENTICATION (BigQuery over the GA4 export)
- REQUIRE
GOOGLE_APPLICATION_CREDENTIALS. IF unset THEN STOPerror.code="AUTH_MISSING_CREDENTIALS". - SA roles:
roles/bigquery.jobUseron{project}+roles/bigquery.dataVieweron{dataset}.- IF
403 accessDeniedTHEN STOPerror.code="AUTH_NO_BQ_ACCESS".
- IF
- ALWAYS set
maximumBytesBilled = 50 GiBand prefer partition pruning on_TABLE_SUFFIX.
PRECONDITIONS (verify before querying)
- Confirm the export tables exist:
SELECT table_name FROM {dataset}.INFORMATION_SCHEMA.TABLES WHERE table_name LIKE 'events_%' LIMIT 1.- IF none THEN STOP
error.code="EXPORT_NOT_ENABLED": "Enable BigQuery Linking in GA4 Admin; there is no historical backfill, so only post-link dates exist."
- IF none THEN STOP
- Detect schema variant: newer exports carry
collected_traffic_source; older ones only event-leveltraffic_source. Setsource_fieldaccordingly and record it in output asschema_variant.
EXPECTED TOOL CALLS
- Run
scripts/attribution_paths.sqlwith query params@start,@end(as_TABLE_SUFFIXbounds),@conversion_events(ARRAY),@lookback(INT64). Parameterize; never concatenate. - Dry-run first; enforce the cost guard.
PROCEDURE
STEP 1 — SESSION CHANNEL: for every session_start (or first event per user_pseudo_id+ga_session_id), derive channel from source/medium using the mapping in references/channel_rules.json (organic, paid_search, direct, referral, social, email, other).
STEP 2 — CONVERSIONS: select events whose event_name IN @conversion_events; attach conv_value per value_source.
STEP 3 — PATHS: for each conversion, collect that user's distinct session-channels in the @lookback window, ordered by time, deduplicating consecutive repeats → path.
STEP 4 — CREDIT MODELS per conversion value:
last_click: 100% to the final channel.position_based: 40% first, 40% last, 20% split across middle (IF single touch → 100%).linear: equal split across touches. STEP 5 — AGGREGATE credit by channel per model; computeorganic_assist_ratio = organic.position_based / max(organic.last_click, epsilon). STEP 6 — EMIT JSON per schema.
RATE LIMITS & ERROR HANDLING
- BigQuery 429/
rateLimitExceeded→ backoff2^attempt(max 5) then STOPerror.code="RATE_LIMITED". - Poll long jobs
jobs.get≤180s; IF unfinished THENstatus="timeout"+job_id. - IF
maximumBytesBilledexceeded THEN STOPerror.code="COST_GUARD_TRIPPED"with the dry-run estimate; instruct to shortenlookback_daysor date span.
MISSING / INSUFFICIENT DATA
- IF 0 conversions in range THEN
status="no_conversions"; return zeroed model tables, no error. - IF
collected_traffic_sourceAND event-leveltraffic_sourceare both null for a session THEN channel =direct(GA4 convention) and incrementunattributed_sessions. - Cross-device stitching is limited to
user_idwhen present; otherwise paths areuser_pseudo_id-scoped — recordidentity_basisin output. Never overstate cross-device certainty.
OUTPUT
One JSON object per references/output.schema.json. No prose.
FILES
scripts/attribution_paths.sql— parameterized BigQuery Standard SQL over the GA4 export.references/channel_rules.json— source/medium → channel mapping.references/output.schema.json— output contract.
Not using the CLI? Copy the SKILL.md and paste it straight into ChatGPT, Claude, or any agent.
Embed a badge
Install into your agent
More in Analytics and Rank Tracking
GA4 Anomaly Detector
Detects statistically significant anomalies in GA4 organic traffic and conversions by pulling daily metrics from the GA…
Striking Distance Opportunity Finder
Surfaces "striking distance" keywords ranking in Search Console positions 11-20 with real impression demand, ranks them…
BigQuery Log File Analyzer
Analyzes raw server and CDN access logs stored in BigQuery to quantify Googlebot crawl behavior, surface crawl-budget w…
Search Console Cannibalization Analyzer
Detects keyword cannibalization by pulling query-and-page data from the Google Search Console API and clustering querie…