---
name: google-analytics
description: Traps to avoid when querying Google Analytics 4 through treg — cases where the GA4 Data API returns a confident wrong answer instead of an error. Use whenever answering questions about site traffic, visitors, pageviews, channels, conversions, or revenue from GA4.
title: google-analytics
canonical_url: https://skilld.dev/gh/superdesigndev/treg/google-analytics
last_updated: 2026-09-27T14:41:53.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> If the user asked to install this Skill, run `npx skilld install superdesigndev/treg/google-analytics`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/google-analytics`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/superdesigndev/treg/google-analytics) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/google-analytics`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/google-analytics --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/google-analytics --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# GA4 via treg — what will silently mislead you

You already know the GA4 Data API. This file is **only** the things that return a plausible wrong
answer with no error. Everything here was verified live on 2026-07-22, and each trap was
confirmed by watching three independent agents walk into it.

Property id: `treg connections ls` → the `google-analytics` row's `resource_ref`.

## 1. `endDate:"today"` silently includes a partial day

**3 of 3 agents did this.** It inflates every number and you will not notice.

```
28daysAgo → today      /top-page = 45,120   ← includes a partial day
28daysAgo → yesterday  /top-page = 44,300
```

Use `yesterday` unless the user explicitly asks about today. If you must use `today`, say the
last day is partial.

## 2. Zero does not mean zero — check whether it's even tracked

**3 of 3 agents reported "$0 revenue and 0 conversions" for a business with real revenue.** Two
rated it high confidence; one argued the zero was trustworthy because `eventCount` was large.

`keyEvents`, `conversions`, and `totalRevenue` all return `0` when **nothing is instrumented**,
which is indistinguishable from genuinely zero. Before reporting any zero:

```bash
# does this property have ANY key events configured?
--data '{"dateRanges":[...],"metrics":[{"name":"keyEvents"}]}'
```

Don't request `keyEvents` and `conversions` in the same call — they're aliases and GA4 rejects
it with `400 Found duplicate metrics: conversions`. Pick one.

If `keyEvents` is 0 across a long window on a site with traffic, the correct answer is
**"conversions are not instrumented in GA4; this question can't be answered from this source"** —
never "revenue is $0". Revenue almost certainly lives in Stripe/PostHog instead.

## 3. A zero-row response has NO `rows` key at all

Not `rows: []` — the key is absent, and so is `rowCount`. The shape varies by query:

| Query | Top-level keys returned |
|---|---|
| grouped by a dimension | `['dimensionHeaders','metricHeaders','metadata','kind']` |
| metrics only (e.g. `keyEvents`) | `['metadata','kind']` — headers gone too |

A naive `d['rows']` raises `KeyError`, which reads as a malformed request. All three unskilled
agents were confused by this. Use `d.get('rows', [])`, treat empty as "no data", then apply
trap #2.

## 3b. Don't list `dateRange` as a dimension

Comparing two periods is a standard ask, and the obvious move errors:

```
400: "Field dateRange is not a dimension. This field can be used in a Pivot or
      OrderBy like a dimension, but does not need to be listed in the Dimensions."
```

Pass 2+ entries in `dateRanges` and the API **auto-appends** the range as an extra dimension
value. Give the ranges `name`s to label them in the output.

## 4. Dimension sums do NOT equal totals — they overcount

Measured against a dimensionless true total (illustrative, ratios are the point):

| Grouped by | Sum | vs true total |
|---|---|---|
| `sessionDefaultChannelGroup` | | **~104%** |
| `country` | | **~104%** |
| `pagePath` | | **~189%** |

Sessions span multiple pages, so per-page sums double-count badly. **Never sum a dimension to
report a total** — run a separate dimensionless query.

## 5. `limit` defaults to 10,000 and truncates silently

An unlimited `pagePath` query returned exactly 10,000 rows with `"rowCount": 42613` — 32,613 rows
dropped, no warning. **`rowCount` is the truth; `len(rows)` is not.** Compare them before saying
"all" or "every".

## 6. The Admin API is a different host and is unreachable via `/call/`

The tool is bound to `analyticsdata.googleapis.com`. Anything on
`analyticsadmin.googleapis.com` — `accountSummaries`, property metadata — returns a **Google HTML
404**, not JSON. Two of three agents burned several attempts here, including trying to pass an
absolute URL (which gets concatenated into garbage).

To list properties, use treg, not the proxy:

```bash
treg connections resources <connection-id>   # hits the Admin API server-side
```

## Everything else

Standard GA4 Data API. `runReport`, `runRealtimeReport`, `batchRunReports`, `runPivotReport`,
`checkCompatibility`, `/metadata` all verified working through `/call/`. Two minor notes:
metric values are **strings** (cast before arithmetic), and `metadata.timeZone` governs what
"today" means (a property reports in its own timezone, e.g. `Australia/Sydney`).

⚠️ *Reported but not observed here:* high-cardinality dimensions can collapse into an `(other)` row.

- API schema: https://developers.google.com/analytics/devguides/reporting/data/v1/api-schema
- runReport: https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/properties/runReport
- Quotas: https://developers.google.com/analytics/devguides/reporting/data/v1/quotas
