-1

I'm having a problem with the Google Analytics API returning data with missing dates. This only happens when I try and pull larger date ranges. As an example, I'm trying to replicate the Behavior > Site Content > All Pages report from the Google Analytics website in an external app.

When I request data over a larger date range (June 1 - December 30, 2017 in this use case), there is consistently data missing. Oddly the data missing is usually the last 10-15 days of each month. It works for shorter date ranges ( < 30 days), but this isn't going to work for my app. Has anyone else experienced this? I've attached a screenshot of the code.

api call code

Thanks for any help you can provide!

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
SSI
  • 1
  • 2
    Could you post an example response returned by Google Analytics? Preferably text, not a screenshot. – Mehdi Apr 24 '18 at 18:55

1 Answers1

1

This is more then likly an issue with sampling.

Google Analytics calculates certain combinations of dimensions and metrics on the fly. To return the data in a reasonable time, Google Analytics may only process a sample of the data.

You can specify the sampling level to use for a request by setting the samplingLevel parameter.

If a Core Reporting API response contains sampled data, then the containsSampledData response field will be true. In addition, 2 properties will provide information about the sampling level for the query: sampleSize and sampleSpace. With these 2 values you can calculate the percentage of sessions that were used for the query. For example, if sampleSize is 201,000 and sampleSpace is 220,000 then the report is based on (201,000 / 220,000) * 100 = 91.36% of sessions.

See Sampling for a general description of sampling and how it is used in Google Analytics.

You can set the sampling level in your request using

samplingLevel=DEFAULT

Unforuntaly you are using the Google Analytics v3 there is no way of knowing from the response data if the data you are seeing is sampled. However if you switch to Google analytics V4 the response tells you if the data it returned is sampled.

You should also note that it is very hard to get the exact results from the API that you are seeing on the Website. the website has difference sampling levels than we can see as developers and there is also a lot of internal calculations that goes into some of those reports. It can be nerve racking to try and get them to match up 100%

Community
  • 1
  • 1
Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449