Skip to content
OpenSmartRoute
Skillv1.0.0

ga4-common-reports

Copy-paste recipes for the 6-7 reports every site owner actually wants: DAU/MAU/WAU, retention cohort, top pages by source, channel attribution, conversion funnel, geo breakdown, device split. Each re

by jeremylongshore(0) 0 installs
Free
Sign in to install

Free account. Installing gives you the manifest plus copy-paste snippets.

See reviews

About

Imported from jeremylongshore/tons-of-skills-marketplace (plugins/saas-packs/ga4-pack/skills/ga4-common-reports/SKILL.md). Install upstream with npx skills add jeremylongshore/tons-of-skills-marketplace --skill ga4-common-reports. Copyright stays with the author (MIT).

GA4 Common Reports

Overview

Recipes for the reports that get asked for ~95% of the time. Each one is a complete runReport you can paste, change PROPERTY_ID, and run. Prerequisite: ga4-auth-setup done.

Prerequisites

  • A GA4 Data API credential configured by ga4-auth-setup and granted Viewer access to the target property.
  • Python with google-analytics-data installed and GA4_PROPERTY_ID set to the numeric property ID.
  • A clear reporting window; use completed days for stable comparisons.

Instructions

The setup block (same for every recipe):

import os
from google.analytics.data_v1beta import BetaAnalyticsDataClient
from google.analytics.data_v1beta.types import (
    RunReportRequest, DateRange, Metric, Dimension,
    FilterExpression, Filter, OrderBy,
)

PROPERTY = f"properties/{os.environ['GA4_PROPERTY_ID']}"
client = BetaAnalyticsDataClient()

Examples

1. Daily Active Users (DAU) — 30-day rolling

req = RunReportRequest(
    property=PROPERTY,
    date_ranges=[DateRange(start_date="30daysAgo", end_date="yesterday")],
    metrics=[Metric(name="activeUsers")],
    dimensions=[Dimension(name="date")],
    order_bys=[OrderBy(dimension=OrderBy.DimensionOrderBy(dimension_name="date"))],
)
resp = client.run_report(req)
for r in resp.rows:
    print(f"{r.dimension_values[0].value} {r.metric_values[0].value}")

Why yesterday, not today: today's number is incomplete and will keep climbing through the day. For a clean rolling DAU, end the window at yesterday.

2. MAU / WAU — rolling unique users

GA4 doesn't expose MAU as a single metric — you compute it from the same activeUsers rolled up over a wider date range. The trick: a single-row report with no date dimension returns the unique count over the entire window (de-duplicated across days).

# MAU (last 30 days)
mau = client.run_report(RunReportRequest(
    property=PROPERTY,
    date_ranges=[DateRange(start_date="29daysAgo", end_date="yesterday")],
    metrics=[Metric(name="activeUsers")],
))
mau_count = int(mau.rows[0].metric_values[0].value) if mau.rows else 0

# WAU (last 7 days)
wau = client.run_report(RunReportRequest(
    property=PROPERTY,
    date_ranges=[DateRange(start_date="6daysAgo", end_date="yesterday")],
    metrics=[Metric(name="activeUsers")],
))
wau_count = int(wau.rows[0].metric_values[0].value) if wau.rows else 0

print(f"MAU: {mau_count:,}   WAU: {wau_count:,}   Ratio (engagement): {wau_count/mau_count:.2%}")

Stickiness rule-of-thumb: WAU/MAU > 0.5 is good, > 0.7 is excellent, < 0.2 means most users visit once and bounce.

3. Top pages — last 7 days, ordered by pageviews

req = RunReportRequest(
    property=PROPERTY,
    date_ranges=[DateRange(start_date="7daysAgo", end_date="yesterday")],
    metrics=[Metric(name="screenPageViews"), Metric(name="activeUsers"), Metric(name="averageSessionDuration")],
    dimensions=[Dimension(name="pagePath")],
    order_bys=[OrderBy(metric=OrderBy.MetricOrderBy(metric_name="screenPageViews"), desc=True)],
    limit=25,
)
resp = client.run_report(req)
print(f"{'Path':<60} {'Views':>8} {'Users':>8} {'AvgSec':>8}")
for r in resp.rows:
    print(f"{r.dimension_values[0].value[:58]:<60} "
          f"{r.metric_values[0].value:>8} {r.metric_values[1].value:>8} "
          f"{float(r.metric_values[2].value):>8.1f}")

4. Channel attribution — where did users come from?

req = RunReportRequest(
    property=PROPERTY,
    date_ranges=[DateRange(start_date="30daysAgo", end_date="yesterday")],
    metrics=[Metric(name="activeUsers"), Metric(name="sessions"), Metric(name="engagedSessions")],
    dimensions=[Dimension(name="sessionDefaultChannelGrouping")],
    order_bys=[OrderBy(metric=OrderBy.MetricOrderBy(metric_name="activeUsers"), desc=True)],
)
resp = client.run_report(req)
print(f"{'Channel':<28} {'Users':>10} {'Sessions':>10} {'Engaged%':>10}")
for r in resp.rows:
    users = int(r.metric_values[0].value)
    sess = int(r.metric_values[1].value)
    eng = int(r.metric_values[2].value)
    eng_rate = eng / sess if sess else 0
    print(f"{r.dimension_values[0].value:<28} {users:>10,} {sess:>10,} {eng_rate:>9.1%}")

GA4's default channel grouping has ~12 buckets: Direct, Organic Search, Paid Search, Organic Social, Paid Social, Email, Referral, Display, Video, Affiliates, Audio, etc. Use sessionSource + sessionMedium for finer-grained attribution (e.g. google / organic vs bing / organic).

5. Retention cohort — week 1 / 2 / 3 / 4 return rate

GA4 has a built-in cohort exploration in the UI but the Data API doesn't expose it cleanly. The workaround: query DAU per week and compute rolling overlap. The cheap approximation:

# Weekly active users for the last 8 weeks
req = RunReportRequest(
    property=PROPERTY,
    date_ranges=[DateRange(start_date="56daysAgo", end_date="yesterday")],
    metrics=[Metric(name="activeUsers")],
    dimensions=[Dimension(name="isoYearIsoWeek")],
    order_bys=[OrderBy(dimension=OrderBy.DimensionOrderBy(dimension_name="isoYearIsoWeek"))],
)
resp = client.run_report(req)
for r in resp.rows:
    print(f"{r.dimension_values[0].value}  {r.metric_values[0].value}")

For true cohort retention (e.g. "of users acquired in week N, what % came back in week N+1, N+2, N+3"), you need event-level data — use ga4-bigquery-export and write the cohort SQL directly. The Data API can't express the join.

6. Conversion funnel — landing → engagement → conversion

GA4 funnels via API: query each step as a separate runReport filtered by the event that defines the step, then divide.

def step_users(event_name, days_ago=7):
    return int(client.run_report(RunReportRequest(
        property=PROPERTY,
        date_ranges=[DateRange(start_date=f"{days_ago}daysAgo", end_date="yesterday")],
        metrics=[Metric(name="activeUsers")],
        dimension_filter=FilterExpression(filter=Filter(
            field_name="eventName",
            string_filter=Filter.StringFilter(
                match_type=Filter.StringFilter.MatchType.EXACT,
                value=event_name,
            ),
        )),
    )).rows[0].metric_values[0].value)

# Example funnel: landed → engaged → signed up → purchased
steps = [
    ("session_start",  step_users("session_start")),
    ("user_engagement", step_users("user_engagement")),
    ("sign_up",         step_users("sign_up")),
    ("purchase",        step_users("purchase")),
]
top = steps[0][1] or 1
print(f"{'Step':<20} {'Users':>10} {'% of top':>10}")
for name, count in steps:
    print(f"{name:<20} {count:>10,} {count/top:>9.1%}")

Limitation: this counts users who fired the event at any point in the window, NOT users who progressed through the funnel in order. For ordered funnels (true sequencing), use BigQuery export or the GA4 UI's Exploration → Funnel report.

7. Geo + device split

req = RunReportRequest(
    property=PROPERTY,
    date_ranges=[DateRange(start_date="30daysAgo", end_date="yesterday")],
    metrics=[Metric(name="activeUsers"), Metric(name="bounceRate")],
    dimensions=[Dimension(name="country"), Dimension(name="deviceCategory")],
    order_bys=[OrderBy(metric=OrderBy.MetricOrderBy(metric_name="activeUsers"), desc=True)],
    limit=30,
)
resp = client.run_report(req)
for r in resp.rows:
    country, device = r.dimension_values[0].value, r.dimension_values[1].value
    users, bounce = r.metric_values[0].value, float(r.metric_values[1].value)
    print(f"{country:<20} {device:<10} {users:>10} {bounce:>6.1%}")

A common signal: if one country dominates with low engagement + high bounce, it's often bot traffic from that country's cloud-host hubs (Singapore, Vietnam, China data centers are the usual suspects).

Output

Each recipe prints a focused, ready-to-inspect report: date-series users, aggregate MAU/WAU, ranked pages or channels, a funnel, or geo/device rows. The results are API aggregates and should be interpreted with the date window and metric definitions shown in each recipe.

Error Handling

If a request fails, first confirm that the property ID is numeric, the credential has property access, and the metric/dimension pair is valid. Empty reports can be legitimate for an inactive property or a future/incomplete date range; use ga4-data-api-query to check compatibility and pagination before assuming data loss.

Resources

  • GA4 Data API reference — metric, dimension, and request documentation.
  • ga4-bigquery-export — the companion skill for event-level analysis and unsampled cohort queries.

When the Data API isn't enough

Three reasons to graduate to BigQuery export:

  1. Sampling — your queries hit resp.metadata.data_loss_from_other_row=True. Sampled = approximate. BQ export = exact.
  2. Custom event analytics — joining event-level data across sessions, computing retention cohorts, building attribution models. SQL is the only sensible tool.
  3. Cost — Data API has daily quotas; BQ is pay-per-query (free for small properties, cheap up to ~100M events/day).

See ga4-bigquery-export for the setup.

Related skills

  • ga4-auth-setup — prerequisite
  • ga4-data-api-query — the underlying API the recipes here use
  • ga4-realtime-api — for "right now" data instead of any of the above
  • ga4-bigquery-export — when these recipes hit their limits

Use it

Copy one of these into your project. Installing also returns the manifest and these snippets.

yaml
targets:
  - https://api.opensmartroute.ai/api/v1/registry/jeremylongshore-tons-of-skills-marketplace-ga4-common-reports/manifest   # or paste the manifest below

Manifest

An Open Capability Manifest: the router reads it to know what this does, what it costs and when to pick it.

jeremylongshore-tons-of-skills-marketplace-ga4-common-reports.ocm.jsonjson
{
  "ocm": "1",
  "id": "jeremylongshore-tons-of-skills-marketplace-ga4-common-reports",
  "kind": "skill",
  "name": "ga4-common-reports",
  "description": "Copy-paste recipes for the 6-7 reports every site owner actually wants: DAU/MAU/WAU, retention cohort, top pages by source, channel attribution, conversion funnel, geo breakdown, device split. Each recipe is a fully-formed Data API request. Trigger with \"GA4 DAU\", \"GA4 retention\", \"GA4 top pages\", \"GA4 funnel\", \"GA4 channel report\", \"common GA4 reports\".",
  "publisher": "jeremylongshore",
  "version": "1.0.0",
  "capabilities": {
    "domains": [
      "coding",
      "math"
    ],
    "tags": [
      "skill-md",
      "saas",
      "analytics",
      "google-analytics",
      "ga4",
      "reports",
      "skills-sh"
    ],
    "languages": [
      "en"
    ]
  },
  "quality_prior": 0.6,
  "examples": [
    "Copy-paste recipes for the 6-7 reports every site owner actually wants: DAU/MAU/WAU, retention cohort, top pages by source, channel attribution, conversion funnel, geo breakdown, device split. Each recipe is a fully-formed Data API request. Trigger with \"GA4 DAU\", \"GA4 retention\", \"GA4 top pages\", \"GA4 funnel\", \"GA4 channel report\", \"common GA4 reports\"."
  ],
  "primary": false,
  "metadata": {
    "source": {
      "provider": "skills.sh",
      "repository": "https://github.com/jeremylongshore/tons-of-skills-marketplace",
      "path": "plugins/saas-packs/ga4-pack/skills/ga4-common-reports/SKILL.md",
      "ref": "HEAD",
      "url": "https://github.com/jeremylongshore/tons-of-skills-marketplace/blob/HEAD/plugins/saas-packs/ga4-pack/skills/ga4-common-reports/SKILL.md",
      "key": "jeremylongshore/tons-of-skills-marketplace/plugins/saas-packs/ga4-pack/skills/ga4-common-reports/SKILL.md"
    },
    "compatibility": "Designed for Claude Code",
    "allowed_tools": [
      "Bash(python3:*)"
    ],
    "license": "MIT"
  },
  "instructions": "# GA4 Common Reports\n\n## Overview\n\nRecipes for the reports that get asked for ~95% of the time. Each one is a complete `runReport` you can paste, change `PROPERTY_ID`, and run. Prerequisite: `ga4-auth-setup` done.\n\n## Prerequisites\n\n- A GA4 Data API credential configured by `ga4-auth-setup` and granted Viewer access to the target property.\n- Python with `google-analytics-data` installed and `GA4_PROPERTY_ID` set to the numeric property ID.\n- A clear reporting window; use completed days for stable comparisons.\n\n## Instructions\n\nThe setup block (same for every recipe):\n\n```python\nimport os\nfrom ",
  "cost": {
    "context_tokens": 2365
  }
}

Fetch it by URL: GET /api/v1/registry/jeremylongshore-tons-of-skills-marketplace-ga4-common-reports/manifest?version=1.0.0

Reviews

Star ratings from people who tried it. One review per account; edit yours any time.

No reviews yet. Install it, try it, and be the first to rate it.