I've been having issues with the Google Analytics (GA) API over the past several weeks. Our application regularly (every 2h) queries the GA API for visitor numbers from clients of ours.
However, sometimes the GA API suddenly returns only 0s for page metrics that previously provided data. This doesn't happen for all websites, only for a few, occasionally. The problem always starts around midnight (GMT) and persists for up to 24 hours.
It definitely isn't a quota error, as we would have caught that. In fact, Google's API doesn't return any error at all, it just returns 0s for all requested metrics.
Has anyone experienced this issue before? How can I solve this as it's bit of a show stopper.
In the hope this also helps other people I found the answer to my question by scouring the documentation:
https://support.google.com/analytics/answer/1070983?hl=en
Processing latency is 24-48 hours. Standard accounts that send more
than 200,000 sessions per day to Google Analytics will result in the
reports being refreshed only once a day. This can delay updates to
reports and metrics for up to two days. To restore intra-day
processing, reduce the number of sessions you send to < 200,000 per
day. For Premium accounts, this limit is extended to 2 billion hits
per month.
i.e if you are querying a non premium google analytics account with more than 200,000 visitors per day you can expect there to be intermittent lags in results for the last 48 hours. This issue was observed by us as google returning 0's, rather than some error.
This makes sense from Google's perspective as data processing = cost, as such it makes sense to leave processing for large sites (which are not paying for GA anyway) for when servers are loaded less heavily.
Related
We are using google analytics on our website to record the statistics. however, we need to show the total visits is it possible to show from google analytics API? TIA
Im not sure where you want to show the total visits but if its on your website you need to remember a few things about the Google Analytics api.
The first being that there is a data latency which means that it takes between 24 -48 hours for your data to complete processing. If you attempt to request say the current visits for today then the number will not be correct. You could request the number of vists for say three days ago and get back a number that is stable.
The other issue you are going to have is with quota. If you intend to load this from the API everytime a user visits your website they you will quickly run out of quota as you can only make 10k requests against a view in a single day so depending upon how many times this page is loaded this may not work for you.
An idea would be to load the data once at night and store the data in your database some place and then load from that as then you are only making a single request to the api and are unlikely to run out of quota.
Google anlaytics reporting api v4
Yes, just get ga:sessions metric defining the time interval that interests you.
Core Reporting API: https://developers.google.com/analytics/devguides/reporting/core/v3/common-queries
The Dimensions & Metrics Explorer lists: https://ga-dev-tools.appspot.com/dimensions-metrics-explorer/
I've got an API query that pulls Acquisition/Channel data by day, users, sessions, bounce rate, etc. Historically, I tie out exactly to the data shown at the GA site.
I've built a new report that analyzes our same-day sales, and find that all my numbers are much higher than that shown on the GA site. This was the situation yesterday, and now my data, pulled this morning, ties out.
I haven't seen the GA site update our numbers in hours, but my GA API data is changing on each pull.
Is this expected behavior? Have others seen similar things?
Data going into GA and pulled from the API is not real-time. There is a processing latency with data processing that could be 24-28 hours.
Here i have got JSON values from this i have used in query core explore but i got 0 value
{"kind":"analytics#gaData","id":"https://www.googleapis.com/analytics/v3/data/ga?ids=ga:181407717&metrics=ga:pageviews,ga:uniquePageviews&start-date=7daysAgo&end-date=today","query":{"start-date":"7daysAgo","end-date":"today","ids":"ga:181407717","metrics":["ga:pageviews","ga:uniquePageviews"],"start-index":1,"max-results":1000},"itemsPerPage":1000,"totalResults":1,"selfLink":"https://www.googleapis.com/analytics/v3/data/ga?ids=ga:181407717&metrics=ga:pageviews,ga:uniquePageviews&start-date=7daysAgo&end-date=today","profileInfo":{"profileId":"181407717","accountId":"125404806","webPropertyId":"UA-125404806-1","internalWebPropertyId":"183966900","profileName":"All Web Site Data","tableId":"ga:181407717"},"containsSampledData":false,"columnHeaders":[{"name":"ga:pageviews","columnType":"METRIC","dataType":"INTEGER"},{"name":"ga:uniquePageviews","columnType":"METRIC","dataType":"INTEGER"}],"totalsForAllResults":{"ga:pageviews":"4","ga:uniquePageviews":"2"},"rows":[["4","2"]]}
totalsForAllResults":{"ga:pageviews":"4","ga:uniquePageviews":"2"},"rows":[["4","2"]]}
Your request appears to returning results just fine. if these aren't the numbers you were expecting then you may want to consider the following as you have added today in your request.
The Google analytics core reporting api is for extracting data from Google analytics it is not intended for extracting resent data from Google analytics as It takes 24 - 48 hours for the data to be processed on the servers.
Data latency
Data processing latency
Processing latency is 24-48 hours. Standard accounts that send more than 200,000 sessions per day to Analytics will result in the reports being refreshed only once a day. This can delay updates to reports and metrics for up to two days. To restore intra-day processing, reduce the number of sessions your account sends to < 200,000 per day.
Try doing the same request but do it for a few days ago. or try using the Google antlyics realtime api which only displays the last five minutes of data give or take.
I am using a WordPress plugin on my website to show the actual views on each post, pulling the number from Google Analytics. The plugin uses the Analytics API.
At first, it worked great. However, a few hours in, I run into an error that I have exceeded the daily request limit. The error didn't go away until the quota reset at midnight pacific time.
The thing is, I checked my quotas at the console, and I had made barely more than 10,000, nowhere near the 50,000 limit.
Quota
I was thinking of requesting to increase the quota, but since I am nowhere near the 50,000, this does not seem to be a solution. Let alone that to request an increase I should have been at about 80% of the current quota.
To avoid the problem, I can have the plugin check the post views every four hours, instead of every hour, through the plugin's settings. But, since I am supposed to have 50000 daily queries, I would prefer to update the views on an hourly basis.
I understand that the current quota at the Google Developer console is a estimate it is not 100% accurate. But could it be so much off, showing 10k when the real number is 50k?
Should I ask for an extension?
You're most likely hitting the profile quota limit, which cannot be increased.
More information here
The 10,000 requests per view (profile) per day or the 10 concurrent requests per view (profile) cannot be increased.
I am using the Analytics API to get the number of sessions from the previous day. I run this code at 5am.
When I get to the office at 9am, querying the API again (or seeing the analytics
interface) returns me a higher number then the one I got at 5am.
So, how long does Analytics take to update data from day before? Is this the issue or could it be something else? I was thinking could be something timezone related, but after getting my head through it, now, I think it can't.
Thanks
It takes between 24 and 48 hours for data to finish processing in Google Analytics. This is true for both the Google Analytics API and the Google Analytics website. Although the website might get data before the API but I have been unable to prove this because by the time you make the request again both have changed. Its probably not related to time zone its from the time the hit was recorded.
Data limits
Data processing latency Processing latency is 24-48 hours. Standard
accounts that send more than 200,000 sessions per day to Analytics
will result in the reports being refreshed only once a day. This can
delay updates to reports and metrics for up to two days. To restore
intra-day processing, reduce the number of sessions your account sends
to < 200,000 per day. For Premium accounts, this limit is extended to
2 billion hits per month.