Skip to main content
The GoogleAnalyticsResourceClient provides access to Google Analytics 4 reporting, metadata exploration, and account management.

Usage

import { myAnalyticsClient } from "./clients";

const result = await myAnalyticsClient.invoke(
  "POST",
  "/v1beta/properties/123456:runReport",
  "weekly-report",
  {
    body: {
      type: "json",
      value: {
        dateRanges: [{ startDate: "7daysAgo", endDate: "today" }],
        metrics: [{ name: "activeUsers" }],
        dimensions: [{ name: "country" }],
      },
    },
  }
);

if (result.ok && result.result.body.kind === "json") {
  console.log("Report:", result.result.body.value);
}

Inputs

The invoke method accepts the following arguments:
method
string
required
The HTTP method to use: "GET" or "POST".
path
string
required
The Google Analytics API path (e.g., /v1beta/properties/123456:runReport).
invocationKey
string
required
A unique identifier for this operation.
options
object
Optional configuration object.

Outputs

The output format is the same as the Custom API client.
kind
"api"
Discriminator for the response type.
status
number
The HTTP status code.
body
ResponseBody
The response body (typically JSON).