English 中文(简体)
I am using below to pull GA4 data. But when i am adding certain dimensions like HostName/pagePath, its giving elevated numbers
原标题:

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

问题回答

Let s say we have 10 sessions in last 28 days.

If we pull the dimension pagePath.

  • page A , 5 sessions
  • page B , 3 sessions
  • page C , 3 sessions

The reason why it shows 1 more session is because

If a user browse page A and page c within a session.

It will both count 1 on PageA and Page C.

So when you add the value from split rows => total 11

But on the report it will show the total is 10





相关问题
google analytics api fails to return segment data

I m trying to use Google Analytics API to retrieve data for my custom segments. They say here http://code.google.com/apis/analytics/docs/gdata/gdataReferenceAccountFeed.html#accountResponse that ...

Google Analytics API - Tying Behavior to Specific Dates

I am using the API to understand the performance of Adwords ad campaigns. I need to know how to attribute metrics back to the date dimension. For instance, for a given date, if I have 20 clicks, 18 ...

Integrating Google Analytics into GWT application

This should be totally simple but I can t get it working no matter what I try. I m trying to use Google Analytics with GWT application. From what I understood, there are two way to do it: First is ...

API for historical traffic data? [closed]

Does anyone know of a public API for historical traffic data? Some quick googling pulls up an API from Yahoo which offers real-time data, but I d be curious if anyone hosts a service for historical ...

Tools to generate reportanalytics feeds from google

Can you recommend any programmable tools/extensions that can be used to generate reports out of google analytics feed on th fly? Essentially some kind of pdf generator from feed, not sure though. Or ...

热门标签