I am pulling data programmatically from google analytics. This is the query I execute
def executeDataQuery(analytics: Analytics, profileId: String) : GaData = {
analytics.data().ga().get("ga:" + profileId,
"2012-01-01", // Start date.
"2012-01-14", // End date.
"ga:visits") // Metrics.
.setDimensions("ga:date")
.setSort("ga:date")
.setMaxResults(25)
.execute()
}
This gives visits/day. I assume the default granularity is per day.
How can I change the granularity of the data from visits/day to visits/minute or visits/month?
I know this can be done on the google analytics website.
There are quite a few ways you can slice up your data using the Core Reporting API Time - Dimensions & Metrics.
For instance, if you wanted to change it to hour, you could do:
.setDimensions("ga:dateHour")
If you'd like to preview the data that the api can get you, use the GA Query Explorer.
Related
Previously, with Universal Analytics, it was possible to request goal data via API by specifying the goal number, for example:
ga:goal01Completions
In GA4, assuming the event has been 'marked as conversion', this can be replicated by specifying the conversion name, for example:
conversions:online_enquiry
However is there are generalised method in GA4 which can request the count of any named event, regardless of whether or not it has been marked as a conversion, for example:
events:online_enquiry
events:page_view
events:begin_checkout
events:scroll
events:404_not_found
I used the runReport before.
https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/properties/runReport
It's creating a report. Dimension is eventName and Metric might be eventCount or other you prefer.
Here is the list dimension and metric you can find
Metric
Dimension
But still open to better way maybe I don't know.
I use R Studio to export the necessary data from the GA4 property. I wanted to collect data on Google Ads campaign name, number of sessions and Google Ads clicks assigned to the corresponding campaigns. The number of sessions downloads to me, but it shows 0 Google Ads clicks, although I can see in the GA4 property that the clicks are there. Have you also had this problem? I am using the publisherAdclicks metric:
metric in R Studio API
I have not found any other metric through which I can retrieve this data, so do you have any idea what the problem is?
My code looks like this:
googleAdsSessionsClick <- google_analytics_set(c("sessions", "publisherAdClicks"),
c("sessionCampaignName", "sessionSourceMedium"))
I use my own function:
google_analytics_set <- function(choosenMetrics = NULL, choosenDimentions = NULL) {ga_data(webPropertyId,
date_range = date,
metrics = choosenMetrics,
dimensions = choosenDimentions)}
I am using the GA4 (Google.Apis.AnalyticsReporting.v4) reporting API to create a dashboard for my company.
I noticed that if you select the following dimension:-
TIME/ga:dateHourMinute,
ADWORDS/ga:adwordsCampaignID
ADWORDS/ga:adwordsAdGroupID
with METRICS:-
ga:impressions,
ga:CPC
ga:adCost no data is returned
BUT if you change the selection to dimensions:-
TIME/ga:date,
ADWORDS/ga:adwordsCampaignID,
ADWORDS/ga:adwordsAdGroupID
with METRICS:-
ga:impressions,
ga:CPC
ga:adCost
data is returned. Does anyone know how to get the first query to return data?
The dimension ga:dateHourMinute is not compatible with the metrics ga:impressions, ga:CPC, and ga:adCost. Google Analytics does not store these metrics broken down by date, hour, and minute. If you send the first query, you will get that the dimensions and metrics are incompatible:
You can visit the dimension & metric explorer to plan a query for compatible dimensions and metrics. If you check the fields ga:adwordsCampaignID, ga:adwordsAdGroupID, ga:impressions, ga:CPC, and ga:adCost, then the dimension ga:dateHourMinute is grayed out to signify incompatibility:
I am Fetching Data from Google Analytics For Metrics (Pageviews,Unique pageviews, TimeonPAge, Exits) as below
DataResource.GaResource.GetRequest r = GAS.Data.Ga.Get(profileID,startdate.ToString("yyyy-MM-dd"),enddate.ToString("yyyy-MM-dd"),"ga:pageviews,ga:uniquePageviews,ga:timeOnPage,ga:exits");
r.Dimensions = "ga:pagePath";
r.Filters = "ga:pagePath=~ItemID=" + strPagePath + "*";
r.MaxResults = 1000;
GaData d = r.Fetch();`
I want to get a count of how many requests are remaining out of my current day's allocated quota for my ProfileID. Is there any method which gives count for the same??
There is no way to programmatically check what the status of your quota is. You can check some of the quotas project based ones on the Google developer console but this is project based. This isn't going to be your view based quota.
The best option is to count them yourself locally. However note its not a perfect system Google sometimes lets you go over or under by a few hundred.
I'm looking for a method to export every unique visitor from Google Analytics. So, a visitor could open a website for multiple times, I would like to export a single row with some information about the visits like mean time on the website, number of purchases, mean order amount etc.
Thanks in advance.
Stefan, I would suggest using customVariables for this.
Just make sure that you put this code before calling _trackPageview.
_gaq.push(['_setCustomVar',
1, // This custom var is set to slot #1.
'VisitorID', // Name of your CustomVar that will show up in Reports
'123456789', // ID of your visitors, you need to set this.
1 // Set the scope to visitor-level.
]);
The tricky part could be using actually getting the visitor ID on consistent basis. One of the ways to go is to actually use the same Visitor ID as Google Analytics stores in _utma cookie (details in this article).
The complete code to get it done this way would be following:
var a = uGC(document.cookie, '__utma=', ';');
var id = a.split(".")
_gaq.push(['_setCustomVar', 1, 'VisitorID', id[1], 1]);
After that, you can build custom report with the VisitorID as the main dimension and select any metrics you would like to see. Just make you use the correct and logical combination of dimensions/metrics to get numbers that actually make sense (see this brilliant article by Avinash Kaushik).