We want to get "the users in last 30 minutes" as below image. Any API can get that? Or, possible got this from BigQuery data?
Updated, This is the code I tried later, hope it helps.
from google.analytics.data_v1beta import BetaAnalyticsDataClient
from google.analytics.data_v1beta.types import (
Metric,
MinuteRange,
RunRealtimeReportRequest,
)
def sample_run_report(property_id="123456789"):
"""Runs a simple report on a Google Analytics 4 property."""
# TODO(developer): Uncomment this variable and replace with your
# Google Analytics 4 property ID before running the sample.
# property_id = "YOUR-GA4-PROPERTY-ID"
# Using a default constructor instructs the client to use the credentials
# specified in GOOGLE_APPLICATION_CREDENTIALS environment variable.
client = BetaAnalyticsDataClient()
request = RunRealtimeReportRequest(
property=f"properties/{property_id}",
metrics=[Metric(name="activeUsers")],
minute_ranges=[
MinuteRange(name="0-29 minutes ago", start_minutes_ago=29),
],
)
response = client.run_realtime_report(request)
print("Report result:")
for row in response.rows:
print(row.metric_values[0].value)
# print(row.dimension_values[0].value, row.metric_values[0].value)
Given that you're asking about the realtime report of Google Analytics, that data would have to be in the results of calling properties.runRealtimeReport
of the Google Analytics 4 Analytics Data API.