MarkdownCopies this page as Markdown, ready to paste into an AI assistant.
Google Analytics API
8 Google Analytics endpoints behind one key, priced in credits per call and routed to the cheapest healthy source.
On this page
Web Intelligence · 8 endpoints · from 1 credit per call
Endpoints
- POSTGoogle Analytics Create Custom Dimension
/v1/run/google-analytics.create_custom_dimensionCreates a custom dimension in a Google Analytics 4 property from an event parameter, user property or item parameter (a change to the connected account).1 creditper call - POSTGoogle Analytics Create Key Event
/v1/run/google-analytics.create_key_eventMarks an event as a key event (conversion) in a Google Analytics 4 property (a change to the connected account).1 creditper call - POSTGoogle Analytics Custom Dimensions
/v1/run/google-analytics.custom_dimensionsLists the custom dimensions of a Google Analytics 4 property with the parameter each one reads and its scope.1 creditper call - POSTGoogle Analytics Dimensions and Metrics
/v1/run/google-analytics.metadataLists the dimensions and metrics a Google Analytics 4 property can report on, including its custom ones, with their API names.1 creditper call - POSTGoogle Analytics Key Events
/v1/run/google-analytics.key_eventsLists the key events (conversions) of a Google Analytics 4 property with their counting method and default value.1 creditper call - POSTGoogle Analytics Properties
/v1/run/google-analytics.propertiesLists the Google Analytics 4 accounts and properties the connected Google account can see.1 creditper call - POSTGoogle Analytics Realtime Report
/v1/run/google-analytics.realtime_reportLive Google Analytics 4 data for a property from the last 30 minutes (60 on Analytics 360): active users, events and more by dimension.1 creditper call - POSTGoogle Analytics Report
/v1/run/google-analytics.reportRuns a Google Analytics 4 report for a property: any dimensions and metrics over date ranges, with filters, sorting and paging.1 creditper call
Calling them
Every endpoint on this page is one POST to https://api.primaryapi.com/v1/run/{sku} with your API key and a JSON body. Responses share one envelope, so code written for one endpoint handles the others. For example, google-analytics.create_custom_dimension:
curl -sS -X POST "https://api.primaryapi.com/v1/run/google-analytics.create_custom_dimension" \
-H "Authorization: Bearer $PRIMARYAPI_API_KEY" \
-H "Content-Type: application/json" \
-d '{"propertyId":"312345678","parameterName":"article_author","displayName":"Article author","description":"Author of the article viewed","scope":"EVENT"}'const res = await fetch('https://api.primaryapi.com/v1/run/google-analytics.create_custom_dimension', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.PRIMARYAPI_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
propertyId: '312345678',
parameterName: 'article_author',
displayName: 'Article author',
description: 'Author of the article viewed',
scope: 'EVENT',
}),
});
const body = await res.json();
if (!res.ok) throw new Error(`${body.code}: ${body.error}`);
// found:false is a successful answer ("does not exist"), not an error
console.log(body.output.found ? body.output.data : body.output.reason, body.credits);import os
import requests
res = requests.post(
"https://api.primaryapi.com/v1/run/google-analytics.create_custom_dimension",
headers={"Authorization": f"Bearer {os.environ['PRIMARYAPI_API_KEY']}"},
json={
"propertyId": "312345678",
"parameterName": "article_author",
"displayName": "Article author",
"description": "Author of the article viewed",
"scope": "EVENT",
},
timeout=60,
)
body = res.json()
if not res.ok:
raise RuntimeError(f"{body['code']}: {body['error']}")
# found=False is a successful answer ("does not exist"), not an error
print(body["output"]["data"] if body["output"]["found"] else body["output"]["reason"], body["credits"])New to PrimaryAPI? Start with the Quickstart, then read Making requests.