Google Analytics API not returning same data as An

2019-05-10 13:24发布

问题:

I'm trying to write a Google Analytics API query that simply returns the monthly unique visitors for each month over the last year.

This is the data I see in the Google Analytics dashboard.

I've used the Analytics API explorer to write the query, I've verified the ID and account is authed correctly. I'm using the ga:month dimension to get the data month-by-month.

This is the query, and the resultant data

These numbers are nothing at all like the ones I see on the Analytics dashboard.

This is a graph of that data.

I'm very confused. I can't see what is different between what I specify in the Google Analytics dashboard and what I've entered in the API query, or why I should get such wildly different numbers.

Edit: I've deduced that the problem lies when the start and end date span across 2013 to 2014. If my start and end date are both in 2013, the numbers are correct. But if it spans across from 2013 to 2014, the numbers are incorrect. Not sure how to fix it.

回答1:

I suspect you are having an issue with Sampling level

samplingLevel

samplingLevel=DEFAULT 
Optional.Use this parameter to set the sampling level (i.e. the number of visits 
used to calculate the result) for a reporting query. The allowed values are consistent
 with the web interface and include: 
•DEFAULT — Returns response with a sample size that balances speed and accuracy.
•FASTER — Returns a fast response with a smaller sample size.
•HIGHER_PRECISION — Returns a more accurate response using a large sample size, but 
 this may result in the response being slower.

If not supplied, the DEFAULT sampling level will be used.