We have custom dimension define in Google Analytics Data API v1Beta for extracting data from Google Analytics GA4 account.
This worked fine till yesterday.
Error:
Please remove customEvent:institution_id to make the request compatible. The request's dimensions & metrics are incompatible. To learn more, see https://ga-dev-tools.web.app/ga4/dimensions-metrics-explorer/
POST - https://analyticsdata.googleapis.com/v1beta/properties/{propertyId}:runReport
Body
{
"dateRanges": [
{
"startDate": "2022-08-29",
"endDate": "2022-12-07"
}
],
"dimensions": [
{
"name": "customEvent:institution_id"
},
{
"name": "pagePathPlusQueryString"
}
],
"dimensionFilter": {
"andGroup": {
"expressions": [
{
"filter": {
"fieldName": "customEvent:institution_id",
"inListFilter": {
"values": [
"47339486-a1e5-47be-abce-e4270af23rte"
]
}
}
},
{
"filter": {
"fieldName": "pagePathPlusQueryString",
"stringFilter": {
"matchType": "PARTIAL_REGEXP",
"value": "/clip/.+",
"caseSensitive": false
}
}
}
]
}
},
"metrics": [
{
"name": "screenPageViews"
}
],
"metricAggregations": [
"TOTAL"
],
"limit": "10000"
}
Dimensions that include the query string like pagePathPlusQueryString are only compatible with a limited set of dimensions & metrics.
This changed was announced 2022-09-13 Schema compatibility changes announcement.
It went live earlier this week. So the cause if the error is that the "customEvent:institution_id" dimension is not compatible with "pagePathPlusQueryString".
Related
Is this the right request to send? And then I guess I need to manually sum the metrics over each date in the months? I can't even get the monthly view on the google analytics UI. It only lets me look at weekly. I am using google analytics v4 property. Docs
POST https://analyticsdata.googleapis.com/v1alpha:runReport
{
"entity": { "propertyId": "XXXX" },
"dateRanges": [{ "startDate": "2020-10-01", "endDate": "<today>" }],
"dimensions": [{ "name": "date" }],
"metrics": [{ "name": "eventCount" }],
"dimensionFilter": {
"andGroup": {
"expressions": [
{
"filter": {
"fieldName": "eventName",
"stringFilter": {
"value": "page_view"
}
}
},
{
"filter": {
"fieldName": "unifiedPageScreen",
"stringFilter": {
"value": "www.mysite.com/page_of_interest"
}
}
}
]
}
},
}
How is unifiedPageScreen populated on the page_view event? Do I need to do that manually?
I'm currently doing some tests on google datastore, but I'm having a problem with my queries.
If I believe in the documentation https://cloud.google.com/datastore/docs/concepts/queries we can realize a filter on several columns with the instruction EQUALS.
But when testing, I get an error from the API.
While searching on Datastore's github, I found this reference: https://github.com/GoogleCloudPlatform/google-cloud-dotnet/issues/304 which corresponds to my problem, except that for my case the query to the look good.
Here is the request sent:
{
{
"kind": [{
"name": "talk.message"
}],
"filter": {
"compositeFilter": {
"op": "AND",
"filters": [{
"propertyFilter": {
"property": {
"name": "Conversation"
},
"op": "EQUAL",
"value": {
"stringValue": "2f16c14f6939464ea687d316438ad4cb"
}
}
},
{
"propertyFilter": {
"property": {
"name": "CreatedOn"
},
"op": "LESS_THAN_OR_EQUAL",
"value": {
"timestampValue": "2019-03-15T10:43:31.474166300Z"
}
}
},
{
"propertyFilter": {
"property": {
"name": "CreatedOn"
},
"op": "GREATER_THAN_OR_EQUAL",
"value": {
"timestampValue": "2019-03-14T10:43:31.474175100Z"
}
}
}
]
}
}
}
}
And here is the answer from the API:
{Grpc.Core.RpcException: Status(
StatusCode=FailedPrecondition,
Detail="no matching index found. recommended index is:
- kind: talk.message
properties:
- name: Conversation
- name: CreatedOn"
)
According to the documentation, this should be good... but it's not !
What am I missing ?
Your query includes both an EQUALS (on Conversation) and a non-EQUALS filter (on CreatedOn), therefore you need a composite index to fulfil the query. So your query is valid, but it needs a composite index to be able to run the query.
I am trying to use GA API to check if lead submissions are going through our system correctly.
I need to check if pageview has been logged by GA on a url like below:
*www.mysite.com/leads/?e={{email}}
The e= parameter will be a string variable (email address) I pass to my API request, so basically I am checking to see if there is a logged pageview for the passed email.
I have been looking at the GA docs and think I need to use a filter of some kind but a little unsure how to proceed.
Here is my current code, it is simply checking for all todays PageViews without any filter.
{
"reportRequests": [
{
"viewId": {{View-ID}},
"dateRanges": [
{
"startDate": "today",
"endDate": "today"
}
],
"metrics": [
{
"expression": "ga:pageviews"
}
],
"dimensions":[
{
"name":"ga:date"
}
]
}
]
}
To answer your question in a more general sense, you should use dimension filter clause.
Example:
{
"reportRequests": [
{
"viewId": {{View-ID}},
"dateRanges": [
{
"startDate": "today",
"endDate": "today"
}
],
"metrics": [
{
"expression": "ga:pageviews"
}
],
"dimensions":[
{
"name":"ga:date"
}
],
"dimensionFilterClauses": [
{
"filters": [
{
"dimensionName": "ga:page",
"operator": "PARTIAL",
"expressions": {{email}}
}
]
}
]
}
]
}
I am trying to get all data from my Google Analytics account to a database using their Reporting API v4. In the below request and response, I see a number in the values attribute. I want to get member specific data for that number? For example, value is 65 for dimension 20130101. I want to get data of those 65 members that accessed my website that day (2013-01-01 - the specified dimension in the request). Any data that GA has will suffice. For example, the Gender of those 65 members, their session Id, age etc.
Google Analytics Reporting API Request:
{
"reportRequests": [
{
"viewId": "345",
"dateRanges": [
{
"startDate": "daysAgo",
"endDate": "yesterday"
}
],
"metrics": [
{
"expression": "ga:users"
}
],
"dimensions":[
{
"name":"ga:date"
}
]
}
]
}
Response
{
"reports": [
{
"columnHeader": {
"dimensions": [
"ga:date"
],
"metricHeader": {
"metricHeaderEntries": [
{
"name": "ga:users",
"type": "INTEGER"
}
]
}
},
"data": {
"rows": [
{
"dimensions": [
"20130101"
],
"metrics": [
{
"values": [
"65"
]
}
]
},
{
"dimensions": [
"20130102"
],
"metrics": [
{
"values": [
"69"
]
}
]
},
{
"dimensions": [
"20130103"
],
"metrics": [
{
"values": [
"48"
]
}
]
}
],
"totals": [
{
"values": [
"490"
]
}
],
"rowCount": 3,
"minimums": [
{
"values": [
"44"
]
}
],
"maximums": [
{
"values": [
"94"
]
}
],
"isDataGolden": true
}
}
]
}
Google Analytics reporting api don't provide single rows reports, that means that all the data that you can collect is gruped by the dimension.
In that case, if you want to retrieve al this data in a single report, you have to implement a custom dimension to a users level to identify each one, one option is send the client id (the _ga cookie) to the platform and add that dimension
Here is a good post of how to implement this
https://www.simoahava.com/analytics/add-clientid-to-custom-dimension-gtag-js/
Have in mind that you can expect others on the reports in that case, due the high cardinality.
https://support.google.com/analytics/answer/1009671?hl=en
For premium users you can export the data via BigQuery
Greetings
Below is the page for API v4 to get GA data
https://developers.google.com/analytics/devguides/reporting/core/v4/rest/v4/reports/batchGet
My request :
{
"reportRequests": [
{
"dateRanges": [
{
"startDate": "7daysAgo",
"endDate": "yesterday"
}
],
"metrics": [
{
"expression": "ga:users"
}
]
},
{
"viewId": "ga:123456"
}
]
}
Response :
{
"error": {
"code": 400,
"message": "Parameter viewId must be set.",
"status": "INVALID_ARGUMENT"
}
}
Query Explorer uses the the same ViewID and request parameter and it is fetching the data properly. What I am missing?
You are missing the viewId key in your first ReportRequest object. Having viewId standalone in a separate object doesn't work. Try this code instead:
{
"reportRequests": [
{
"viewId": "ga:123456", //viewId defined within the ReportRequest object itself
"dateRanges": [
{
"startDate": "7daysAgo",
"endDate": "yesterday"
}
],
"metrics": [
{
"expression": "ga:users"
}
]
}
]
}
You are missing a dimension like ga:date. Here is the list with possible dimensions to use in the GA-API: https://developers.google.com/analytics/devguides/reporting/core/dimsmets