Reputation: 46
I have tried using Google Analytics Data Api - and issue with it is that the numbers don't much up with what I get from api and from what I see on web ui of Google Analytics. I even tried query explorer for Google Analytics Data Api but got less results again.
From what I am assuming and come to know that google sampling applies on GA Data Api (Although I have results of a day in few hundreds only). Now I heard there is no option to control sampling in GA Data API but there was in GA Reporting API by controlling sampling size option. So I decided to use that. But to my surprise Reporting API only takes View ID and I only had Property ID because I was using GA4 (can't enable universal analytics).
This takes me down to what? I tried Management api and it is for controlling options but not to view data. I tried to import data into Looker and exported from there to myself. But Looker has same results I get from query explorer which are less than web ui of Google Analytics.
I want to do this programatically so just can't use manual export option of GA4.
Need help in finding best way to do it !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
I have done this same thing in google analytics data api, query explorer as well as ga web ui. Ga web ui shows the most results. While query explorer and google analytics data api shows the same after sampling. Attached screenshots for reference.
GA WEB UI _ QUERY
GA WEB UI _ RESULTS EXPORTED TO CSV
QUERY EXPLORER_ QUERY
QUERY EXPLORER_ RESULTS
GA4 DATA API_ RESULTS
EVEN TRIED 3rd PARTY SERVICE Supermetrics GOT SAME
Here is code for GAT DATA API: `
from apiclient.discovery import build
from oauth2client.service_account import ServiceAccountCredentials
import pandas as pd
from collections import defaultdict
SCOPES = ['https://www.googleapis.com/auth/analytics.readonly']
KEY_FILE_LOCATION = 'MY_GA.json'
property_id = 'properties/266233569'
dimensions = ["date","platform","customEvent:order_id"]
metrics = ['sessions']
request = {
"requests": [
{
"dateRanges": [
{
"startDate": "2022-10-19",
"endDate": "2022-10-19"
}
],
"dimensions": [{'name': name} for name in dimensions],
"metrics": [{'name': name} for name in metrics],
"limit": 10000,
"return_property_quota": True,
"keep_empty_rows": True
}
]
}
credentials = ServiceAccountCredentials.from_json_keyfile_name(KEY_FILE_LOCATION, SCOPES)
analytics = build('analyticsdata', 'v1beta',
credentials=credentials)
response =
analytics.properties().batchRunReports(property=property_id,
body=request).execute()
`
Upvotes: 0
Views: 1388
Reputation: 134
I believe it's a GA4 limitation. If you're considering third-party solutions, Able CDP has its own tracking that connects to BigQuery (so easily accessible in Looker) and provides raw tracking data without sampling.
Upvotes: 0