0

I'm using the Google Analytics Data API v1beta to pull campaign-wise key events from my GA4 property, specifically tracking a custom event called Phone_Number_Click (configured via Google Tag Manager). However, I’m seeing a discrepancy between the UI and the API response. Google Analytics UI

Here’s what I see for a specific campaign:

Campaign ID Campaign Name Source keyEvents 225 Stroke-Rehab-Awareness-pmax GA4 UI 135.98 225 Stroke-Rehab-Awareness-pmax GA4 API 96.36

from google.analytics.data_v1beta import BetaAnalyticsDataClient
from google.analytics.data_v1beta.types import RunReportRequest, DateRange, Dimension, Metric
import pandas as pd
import os

os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = 'path_to_key.json'
client = BetaAnalyticsDataClient()

request = RunReportRequest(
    property="properties/2812",
    dimensions=[
        Dimension(name="campaignId"),
        Dimension(name="campaignName")
    ],
    metrics=[Metric(name="keyEvents")],
    date_ranges=[DateRange(start_date="yesterday", end_date="yesterday")],
)

response = client.run_report(request)
rows = [
    { "Campaign ID": row.dimension_values[0].value,
      "Campaign": row.dimension_values[1].value,
      "keyEvents": row.metric_values[0].value }
    for row in response.rows
]
df = pd.DataFrame(rows)
print(df)

My Questions:

  1. Does the Data API use the same attribution model as the GA4 UI?

  2. Is there a way to specify or align attribution settings in the API request?

  3. What can cause the API to return lower key events than the GA4 UI?

3
  • Try first to change timeframe, not today or yesterday Commented May 23 at 16:08
  • I tried changing the timeframe, but there is still the same difference between UI and API. What I observed the problem is because of the Segment filter.It is a custom segment under User Segment in which includes users when the Events is equal to Phone Number Click Commented May 26 at 10:10
  • If I do not use the Segment Filters, just add the rows and columns and values, it will give the correct match to UI and API Commented May 26 at 10:14

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.