Common pitfalls

The AdSense Management API has calls to generate new and saved reports. They can contain simple analytics like earnings per day or very complex tables of click-through rates per custom channel per country. This guide presents a list of edge cases that should be correctly handled for a robust integration with the APIs.

Report structure

Report results are returned as a ReportResult object. See the report response reference for full detials.

Using chronological dimensions: DATE, WEEK, and MONTH

Reports can be empty or have gaps

If there was no activity during the time period specified in the request, no ad requests are generated and the report service won't show rows for those time periods. This is important if you are, for example, plotting a graph.

Check out the Filling in Dates guide for more information.

Requesting MONTH and WEEK dimensions in the same report

This report can have negative or unexpected consequences. If a week belongs to two different months, it will show two rows for the same week, one for each month.

Example

DimensionsMetricsStart dateEnd date
WEEK
MONTH
CLICKS2014-04-28 2014-05-03
Returns:
MONTHWEEK*CLICKS
2014-04 2014-04-27 50
2014-05 2014-04-27 43

* first day of the week

Solution

Remove MONTH from the report.

WEEKCLICKS
2014-04-27 93

Collating dimension values

When requesting dimensions like the ones related to, for example, platforms (desktop, high-end mobile devices, etc.), only the platforms with activity will be shown. If a given day, week, or month has no visits from high-end mobile devices, it will have no information for that category.

Example

DimensionsMetricsStart dateEnd date
PLATFORM_TYPE_NAME
MONTH
AD_REQUESTS 2014-02-012014-03-31
Returns:
MONTHPLATFORM_TYPE_NAMEAD_REQUESTS
2014-03 Desktop 100
2014-03 High-end mobile devices 5
2014-04 Desktop 75
Solution

When processing the report results, assume a value of zero for any dimension values that do not appear in the results:

MONTHPLATFORM_TYPE_NAMEAD_REQUESTS
2014-03 Desktop 100
2014-03 High-end mobile devices 5
2014-04 Desktop 75
2014-04 High-end mobile devices 0

Combining multiple contiguous reports

Sometimes a report is too large to be generated all at once and it has to be batched. If your app does this, consider these cases:

  • If you're using WEEK or MONTH dimensions and you're splitting the report in the middle of a week or month, each report will have duplicated entries with different data.
  • Make sure all the reports have the same metrics and dimensions, as data might not be combinable using different dimensions.

Special accounts

Some of your users might have AdSense accounts with attributes that you don't expect or know about. Make sure to take into account:

  • Publishers with thousands of domains or sites
  • Publishers with thousands of ad units or custom channels
  • Publishers that would like to report on multiple ad clients (AdSense for Search, AdSense for Video, etc.)

Multiple accounts

Users can have access to more than one AdSense account. An account ID has to be specified for every call to the API for this reason. A call to accounts.list fetches a list of accounts and an account chooser dialog should be displayed to the user. It can be bypassed if the number of fetched accounts is one.

Time zone changes

AdSense Publishers can change their timezone at any time and this can produce spikes or dips in the reports. Read the guide about Local Time Zone Reporting for more information.