I am using below to pull GA4 data. But when i am adding certain dimensions like HostName or pagePath, its giving elevated numbers( mostly for users and sessions) than what actual values are, My guess is it calculates duplicates. How to get accurate results ?
def run_report_for_single_day(client, property_id, report_request, date):
"""Run report for a single day."""
date_range = [DateRange(start_date=date, end_date=date)]
dimensions = [Dimension(name=dimension["name"]) for dimension in report_request.get("dimensions", [])]
metrics = [Metric(name=metric["expression"]) for metric in report_request.get("metrics", [])]
request = RunReportRequest(property=f"properties/{property_id}", date_ranges=date_range, dimensions=dimensions, metrics=metrics)
try:
response = client.run_report(request)
return response.to_dict()
except (GoogleAPICallError, RetryError) as e:
print(f"An error occurred: {e}")
return None
A sample Request : The following works perfectly with only Date and eventName dimensions, But when i add hostname and pagepath the numbers are crazy high.
{"dimensions":[{"name":"date"},{"name":"eventName"},{"name":"hostName"},{"name":"pagePath"}],"metrics":[{"name":"activeUsers"},{"name":"eventCount"},{"name":"keyEvents"},{"name":"screenPageViews"},{"name":"sessions"},{"name":"totalRevenue"}],"dateRanges":[{"startDate":"2024-04-02","endDate":"2024-04-03"}],"metricAggregations":["TOTAL"]}
I am trying to pull the request with accurate values