This page describes how to get started using
[AMPHTML ads](https://www.ampproject.org/learn/who-uses-amp/amp-ads/) with
RTB. Check out the following [Resources](https://developers.google.com/authorized-buyers/rtb/amp-ads#resources) for additional
information about AMPHTML ads and tools to help you get started.

## High-level approach

### RTB bid request

The RTB bid request indicates whether the request is coming from an AMP page
and the requirements for AMPHTML ads.

#### AMP page

The `BidRequest.site.ext.amp` field can be used to determine if
the request is coming from an AMP page. It can be set to the following values:

```
enum AmpPage {
  // This is not an AMP page.
  DIALECT_HTML = 0;

  // This is an Amp page.
  DIALECT_HTML_AMP = 1;
}
```

#### AMPHTML ad requirements

The `BidRequest.imp.ext.ampad` field can be used to determine the
requirements for AMP ads.

```
enum AmpAdRequirementType {
  // AMP ad requirements unknown.
  UNKNOWN_AMP_AD_REQUIREMENT_TYPE = 1;

  // AMP ads are not allowed.
  AMP_AD_NOT_ALLOWED = 2;

  // Either AMP ads or non-AMP ads are allowed;
  // AMP ads are not early rendered.
  AMP_AD_ALLOWED_AND_NOT_EARLY_RENDERED = 3;

  // Either AMP ads or non-AMP ads are allowed;
  // AMP ads are early rendered.
  AMP_AD_ALLOWED_AND_EARLY_RENDERED = 4;

  // AMP ads are required.
  // Ads that are non-AMP may be rejected by the publisher.
  AMP_AD_REQUIRED = 5;
}
```

### RTB bid response

The `BidResponse.seatbid.bid.ext.amp_ad_url` field accepts a URL
pointing to AMPHTML ad content.

### Verification of valid AMPHTML

For AMPHTML ads to be early rendered, the exchange is required to verify and
sign them, indicating that the ad is written in amp4ads `<html
amp4ads>` creative format.

Ads that are valid AMPHTML will be allowed to render early by AMP pages. Ads
that are not verified as valid AMPHTML will render at the same speed as
non-AMPHTML ads.

Only AMPHTML ads should be returned in the `amp_ad_url`.

In the future, if a publisher requires AMPHTML ads only, ads not signed as
AMPHTML won't be rendered.

With Authorized Buyers, bidders will still be charged if they return a
non-AMPHTML Ad to an AMPHTML ad-required adslot.

### Server-side fetch

For AMPHTML ads to be early rendered, AMPHTML ad content must be rendered
without requiring additional hops from the client. This is designed to avoid
poor user experiences due to ad latency and extra client-side calls.

After a bidder wins the auction, the exchange will perform a
server-to-server request to retrieve the AMPHTML ad content located at the URL
provided in `amp_ad_url`. Creative servers must respond and return
content within 300 ms.

The AMPHTML ad returned from the creative server will be injected into the
adslot and subsequently rendered. Note that a valid AMPHTML ad cannot contain
iframes or other `<amp-ad>` tags. See the [AMPHTML
ads spec](https://github.com/ampproject/amphtml/blob/master/extensions/amp-a4a/amp-a4a-format.md) for more details.

#### Beta only feature: Contact your account team if you require this

During server-to-server retrieval of the AMPHTML ad (specified in
`amp_ad_url`), Authorized Buyers may pass the HTTP header and IP
from the user's browser to the creative server. This ensures the creative
server receives information similar to that sent from a standard client-side
fetch. In some cases, the IP address may be truncated to only the first 3 bytes
(IPv4) or first 6 bytes (IPv6). Contact your account team if you require this
feature. Here is a sample HTTP header:
<button type="button" class="button-red button expand-control">Show Me</button>

```
Url: "http://amp.com"
Params {
  RequestorID: "harpoon-adx-amp-ads"
  UserAgentToSend: "Mozilla/5.0 Google-AMP"
  Referer: "amp-url.com"

  HTTPOptions {
    ExternalUserIPPacked: "12.345.67.890"
    AlwaysSendExternalUserIP: true
    Headers {
      key: "Accept-Language"
      value: "fr"
    }
    Headers {
      key: "Accept-Language"
      value: "en"
    }
  }
  CompressBody: false
}
```

### Impression tracking URLs and click macros

RTB buyers often include impression trackers as a structured field in the
bid response (this is `Bid.burl`, the "billing notice URL" in
OpenRTB 2.5).

With Authorized Buyers, these will be fired client-side; [amp-pixel](https://www.ampproject.org/docs/reference/components/ads/amp-pixel)
fires tracking URLs when the creative is rendered. [amp-analytics](https://www.ampproject.org/docs/reference/components/ads/amp-analytics)
can handle more advanced tracking use cases beyond rendering.

AMPHTML ads are required to contain a valid [click macro](https://support.google.com/authorizedbuyers/answer/3187591) in
the AMPHTML. This will typically take the form of something like this:

```
<a href="%%CLICK_URL_UNESC%%http%3A%2F%2my.adserver.com%2Fsome%2Fpath%2Fhandleclick%3Fclick%3Dclk"></a>
<a href="https://my.adserver.com/click?google_click_url=%%CLICK_URL_ESC%%"></a>
```

### Cookie matching

Creatives often include [cookie
matching](https://developers.google.com/authorized-buyers/rtb/cookie-guide#how-it-works) pixels within the creative code. AMPHTML ads can use the
[amp-pixel](https://www.ampproject.org/docs/reference/components/ads/amp-pixel)
and [amp-analytics](https://www.ampproject.org/docs/reference/components/ads/amp-analytics)
components for this use case. If your use case cannot be accommodated by using
`amp-analytics` or `amp-pixel`, open a
[GitHub issue](https://github.com/ampproject/amphtml/issues/new) to discuss
alternate options. We welcome new extensions that can be broadly used by
a number of different companies. See
[detailed
guidelines](https://github.com/ampproject/amphtml/blob/master/3p/README.md#embeds) or a
[technical
guide](https://github.com/ampproject/amphtml/tree/master/extensions) to building a new extension.

## Sample AMP Ad URLs for testing

You can use the following sample AMPHTML ad content for testing:

- [Banner ad](https://github.com/ampproject/amp-by-example/blob/master/src/amp-ads/20_Basic_Ads/Banner_Ad.html)
- [Carousel ad](https://github.com/ampproject/amp-by-example/blob/master/src/amp-ads/30_Advanced_Ads/Carousel_Ad.html)

## Resources

The AMP Project and Google have released a number of resources to help you get started:

Building ads in AMP
:
    - [AMPHTML
      ad Creative Format Spec (GitHub)](https://github.com/ampproject/amphtml/blob/master/extensions/amp-a4a/amp-a4a-format.md)
    - [AMPHTML
      ads Overview (GitHub)](https://github.com/ampproject/amphtml/blob/master/ads/google/a4a/docs/a4a-readme.md)
    - [AMPHTML ads
      Website from the AMP Project](https://www.ampproject.org/learn/who-uses-amp/amp-ads/)
    - [Example
      AMPHTML ads](https://ampbyexample.com/amp-ads/#amp-ads/introduction)
    - [Speed
      comparison](https://ampbyexample.com/amp-ads/introduction/amphtml_ads_vs_non-amp_ads/)---See how fast an AMPHTML ad loads in comparison to a regular ad. Best viewed on a 3G connection.

RTB-specific proposals to IAB / OpenRTB Group
:
    - [Discussion
      in OpenRTB Developer Forum](https://groups.google.com/forum/#!topic/openrtb-dev/0wyPsF5D07Q)