Subhash Deshmukh
Subhash Deshmukh

Reputation: 360

Google Console Search API giving incorrect data

I am extracting Search Analytics data for some Property using search console API v3. I am using googleapiclient library(Python) for making API call. Python script making API request:

from googleapiclient import sample_tools

service, flags = sample_tools.init(['https://example.com/'], 'webmasters', 'v3', __doc__, __file__,
                                             # parents=[argparser],
                                              scope='https://www.googleapis.com/auth/webmasters.readonly')

rowlimit = 5000      #initialised variable to pass values of rowLimit and startRow
startrow = 0

request = {
               'startDate': '2017-05-10',
               'endDate': '2017-05-10',
               'dimensions': ['date','query'],
               'rowLimit': rowlimit,
               'aggregationType': 'byProperty',
               'startRow': startrow
}

response = execute_request(service, 'https://example.com/', request)

We are getting response. Now there is one limitation that we can not give rowLimit > 5000.

Now with each request we often don't get 5000 records. So for next iteration I am setting startRow value by record beyond what I got in first request.

i.e. startrow = startrow+record_count_in_first_request So, second iteration will have startRow:startrow
rowLimit:5000

Using this approach I can get all the result data for certain date range.

But now I am facing another issue. The metrics values that I extracted using API are not matching with console platform(UI) values.
I checked the sum of clicks, impression over a certain date range, it is not matching with UI values for same date range. Why do you think that happens?

Again this is the case when I use 'dimensions': ['date', 'query'] on the other hand when I use 'dimensions': ['date', 'page'] then I am getting correct result. I have checked the results with console UI. This behaviour of console search API is quite confusing. Does anybody faced similar issue before. Is there any sampling of data? Let me know if you need more information regarding the issue I am facing. Thanks for you time.

Upvotes: 1

Views: 1934

Answers (1)

baxang
baxang

Reputation: 3807

In short, when you use page in dimensions and you didn't specify aggregationType in your API call, then the aggregation type will be determined by the API service.

aggregationType determines how clicks and impressions are aggregated. When you use dimensions: date, query, the API will use byProperty aggregation type by default while date, page automatically choose byPage type. It is documented here.

Please have a read on this documentation for the difference between byProperty (or site) and byPage.

Upvotes: 1

Related Questions