Google Analytics API

Business / OAuth Advanced HTTPS
Varies by plan (check documentation)

Overview

Google Analytics Data API (GA4) lets you query sessions, users, and conversion metrics to build custom dashboards or automate reports. Requires OAuth 2.0 with a service account.

💡

Beginner Tip

Always use a GA4 property ID formatted as "properties/123456789" — Universal Analytics UA-* IDs will not work. Find your property ID in GA4 Admin under Property Settings.

Available Data

Google Analytics data via REST API
JSON-formatted response data
Requires OAuth authentication

Example Response

JSON Response
{
  "status": "success",
  "data": {
    "result": "Data from Google Analytics",
    "description": "Collect, configure and analyze your data to reach the right audience",
    "timestamp": "2025-01-15T10:00:00Z"
  }
}

Field Reference

dimensionHeaders Ordered list of dimension names corresponding to columns in each row.
metricHeaders Ordered list of metric names and types corresponding to columns in each row.
rows Each row contains dimensionValues and metricValues arrays matching the header order.
rows[].dimensionValues[].value The string value for a dimension in this row (e.g. "United States").
rows[].metricValues[].value The metric value returned as a string — convert to a number in your code.
rowCount Total number of rows in the full result before any row limits are applied.

Implementation Example

const url = "https://developers.google.com/analytics/";
// Replace headers or query params with the values required by this API.
const response = await fetch(url, {
  headers: {
  "Authorization": "Bearer YOUR_API_KEY"
  }
});
if (!response.ok) throw new Error(`Request failed: ${response.status}`);
const data = await response.json();
console.log(data);

What Can You Build?

Note: These code examples are AI-generated and unverified. Always refer to the official API documentation for accurate usage.

Common Errors & Troubleshooting

403 User does not have sufficient permissions The service account or OAuth user lacks access to the GA4 property
In GA4 Admin > Property Access Management, grant the service account at least the Viewer role using its email address.
Unknown name error for a dimension or metric A dimension or metric name is misspelled or unavailable in GA4
Check the GA4 Dimensions and Metrics Explorer at developers.google.com/analytics/devguides/reporting/data/v1/api-schema for the exact name.
Empty rows array in response No data exists for the requested date range or filters
Widen the date range and remove dimension filters temporarily to confirm data is present in the property.

Matrix Score Breakdown

🌐 Reachability 30/30
⚡ Speed 5/20
🔒 Security 15/15
🛠 Developer XP 3/20
✓ Reliability 10/15

Partially tested on Apr 5, 2026

Technical Specifications

Auth OAuth
HTTPS REQUIRED
CORS UNKNOWN
Category Business
Difficulty Advanced
Verified: 2026-04-04

Similar APIs

View All →