Loading...
Loading...
Manages Google Analytics reporting data, enables the Analytics Data API via the Cloud CLI, and creates reports using the Google Analytics Data API (v1beta). Use when you need to interact with Google Analytics properties, run customized analytics reports, query metrics (like activeUsers, screenPageViews) and dimensions (like city, date), check metrics and dimensions compatibility, or verify API enablement.
npx skill4agent add google/skills google-analytics-data-api-basicsgcloudgcloudanalyticsdata.googleapis.comgcloud services enable analyticsdata.googleapis.com --quietgcloud services list --enabled --filter="analyticsdata.googleapis.com"gcloud auth application-default login --scopes="https://www.googleapis.com/auth/cloud-platform,https://www.googleapis.com/auth/analytics.readonly"v1beta[!IMPORTANT] Mandatory Agent Directive: When the user selects or requires a specific programming language, read the corresponding client library setup reference guide inlisted below.references/
google-analytics-datacom.google.cloud:google-cloud-analytics-datagoogle/analytics-data@google-analytics/datacloud.google.com/go/analytics/data/apiv1betaGoogle.Analytics.Data.V1Betagoogle-analytics-data-v1beta[!NOTE] Additional Resources: For further examples of calling the Data API with Java, PHP, Node.js, .NET, Python and REST, as well as hints on authentication with a service account, refer to the official Data API Quickstart.
pip install google-analytics-datapippipYOUR-PROPERTY-ID1234567from google.analytics.data_v1beta import BetaAnalyticsDataClient
from google.analytics.data_v1beta.types import DateRange, Dimension, Metric, RunReportRequest
def sample_run_report(property_id: str):
# Initialize the client.
# Assumes Application Default Credentials (ADC) are configured in your environment.
client = BetaAnalyticsDataClient()
request = RunReportRequest(
property=f"properties/{property_id}",
dimensions=[
Dimension(name="city"),
Dimension(name="date")
],
metrics=[
Metric(name="activeUsers"),
Metric(name="sessions")
],
date_ranges=[
DateRange(start_date="2026-05-01", end_date="today")
],
)
response = client.run_report(request)
print(f"Report result for property {property_id}:")
for row in response.rows:
print(
f"City: {row.dimension_values[0].value}, "
f"Date: {row.dimension_values[1].value}, "
f"Active Users: {row.metric_values[0].value}, "
f"Sessions: {row.metric_values[1].value}"
)
if __name__ == "__main__":
sample_run_report("YOUR-PROPERTY-ID")BetaAnalyticsDataClientRunReportRequestRunReportRequestcitycountrydatedeviceCategoryeventNamepageTitleactiveUserseventCountsessionsscreenPageViewstotalRevenueINVALID_ARGUMENTgetMetadata()checkCompatibility()from google.analytics.data_v1beta import BetaAnalyticsDataClient
from google.analytics.data_v1beta.types import CheckCompatibilityRequest, Compatibility, Dimension, Metric
def sample_check_compatibility(property_id: str):
client = BetaAnalyticsDataClient()
# Define the dimensions and metrics you want to query together.
# For example, checking if 'itemDescription' (an e-commerce dimension)
# is compatible with 'activeUsers' and 'totalRevenue'.
request = CheckCompatibilityRequest(
property=f"properties/{property_id}",
dimensions=[
Dimension(name="itemDescription"),
Dimension(name="date")
],
metrics=[
Metric(name="activeUsers"),
Metric(name="totalRevenue")
],
)
response = client.check_compatibility(request)
print(f"Compatibility check for property {property_id}:")
for dim in response.dimension_compatibilities:
is_compatible = dim.compatibility == Compatibility.COMPATIBLE
print(f"Dimension '{dim.dimension_metadata.api_name}' is compatible: {is_compatible}")
for metric in response.metric_compatibilities:
is_compatible = metric.compatibility == Compatibility.COMPATIBLE
print(f"Metric '{metric.metric_metadata.api_name}' is compatible: {is_compatible}")
if __name__ == "__main__":
sample_check_compatibility("YOUR-PROPERTY-ID")