Batch

Sometimes it’s not possible to get all the information you need out of a single report, such as when you have incompatible dimensions and metrics, or when you’re looking to aggregate data in different ways.

In those situations, you’ll need to run multiple reports.

Also, batching is an effective way to improve your app’s performance, reducing the number of requests.

The problem with making multiple independent requests

While a simple solution to implement, making multiple API requests in a short amount of time may cause you to run into quota limitations.

Quota is typically limited to 1 request per user per second. This value can be configured in the Google API Console, but the best solution is to avoid the parallel requests altogether, and instead create batch requests.

Report batching

In the example of a user-driven application, a first approach would be to combine as many independent requests as possible into a single batch request.

Report 1: Top 10 countries for August
Report 2: Values for same 10 countries in July, for comparison
Report 3: Top 10 channels for August
Report 4: Values for same 10 channels in July, for comparison

In the above example, reports 1 and 3 are independent, but cannot be combined into a single report, since they offer different breakdowns of the data. They can, however, be batched together.

Reports 2 and 4 can only be run after obtaining the results of the first batch, since we need to set up an appropriate filter in the request. These can be run as a second batch, once the results from the first arrive.

A different option, which would allow all requests to be combined into a single batch, would be to simply return all values for July (instead of just the top 10), and potentially August as well. This may be a reasonable option depending on the size of the AdSense account in question and the amount of memory available to your application.

How it's done

Batching is handled differently in each client library, so you should check its documentation in order to find out the details. Here are some links to the relevant documentation in several client libraries:

Next steps