> ## Documentation Index
> Fetch the complete documentation index at: https://docs.webrouter.net/llms.txt
> Use this file to discover all available pages before exploring further.

# Google Analytics 4 (Data API)

> Reports from your Google Analytics 4 properties: users, sessions, events and conversions by any dimension, plus realtime and the dimension/metric catalog.

![](https://mintcdn.com/webrouter/gPu3tCeozwRcDBjt/logo/data-apis/google-analytics.svg?fit=max\&auto=format\&n=gPu3tCeozwRcDBjt\&q=85\&s=b48ad5b4013e6ce8f14b506f7851877a)

[Web Catalog · Analytics](https://docs.webrouter.net/data-apis.md?category=analytics)

Needs&#x20;

`GOOGLE_ANALYTICS_CLIENT_ID`

,&#x20;

`GOOGLE_ANALYTICS_CLIENT_SECRET`

,&#x20;

`GOOGLE_ANALYTICS_REFRESH_TOKEN`

Endpoints

3

Auth

OAuth refresh token

[Vendor docs](https://developers.google.com/analytics/devguides/reporting/data/v1)

## Setup

| Variable | | What it is |
| - | - | - |
| `GOOGLE_ANALYTICS_CLIENT_ID` | required | the OAuth client id of a Google Cloud OAuth app with the Google Analytics Data API enabled (Google Cloud console > APIs & Services > Credentials) |
| `GOOGLE_ANALYTICS_CLIENT_SECRET` | required | that OAuth app's client secret |
| `GOOGLE_ANALYTICS_REFRESH_TOKEN` | required | a refresh token minted with that OAuth app for the scope [https://www.googleapis.com/auth/analytics.readonly](https://www.googleapis.com/auth/analytics.readonly) |

Put them in your environment or `.env`; [Data APIs](https://docs.webrouter.net/vendors.md) covers the other ways.

## Notes

* Own-account API: reads properties the signed-in Google user can access. GA4 only; Universal Analytics properties are gone.
* Property ids are digits only; the path takes them as properties/\{id} and this catalog adds the prefix.
* Report requests are POSTs but only read data.
* Row counts and offsets are strings (int64) in the JSON. Default limit 10,000, maximum 250,000 per request. Page with offset.
* Properties have token-based quotas; set returnPropertyQuota: true to see what a call used.

## Endpoints

POST

Run a Google Analytics report

Rows of metrics grouped by dimensions over date ranges, with filters and ordering.

[Open](#google-analytics-report-run)

POST

Run a realtime Google Analytics report

Events and users from the last 30 minutes (up to 60 on GA 360).

[Open](#google-analytics-report-realtime)

GET

List a property's dimensions and metrics

Every dimension and metric usable in reports for the property, including its custom ones.

[Open](#google-analytics-metadata-get)

### Run a Google Analytics report

POST

`/properties/{property_id}:runReport`

`google-analytics.report.run`

Rows of metrics grouped by dimensions over date ranges, with filters and ordering.

Input

<table>
  <thead>
    <tr>
      <th>
        Name
      </th>

      <th>
        Type
      </th>

      <th>
        In
      </th>

      <th>
        Notes
      </th>
    </tr>
  </thead>

  <tbody>
    <tr><td>`property_id` required</td><td>string</td><td>path</td><td>GA4 property id, digits only (Admin > Property details). Not the G-XXXX measurement id. Example `123456789`</td></tr>
    <tr><td>`dimensions`</td><td>array</td><td>body</td><td>\[\{name: 'country'}, ...]. Names from google-analytics.metadata.get. Example `[{"name": "country"}]`</td></tr>
    <tr><td>`metrics`</td><td>array</td><td>body</td><td>\[\{name: 'activeUsers'}, ...]. Names from google-analytics.metadata.get. Example `[{"name": "activeUsers"}]`</td></tr>
    <tr><td>`dateRanges`</td><td>array</td><td>body</td><td>\[\{startDate, endDate}] with YYYY-MM-DD or 'today', 'yesterday', 'NdaysAgo'. Example `[{"startDate": "28daysAgo", "endDate": "yesterday"}]`</td></tr>

    <tr>
      <td>
        `dimensionFilter`
      </td>

      <td>
        object
      </td>

      <td>
        body
      </td>

      <td>
        FilterExpression over dimensions. Metrics are not allowed here.
      </td>
    </tr>

    <tr>
      <td>
        `metricFilter`
      </td>

      <td>
        object
      </td>

      <td>
        body
      </td>

      <td>
        FilterExpression over metrics, applied after aggregation (like HAVING).
      </td>
    </tr>

    <tr>
      <td>
        `orderBys`
      </td>

      <td>
        array
      </td>

      <td>
        body
      </td>

      <td>
        How to sort the rows.
      </td>
    </tr>

    <tr><td>`limit`</td><td>string</td><td>body</td><td>Rows to return; default 10000, up to 250000. Example `1000`</td></tr>
    <tr><td>`offset`</td><td>string</td><td>body</td><td>Zero-based index of the first row, for paging. Example `0`</td></tr>

    <tr>
      <td>
        `metricAggregations`
      </td>

      <td>
        array
      </td>

      <td>
        body
      </td>

      <td>
        TOTAL, MAXIMUM or MINIMUM rows, shown under RESERVED\_ dimension values.
      </td>
    </tr>

    <tr>
      <td>
        `currencyCode`
      </td>

      <td>
        string
      </td>

      <td>
        body
      </td>

      <td>
        ISO 4217 code for money metrics; default is the property's currency.
      </td>
    </tr>

    <tr>
      <td>
        `keepEmptyRows`
      </td>

      <td>
        boolean
      </td>

      <td>
        body
      </td>

      <td>
        Include rows where every metric is 0.
      </td>
    </tr>

    <tr>
      <td>
        `returnPropertyQuota`
      </td>

      <td>
        boolean
      </td>

      <td>
        body
      </td>

      <td>
        Return the property's quota state.
      </td>
    </tr>
  </tbody>
</table>

[Vendor docs](https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/properties/runReport) · Same job: [Amplitude](https://docs.webrouter.net/data-apis/amplitude.md#amplitude-charts-query), [Close](https://docs.webrouter.net/data-apis/close-crm.md#close-crm-reports-activity), [Cloudflare](https://docs.webrouter.net/data-apis/cloudflare.md#cloudflare-analytics-graphql), [Instagram Graph API](https://docs.webrouter.net/data-apis/instagram.md#instagram-user-insights), [Klaviyo](https://docs.webrouter.net/data-apis/klaviyo.md#klaviyo-campaigns-report), [Microsoft Graph (Microsoft 365)](https://docs.webrouter.net/data-apis/microsoft-graph.md#microsoft-graph-reports-active-users)

```python Python theme={null}
router.call_data_api("google-analytics.report.run", {'property_id': '123456789', 'dimensions': [{'name': 'country'}], 'metrics': [{'name': 'activeUsers'}], 'dateRanges': [{'startDate': '28daysAgo', 'endDate': 'yesterday'}], 'limit': '1000', 'offset': '0'})
```

```text MCP theme={null}
call_data_api(endpoint="google-analytics.report.run", params={"property_id": "123456789", "dimensions": [{"name": "country"}], "metrics": [{"name": "activeUsers"}], "dateRanges": [{"startDate": "28daysAgo", "endDate": "yesterday"}], "limit": "1000", "offset": "0"})
```

> [!NOTE]
>
> * A read over POST: it only reports data.
> * Incompatible dimension and metric pairs are refused; check with the metadata endpoint.

### Run a realtime Google Analytics report

POST

`/properties/{property_id}:runRealtimeReport`

`google-analytics.report.realtime`

Events and users from the last 30 minutes (up to 60 on GA 360).

Input

<table>
  <thead>
    <tr>
      <th>
        Name
      </th>

      <th>
        Type
      </th>

      <th>
        In
      </th>

      <th>
        Notes
      </th>
    </tr>
  </thead>

  <tbody>
    <tr><td>`property_id` required</td><td>string</td><td>path</td><td>GA4 property id, digits only (Admin > Property details). Not the G-XXXX measurement id. Example `123456789`</td></tr>
    <tr><td>`dimensions`</td><td>array</td><td>body</td><td>\[\{name: 'country'}, ...]. Names from google-analytics.metadata.get. Example `[{"name": "country"}]`</td></tr>
    <tr><td>`metrics`</td><td>array</td><td>body</td><td>\[\{name: 'activeUsers'}, ...]. Names from google-analytics.metadata.get. Example `[{"name": "activeUsers"}]`</td></tr>

    <tr>
      <td>
        `minuteRanges`
      </td>

      <td>
        array
      </td>

      <td>
        body
      </td>

      <td>
        Up to 2 ranges \[\{name, startMinutesAgo, endMinutesAgo}]; default is the last 30 minutes.
      </td>
    </tr>

    <tr>
      <td>
        `dimensionFilter`
      </td>

      <td>
        object
      </td>

      <td>
        body
      </td>

      <td>
        FilterExpression over dimensions.
      </td>
    </tr>

    <tr>
      <td>
        `metricFilter`
      </td>

      <td>
        object
      </td>

      <td>
        body
      </td>

      <td>
        FilterExpression over metrics.
      </td>
    </tr>

    <tr>
      <td>
        `orderBys`
      </td>

      <td>
        array
      </td>

      <td>
        body
      </td>

      <td>
        Row sorting.
      </td>
    </tr>

    <tr>
      <td>
        `limit`
      </td>

      <td>
        string
      </td>

      <td>
        body
      </td>

      <td>
        Rows to return; default 10000, up to 250000.
      </td>
    </tr>

    <tr>
      <td>
        `metricAggregations`
      </td>

      <td>
        array
      </td>

      <td>
        body
      </td>

      <td>
        Aggregated rows.
      </td>
    </tr>

    <tr>
      <td>
        `returnPropertyQuota`
      </td>

      <td>
        boolean
      </td>

      <td>
        body
      </td>

      <td>
        Return the realtime quota state.
      </td>
    </tr>
  </tbody>
</table>

[Vendor docs](https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/properties/runRealtimeReport)

```python Python theme={null}
router.call_data_api("google-analytics.report.realtime", {'property_id': '123456789', 'dimensions': [{'name': 'country'}], 'metrics': [{'name': 'activeUsers'}]})
```

```text MCP theme={null}
call_data_api(endpoint="google-analytics.report.realtime", params={"property_id": "123456789", "dimensions": [{"name": "country"}], "metrics": [{"name": "activeUsers"}]})
```

> [!NOTE]
>
> * A read over POST. Realtime supports a smaller set of dimensions and metrics than runReport.

### List a property's dimensions and metrics

GET

`/properties/{property_id}/metadata`

`google-analytics.metadata.get`

Every dimension and metric usable in reports for the property, including its custom ones.

Input

<table>
  <thead>
    <tr>
      <th>
        Name
      </th>

      <th>
        Type
      </th>

      <th>
        In
      </th>

      <th>
        Notes
      </th>
    </tr>
  </thead>

  <tbody>
    <tr><td>`property_id` required</td><td>string</td><td>path</td><td>GA4 property id, digits only (Admin > Property details). Not the G-XXXX measurement id. Example `123456789`</td></tr>
  </tbody>
</table>

[Vendor docs](https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/properties/getMetadata) · Same job: [Close](https://docs.webrouter.net/data-apis/close-crm.md#close-crm-reports-activity-metrics)

```python Python theme={null}
router.call_data_api("google-analytics.metadata.get", {'property_id': '123456789'})
```

```text MCP theme={null}
call_data_api(endpoint="google-analytics.metadata.get", params={"property_id": "123456789"})
```

> [!NOTE]
>
> * Use property id 0 to list only what every property shares (no custom fields).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.