A Google Analytics 4 API mock for reading traffic reports.
Your agent requests reports from fixed sessions and events in a seeded property. The test checks the report call and that the final answer names the right traffic source.
report_readCalls POST /v1beta/properties/*:runReport
answer_givenThe final answer mentions linkedin
Starting records
properties
- id
345678901- displayName
Acme — marketing
principals
- id
acme-analyst
Connect your agent to the Google Analytics 4 mock
When ancha runs your agent, it sets:
GA4_API_URLGA4_ACCESS_TOKEN
Point the client you already use at them.
const response = await fetch(process.env.GA4_API_URL + '/v1beta/properties/345678901:runReport', {method:'POST', headers:{Authorization:'Bearer '+process.env.GA4_ACCESS_TOKEN,'Content-Type':'application/json'}, body:JSON.stringify({dateRanges:[{startDate:'2026-10-23',endDate:'2026-10-25'}],dimensions:[{name:'sessionSource'}],metrics:[{name:'sessions'}]})});
const report = await response.json();Locally, ancha runs your agent as an ordinary process, so keep real Google Analytics 4 credentials out of its environment.
See all 4 endpoints
properties
/v1beta/properties/:property:batchRunReports/v1beta/properties/:property:checkCompatibility/v1beta/properties/:property:runReport/v1beta/properties/:property/metadataSeed your own data
The data the Google Analytics 4 mock starts with on every run, cut to a few records. ancha twins seed ga4 prints every field.
Full seed YAML
twins:
- ga4
seed:
ga4:
properties:
- id: "345678901"
displayName: Acme — marketing
timeZone: America/Los_Angeles
currencyCode: USD
principals:
- id: acme-analyst
propertyIds:
- "345678901"
scopes:
- https://www.googleapis.com/auth/analytics.readonly
actor: acme-analyst
sessions:
- id: acme-session-1
propertyId: "345678901"
date: 2026-10-23
userId: visitor-ridgeway-01
country: United States
city: San Francisco
deviceCategory: desktop
source: linkedin
medium: paid_social
campaign: Ridgeway Robotics Q4 pilot
channelGroup: Paid Social
active: true
engaged: true
events:
- name: session_start
count: 1
Check what your agent did
Checks YAML
checks:
- id: report_read
trace:
called: POST /v1beta/properties/*:runReport
- id: answer_given
answer:
contains:
- linkedinMore marketing tools
All 43 toolsGoogle Analytics 4 API mock FAQ
Will a GA4 API mock count the same visitor twice across sessions?
Ancha calculates totalUsers from distinct seeded userId values and sessions from distinct session IDs in each report group. For metricAggregations: [TOTAL], it recalculates those counts from the matching source data.
How are dimensionFilter and metricFilter applied to a GA4 test report?
The mock applies dimensionFilter to session and event data before grouping, then applies metricFilter to each group's calculated metrics. Filters can combine andGroup, orGroup and notExpression, including string matches for dimensions and numeric comparisons for metrics.
Can I compare several date ranges in one Google Analytics report test?
A mock runReport request accepts one to four dateRanges and adds a dateRange dimension when you supply several. Values such as today, yesterday and 7daysAgo are resolved using the simulation clock in the property's timezone.
Install the CLI and run your agent against the Google Analytics 4 mock.
Ancha is not affiliated with Google Analytics 4.