AdSense Management API

Getting Started

This document is for developers who want to use the AdSense Management API to get information about their AdSense account. This document assumes that you're familiar with web programming concepts and web data formats.

Contents

Before you start

Get an AdSense account

You need an AdSense account for testing purposes. If you already have a test account, then you're all set; you can visit the AdSense user interface to set up, edit, or view your test data.

Get familiar with AdSense

If you're not familiar with AdSense concepts read the introductory information on AdSense and experiment with the user interface before starting to code.

Choose your client library

In the Client Libraries and Samples page you’ll find information on the available libraries and samples. Click the tab for your chosen language and follow the links to download the source. The client libraries handle the following for you:

  • authentication
  • discovery of services
  • building the requests to the API
  • response parsing

Read the instructions to install and configure your chosen client library, typically found in the README file in the root directory of the repository.

If your implementation has special needs, such as using an unsupported language, you can make direct requests to the API instead of using a client library.

Register your application

To use the AdSense Management API you must register the application you're developing with Google:

  1. Go to the APIs Console.
  2. Either sign into your Google account or create an account.
  3. Create a new project.
  4. In your newly created project, click the Activate button under the AdSense Management API.
  5. Go to the API Access section.
  6. Create a Client ID:
    1. Web application, if your implementation lives in a web server.
    2. Installed application, for everything else.

    Note: Service Accounts are not supported as they access protected data.

  7. Edit the configuration files for your client library project with the new credentials you just created. Check the client library documentation for more details.

Note: The Google account used for registration should be your developer account, that is, the account that you wish users of your application to see as the developer of the application. This account does not need to be tied to an AdSense login, as users will be granting access to their own accounts while using the application.

Quick start tutorial

Follow the steps below to make your first requests, note that these steps may vary slightly depending on the library or language you are using:

  1. Use the appropriate sample to retrieve a list of ad clients from an AdSense account. This request initiates a one-time process in which the AdSense user authenticates and authorizes your project.

    Ad clients represent an association between an AdSense account and an AdSense product, such as Content Ads or Search Ads. An AdSense account can have one or multiple ad clients.

    1. For web applications, users will be redirected to a site where they can choose to grant access. Once authorized, they will be redirected to the callback URL defined in the APIs console.
    2. Installed applications work similarly. The client library will try to open a browser window and use an authorization code. For Android, Chrome and iOS applications this method is platform-specific.
  2. Use the APIs explorer in reports.generate to request the following report:
    • startDate: today-1m
    • endDate: today
    • dimensions: DATE
    • metrics: EARNINGS

    Reports give you insight into what you're earning, as well as what's having an impact on those earnings. They can be run on an entire account or on a subset of ad units, through the use of channels.

  3. Try to request the same report from your application.
  4. You can filter the reports by ad units. Fetch the list of ad units using adunits.list. Note that an ad client ID is needed (get it from step 1). After you choose an ad unit, use its ID in the filter parameter for reports.generate:

    Ad Units are user-configured placeholders for ads, that define some properties for the ads being shown (such as size and shape).

    • startDate: today-1m
    • endDate: today
    • dimensions: DATE
    • metrics: EARNINGS
    • filter: AD_UNIT_ID==ca-pub-123456789:987654321
  5. Try filtering by custom or URL channels or mixing multiple filters.

    Channels are tools that let you track the performance of a subset of your ad units. There are two types of channels: URL and custom. The former lets you track performance across a specific page or domain, whereas the latter help you track performance on specific user-selected groups of ad units.

You are ready to start your implementation by exploring the rest of the available calls and resources in the reference documentation.

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.