Setu Recipes: reusable workflows across every app.Browse templates

Integrations / Google Analytics

Google Analytics

Run reports on your Google Analytics 4 properties: traffic, events, conversions and realtime activity.

4 actions OAuth 2 4 read0 write Calls analyticsdata.googleapis.com

Connect

TypeScript
const conn = await setu.connections.initiate({ userId: "user_1", toolkit: "googleanalytics" });
console.log(conn.connectUrl); // show this to your user
await conn.waitUntilActive();

Permissions requested

ScopeWhy it is requested
https://www.googleapis.com/auth/userinfo.emailSee which Google account you connected
https://www.googleapis.com/auth/analytics.readonlySee your Google Analytics reports and metadata

Actions

Run several reportsreadgoogleanalytics.batch_run_reportsRun up to 5 Google Analytics 4 reports on one property in a single call. Each request has dimensions, metrics and dateRanges.

Needs scope: https://www.googleapis.com/auth/analytics.readonly

InputTypeDescription
property_idstringRequiredNumeric GA4 property ID, e.g. 1234
requestsarray of objectRequiredUp to 5 RunReportRequest objects (dimensions, metrics, dateRanges, ...)
TypeScript
await setu.execute({
  userId: "user_1",
  action: "googleanalytics.batch_run_reports",
  input: {
    "property_id": "<property_id>",
    "requests": []
  },
});
Get dimensions and metricsreadgoogleanalytics.get_metadataList the dimensions and metrics available for a property (including custom ones), so a report can be built with valid names.

Needs scope: https://www.googleapis.com/auth/analytics.readonly

InputTypeDescription
property_idstringRequiredNumeric GA4 property ID, e.g. 1234 (use 0 for the standard set common to all properties)
TypeScript
await setu.execute({
  userId: "user_1",
  action: "googleanalytics.get_metadata",
  input: {
    "property_id": "<property_id>"
  },
});
Run realtime reportreadgoogleanalytics.run_realtime_reportRun a realtime Google Analytics 4 report (activity in the last 30 minutes by default), for example active users by country right now.

Needs scope: https://www.googleapis.com/auth/analytics.readonly

InputTypeDescription
property_idstringRequiredNumeric GA4 property ID, e.g. 1234
dimensionsarray of objectOptionalDimensions, e.g. [{"name":"country"}]
metricsarray of objectRequiredMetrics, e.g. [{"name":"activeUsers"}]
minute_rangesarray of objectOptionalOptional, up to 2, e.g. [{"startMinutesAgo":29,"endMinutesAgo":0}]
limitintegerOptionalMax rows
TypeScript
await setu.execute({
  userId: "user_1",
  action: "googleanalytics.run_realtime_report",
  input: {
    "property_id": "<property_id>",
    "metrics": []
  },
});
Run reportreadgoogleanalytics.run_reportRun a Google Analytics 4 report for a property: choose dimensions, metrics and date ranges (for example sessions by country over the last 28 days).

Needs scope: https://www.googleapis.com/auth/analytics.readonly

InputTypeDescription
property_idstringRequiredNumeric GA4 property ID, e.g. 1234 (Admin > Property settings)
dimensionsarray of objectOptionalDimensions, e.g. [{"name":"country"}]
metricsarray of objectRequiredMetrics, e.g. [{"name":"activeUsers"}]
date_rangesarray of objectRequirede.g. [{"startDate":"28daysAgo","endDate":"today"}]
dimension_filterobjectOptionalOptional FilterExpression on dimensions
order_bysarray of objectOptionalOptional sort order
limitintegerOptionalMax rows (default 10000)
offsetintegerOptionalRows to skip
TypeScript
await setu.execute({
  userId: "user_1",
  action: "googleanalytics.run_report",
  input: {
    "property_id": "<property_id>",
    "metrics": [],
    "date_ranges": []
  },
});