Google Analytics calculated metric not available from core reporting API - google-analytics

Here's how the calculated metric is defined in the Google Analytics web interface:
Name
Profit
External Name
calcMetric_Profit
Formatting Type
Currency (Decimal)
Formula
{{Revenue}} - {{Shipping}} - {{Tax}}
The "External Name" field has this description:
The external name is used to uniquely identify the calculated metric when querying via API. External names may contain alphanumeric and underscore characters only. Special characters, symbols, and spaces are not allowed.
When I request the metric from v4 of the reporting API, using this request:
POST https://analyticsreporting.googleapis.com/v4/reports:batchGet?key=<redacted>
{
"reportRequests": [
{
"dateRanges": [
{
"startDate": "2018-01-01",
"endDate": "2018-01-22"
}
],
"metrics": [
{
"expression": "ga:calcMetric_Profit"
}
],
"viewId": "<redacted>"
}
]
}
I get this response:
400
{
"error": {
"code": 400,
"message": "Invalid value 'ga:calcMetric_Profit' for metric parameter.",
"status": "INVALID_ARGUMENT"
}
}
Am I doing something wrong?
Is this related to calculated metrics still being in Beta?

Change your startDate to one day after you created the calculated metric. Calculated metrics apply from the date they were created (there is no retrofilling). So if your startDate is before the date of creation, the API will throw an error, as the calculated metric doesn't exist for the dates prior to it being created.

Related

Why Google Analytics "minute" dimension doesn't work?

I try to execute the following request usign Google Reporting API:
"reportRequests": [
{
"metrics": [
{
"expression": "ga:sessions"
}
],
"dimensions": [
{
"name": "ga:date"
},
{
"name": "ga:minute"
}
],
"dateRanges": [
{
"startDate": "2018-01-02",
"endDate": "2018-04-17"
}
],
"viewId": "validViewId",
"hideValueRanges": true,
"hideTotals": true
}
]
Unfortunately I get no data. But when I use only "date" dimension, without "minute", I get some data in response.
Could someone please explain such a weird behavior?
As you are querying historical data (here > 2 years) the level of granularity of your data would be impacted by the retention period defined on property level. Meaning that beyond the retention period you can only query a combination of dimensions that are covered by Google Analytics standard aggregated tables (GA Help Center)
In your case the combination "Session | Date | Minute" is not part of Google Analytics aggregated tables, however "Session | Date" is.
You can recreate this phenomenon by using your query on different time ranges: within the retention period vs. outside the retention period.

HERE Routing API - How to use publicTransportTimeTable mode with multiple waypoints using calculate route resource?

I'm using calculateroute resource to calculate a route between multiple waypoints.
https://route.api.here.com/routing/7.2/calculateroute.json?app_id={APP_ID}&app_code={APP_CODE}&waypoint0=-25.4327193,-49.2806026;;0&waypoint1=-25.4392733,-49.2722581;;1&waypoint2=-25.4367652,-49.2833011;;2&waypoint3=-25.4327193,-49.2806026;;3&waypoint4=-25.4327193,-49.2806026;;4&waypoint5=-25.4392733,-49.2722581;;5&departure=2019-09-09T07:10:00-03:00&mode=fastest;car;traffic:disabled;motorway:0&improveFor=distance&language=pt-br&representation=navigation&metricSystem=metric&vehicletype=diesel,5.5
I was using departure parameter to set the initial date of the route, but now, instead of departure, I need to use arrival time in some cases. I was using car mode, but as arrival parameter requires publicTransportTimeTable, I set it this way.
https://route.api.here.com/routing/7.2/calculateroute.json?...&mode=fastest;publicTransportTimeTable;motorway:0..
Then the return was this error message: "Time Table Transit Routing is only supported for two StopOver waypoints", then I set the waypoint0 and waypoint5 as stopOver and the rest as passThrough, and yet, I receive the same error.
GET REQUEST
https://route.api.here.com/routing/7.2/calculateroute.json?app_id={APP_ID}&app_code={APP_CODE}&waypoint0=stopOver!-25.4327193,-49.2806026;;0&waypoint1=passThrough!-25.4392733,-49.2722581;;1&waypoint2=passThrough!-25.4367652,-49.2833011;;2&waypoint3=passThrough!-25.4327193,-49.2806026;;3&waypoint4=passThrough!-25.4327193,-49.2806026;;4&waypoint5=stopOver!-25.4392733,-49.2722581;;5&arrival=2019-09-09T07:10:00-03:00&mode=fastest;publicTransportTimeTable;motorway:0&improveFor=distance&language=pt-br&representation=navigation&metricSystem=metric&vehicletype=diesel,5.5
RETURN
{
"_type": "ns2:RoutingServiceErrorType",
"type": "ApplicationError",
"subtype": "InvalidInputData",
"details": "Time Table Transit Routing is only supported for two StopOver waypoints",
"additionalData": [
{
"key": "waypoint",
"value": ""
}
],
"metaInfo": {
"timestamp": "2019-09-10T13:40:27Z",
"mapVersion": "8.30.99.156",
"moduleVersion": "7.2.201935-5091",
"interfaceVersion": "2.6.68",
"availableMapVersion": [
"8.30.99.156"
]
}
}
as stated in the documentation, you can only use the arrival parameter when mode is set to publicTransportTimeTable. And this type of routing currently supports only two stopover waypoints (waypoint0 and waypoint1) and no passthrough waypoints.

Google Analytics API Revenue Discrepances

I have discrepancies in the revenue metric, between the data I collect from the Google Analytics API and the custom reports in the user interface.
The discrepancies for each value maintain the same rate, where the data collected through the API is greater than the data in the custom reports.
This is the body of the request I'm using:
{
"reportRequests":[
{
"viewId":"xxxxxxxxxx",
"dateRanges": [{"startDate":"2017-07-01","endDate":"2018-12-31"}],
"metrics": [
{"expression": "ga:transactionRevenue","alias": "transactionRevenue","formattingType": "CURRENCY"},
{"expression": "ga:itemRevenue","alias": "itemRevenue","formattingType": "CURRENCY"},
{"expression": "ga:productRevenuePerPurchase","alias": "productRevenuePerPurchase","formattingType": "CURRENCY"}
],
"dimensions": [
{"name": "ga:channelGrouping"},
{"name": "ga:sourceMedium"},
{"name": "ga:dateHour"},
{"name": "ga:transactionId"},
{"name": "ga:keyWord"}
],
"pageSize": "10000"
}]}
This is an extract of the response:
{{
"reports": [
{
"columnHeader": {
"dimensions": [
"ga:channelGrouping",
"ga:sourceMedium",
"ga:dateHour",
"ga:transactionId",
"ga:keyWord"
],
"metricHeader": {
"metricHeaderEntries": [
{
"name": "transactionRevenue",
"type": "CURRENCY"
},
{
"name": "itemRevenue",
"type": "CURRENCY"
},
{
"name": "productRevenuePerPurchase",
"type": "CURRENCY"
}
]
}
},
"data": {
"rows": [
{
"dimensions": [
"(Other)",
"bing / (not set)",
"2018052216",
"834042319461-01",
"(not set)"
],
"metrics": [
{
"values": [
"367.675436",
"316.55053699999996",
"316.55053699999996"
]
}
]
},
...
So, if I create a custom report in the Google Analytics user interface and look for the transaction ID 834042319461-01, I get the following result:
google Analytics custom report filtered by transaction id 834042319461-01
In the end I have a revenue value of 367.675436 in the API response, but a value of 333.12 in the custom report, its a 10.37% more in the value of the API. I get this 10.37% increase for all values.
¿Why I'm having these discrepance?
¿What would you recomend to do in order to solve these problem?
Thanks.
My bet is that you're experiencing sampling (is your time range in the UI lower than in the API?): https://support.google.com/analytics/answer/2637192?hl=en
Sampling applies when:
you customize the reports
the number of sessions for the overall time range of the report (whether or not your query returns less sessions) exceeds 500K (GA) or 100M (GA 360)
The consequence is that:
the report will be based on a subset of the data (the % depends on the total number of sessions)
therefore your report data won't be as accurate as usual
What you can do to reduce sampling:
increase sample size (will only decrease sampling to a certain extend, but in most cases won't completely remove sampling). In UI it's done via the option at the top of the report, in the API it's done using the samplingLevel option
reduce time range
create filtered views so your reports contain the data you need without needed to customize reports
Because you are looking at a particular transaction ID, this might not be a sampling issue.
If the ratio is consistent, from your question it seems to be 10.37%. I believe this is the case of currency that you are using.
Try using local currency metric API calls when making monetary based calls.
For example -
ga:localTransactionRevenue instead of ga:transactionRevenue

Adobe Analytics API - Real Time Classification

I need to get from Omniture real time API a classify eVar, exclude some value, and then breackdown its with sitesection.
I try with this query:
{
"reportDescription": {
"source": "realtime",
"reportSuiteID": "**RSID**", //MY REPORT SUITE
"metrics": [{
"id": "instances"
}],
"elements": [{
"id": "evar", //MY EVAR
"top": 100,
"classification": "Real Time", //CLASSIFICATION NAME
"search": {
"type": "NOT",
"keywords": ["somevalue"] //THE VALUE TO EXCLUDE
}
},{
"id" : "sitesection",
"top" : 1
}],
"dateGranularity": "minute:1",
"dateFrom": "-1 minute"
}
}
But in the JSON response I see "somevalue" how if it not excluded.
The strange thing is that if I remove the "breakdown" (with sitesection) the classification filter seems to works fine.
I can't use classification filter if a breackdown is used in real time report? I can't find any documentation about that.
An other thing is that if I request a report with the classification, without any search, I receve the response but there is a lot of "::Unspecified::". The problem is that the "::Unspecified::" seems to be the last datas that Omniture receves form my webpages. I think this means that classifications are not in real time, also if you can to use it in real time report.

GA: How to access Cohort Analysis via Analytics API?

Cohort dimensions and metrics are listed here. Yet, when I try to query it using API (e.g. using Query Explorer) an error 400 occurs.
One of queries I've tried is: metrics = ga:cohortActiveUsers and dimensions = ga:cohortNthDay .
Is is possible to query Cohort Analysis report via API?
The problem you are having is because the Query explorer uses the v3 of the Google Analytics API. If you look at the Dimensions and Metrics Explorer you will notice that these dimensions were added in the Analytics Reporting API V4.
The error message you are getting is incorrect and should be corrected soon. It should state something more like This metric cannot be used in Version 3 of the API. You caught this while we where in the process of rolling out the new API. Which has now been officially released see change log
To make use of these new dimensions and metrics you must construct a V4 cohort request:
POST https://analyticsreporting.googleapis.com/v4/reports:batchGet
{
"reportRequests": [{
"viewId": "XXXX",
# No date range is required in the request
"dimensions": [{"name": "ga:cohort" },{"name": "ga:cohortNthDay" }],
"metrics": [
{"expression": "ga:cohortActiveUsers" },
{"expression": "ga:cohortTotalUsers"}
],
"cohortGroup": {
"cohorts": [{
"name": "cohort 1",
"type": "FIRST_VISIT_DATE",
"dateRange": { "startDate": "2015-08-01", "endDate": "2015-08-01"}
},{
"name": "cohort 2",
"type": "FIRST_VISIT_DATE",
"dateRange": {"startDate": "2015-07-01", "endDate": "2015-07-01"}
}]
}
}]
}
It is possible to compose a cohort requests by using the Request Composer tool, in the Cohort Request tab.
As you select the options in the Set query parameters section, the request payload is shown below.
Hope it helps.

Resources