GA API differences with UI - google-analytics

Using segments, I am building an app that lets user enter a URL and check different metrics for it.
I see some significant differences between reports pulled with the API and report generated in the UI. Maybe I am misunderstanding something about segments.
For example, I have a segment designed to show only users that went on a specific page.
which map to a small fraction of my users:
When looking at the user age brackets, I see small numbers scattered across all categories.
Now to run the equivalent report in the API, I am using the payload below.
{
"reportRequests": [
{
"viewId": "#####",
"dateRanges": [
{ "startDate": "2017-03-01",
"endDate": "2017-04-27" }
],
"metrics": [
{"expression": "ga:pageviews"},
{"expression": "ga:sessions"},
{"expression": "ga:users"}
],
"segments": [
{
"dynamicSegment": {
"name": "Users of /apath/ofinterest/",
"userSegment": {
"segmentFilters": [
{
"simpleSegment": {
"orFiltersForSegment": {
"segmentFilterClauses": [
{
"dimensionFilter": {
"dimensionName": "ga:pagePath",
"operator": "EXACT",
"expressions": [
"/apath/ofinterest/"
]}}]}}}]}}}
],
"dimensions": [
{ "name": "ga:userAgeBracket" },
{ "name": "ga:segment" }
]
}
]
}
Which yield completely different results:
Only 2 age brackets, and weirdly, the same number of users in each (I tried with different time frame with the same behaviour).
Any ideas on what could be wrong? Could it be something in the settings of the segment? Related to "Sessions/User Include"?
Or could this warning below that I see in the UI have different impact in the UI and the API?
According to this comment, it sounds like numbers might be calculated differently for the API and the UI. Is that still the case?
Thanks a lot!

GA UI data is picked from the pre-aggregated tables.
Pre-calculated data -- pre-aggregated tables
These are the precalculated data that Google uses to speed up the UI. Google does not specify when this is done but it can be at any point of the time. These are known as pre-aggregated tables
So if you compare the numbers from GA UI to your GA API data, you will always see a discrepancy because the view might be aggregated at some early stages of the day, while your api data is fresh

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.

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

Retrieving previously calculated route [HERE Maps] using RouteeId fails with RouteNotReconstructed error

I'm calculating routes based on user input. Then storing the routeId and any additional informations I need. But the shape of the road is something I need occasionally; when the user wants to get a preview of the road again.
Since I don't want to store all the points from shape I tried using getroute endpoint (https://developer.here.com/documentation/routing/topics/resource-get-route.html#resource-get-route) but I get this response:
{
"_type": "ns2:RoutingServiceErrorType",
"type": "ApplicationError",
"subtype": "RouteNotReconstructed",
"details": "Error is NGEO_ERROR_ROUTE_DESERIALIZATION",
"additionalData": [
{
"key": "error_code",
"value": "NGEO_ERROR_ROUTE_DESERIALIZATION"
}
],
"metaInfo": {
"timestamp": "2018-08-01T15:01:56Z",
"mapVersion": "8.30.86.150",
"moduleVersion": "7.2.201830-34436",
"interfaceVersion": "2.6.34",
"availableMapVersion": [
"8.30.86.150"
]
}
}
So the question is: why do I get the error? Following the API documentation https://developer.here.com/documentation/routing/topics/resource-type-error-route-not-reconstructed.html I can exclude wrong routeId (it works for routes saved e.g. today but not for the older ones).
The route was calculated using the same version (7.2)
Is the routeId stored only for a certain amount of time?
If so, how long?
RouteID changes with map version.
https://developer.here.com/documentation/routing/topics/request-route-information.html
You'd need to recalculate periodically to get up to date RouteIDs.

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.

Google Analytics API - Get page view information for specific URLs

I am looking to implement a page view tracking system on one of my websites.
The website is a directory where suppliers can advertise their services. Suppliers have a unique profile page on the site, e.g mysite.com/directory/abc-profile.html
The idea is that suppliers can log in to their account area on the site and view stats on how many people are visiting their profile. Ideally I want to display this as :
Total views | Total today | This week | This month | This year
It does not matter if the data is not completely up to date.
I already have Google Analytics tracking code installed on the site. Is it possible to use the Google Analytics API to retrieve this data? If so, what kind of query do I need to make? I had a look on the documentation but could not figure whether the functions allow this or not.
I am using PHP and MySQL on the server.
Yes - you will need to use the Google Analytics API for this. I would suggest checking out the Query Explorer to get a feel for the queries you will need to create.
You will require numerous queries to get all the data you need (adjusting the starting date):
- Total Views
- This Year
- This Month
- This Week (i.e. last 7 days - from which you could also get Total Today).
Here is an example query:
https://www.googleapis.com/analytics/v3/data/ga?ids=ga:1234456789&dimensions=ga:pagePath&metrics=ga:pageviews&filters=ga:pagePath==/about-us.html&start-date=2013-10-15&end-date=2013-10-29&max-results=50
Alternatively, you might want to consider www.embeddedanalytics.com (disclosure - I work with them). We have a service/platform that allows website owners to embed GA based charts/statistics without having to learn the GA API. We have a CMS version which will do exactly what you need (where you script the call to pass the page path). We have done something like this with a number of podcast sharing sites.
Google suggests using Reporting API V4 now. The accepted answer uses V3.
Here is a V4 request example:
POST https://analyticsreporting.googleapis.com/v4/reports:batchGet?key={YOUR_API_KEY}
{
"reportRequests": [
{
"viewId": "YOUR_VIEW_ID",
"dimensions": [
{
"name": "ga:pagePath"
}
],
"metrics": [
{
"expression": "ga:pageviews"
}
],
"dimensionFilterClauses": [
{
"filters": [
{
"operator": "EXACT",
"dimensionName": "ga:pagePath",
"expressions": [
"/your-path"
]
}
]
}
],
"dateRanges": [
{
"startDate": "2009-12-31",
"endDate": "2016-09-28"
}
]
}
]
}
where
YOUR_API_KEY - for auth related things follow this page
YOUR_VIEW_ID - you can use the Account Explorer to find a View ID. (or Admin -> View -> View Settings -> View ID).
For more documentation details and a "Try it!" console follow this page.
You should be able to add a filter on the landing page. I am assuming that each user's site has its own start page. This returns only the data for that user. If you want the code on how to do this I suggest you google: Google analytics core reporting API PHP tutorial
Another idea would be to let the user add there Google Analytics account to there profile. Then you can output the google analytics code onto there page. Then they can track there own google analytics data and you won't need to deal with any of it.
Thought I would provide an updated version as the others are showing for V3 and V4 - for anyone using the latest API for Google Analytics Data API (GA4). This is just grabbing the total users, over a date range for a specific path.
Note that the POST is hitting the v1 beta address as this was the latest at the time.
POST https://analyticsdata.googleapis.com/v1beta/properties/PROPERTY_ID:runReport
{
"dateRanges": [
{
"startDate": "YYYY-MM-DD",
"endDate": "YYYY-MM-DD"
}
],
"dimensions": [
{
"name": "pagePath"
}
],
"dimensionFilter": {
"filter": {
"fieldName": "pagePath",
"stringFilter": {
"matchType": "CONTAINS",
"value": "/YOUR/PATH"
}
}
},
"metrics": [
{
"name": "totalUsers"
}
]
}

Resources