Process the Request

A real-time bidding interaction begins when Google sends a bid request to your application. This guide explains how to code your application to process the bid request.

Parse request

Google sends a bid request as a serialized protocol buffer attached as the binary payload of an HTTP POST request. The Content-Type is set to application/octet-stream. See Example bid request for an example.

You must parse this request into an instance of the BidRequest message. BidRequest is defined in realtime-bidding.proto, which can be obtained from the reference data page. You can parse the message using the ParseFromString() method in the generated class for the BidRequest. For example, the following C++ code parses a request given a POST payload in a string:

string post_payload = /* the payload from the POST request */;
BidRequest bid_request;
if (bid_request.ParseFromString(post_payload)) {
  // Process the request.
}

Once you have the BidRequest you can then work with it as an object, extracting and interpreting the fields you need. For example, in C++:

for (int i = 0; i < bid_request.adslot_size(); ++i) {
  const BidRequest_AdSlot& adslot = bid_request.adslot(i);
  // Decide what to bid on adslot.
}

Some information sent in a BidRequest, such as the Google User ID, language, vertical classification, and geographic location, is not always available. If you have pretargeting ad groups that use information that is unknown for a given impression, then those ad groups will not match. In cases where the missing information doesn't matter for the pretargeting conditions, bid requests are sent with the information omitted.

Information about the pretargeting ad group is available in the MatchingAdData group for each AdSlot. It currently contains the first matching ad group id of the pretargeting ad group that prompted us to send out a bid request. That is the ad group and campaign that will be charged if your response wins the auction for the impression. Under certain circumstances, you need to explicitly specify the billing_id for attribution in BidResponse.AdSlot, e.g., when the BidRequest.AdSlot has more than one matching_ad_data. For more information on the constraints on the contents of the bid, refer to therealtime-bidding.proto.

Dictionary files

The bid request uses identifiers defined in dictionary files, which are available on the reference data page.

Content labels

Content labels inform buyers about the characteristics of the inventory that is up for bid—whether its content includes profanity, or touches on crime or military conflict, among other things. The detected_content_labels field in the BidRequest contains values which correspond to content labels. For example, the value 23 indicates "Social networks." The complete list of content labels and the values that stand for them is defined in the content-labels.txt file, available from the reference data page.

If no content labels have been applied to the inventory described by a BidRequest, the BidRequest omits the detected_content_labels field. If multiple labels have been applied, the field contains multiple values.

You can use pretargeting to ensure that Google sends you bid requests for the impressions that are most appropriate for you. Content labels can be among the attributes you use in pretargeting.

Bid URL macros

Optionally, some fields of the BidRequest can be inserted into the URL used in the HTTP POST request. This is useful, for example, if you use a light-weight front end that load balances over multiple backends using a value from the request. Contact your technical account manager to request support for new macros.

MacroDescription
%%GOOGLE_USER_ID%%

Replaced with the google_user_id from the BidRequest. For example, the bidder URL

http://google.bidder.com/path?gid=%%GOOGLE_USER_ID%%
will be replaced by something like
http://google.bidder.com/path?gid=dGhpyBhbiBleGFtGxl
at request time.

If the Google User ID is unknown, the empty string is substituted, with a result similar to

http://google.bidder.com/path?gid=
%%HAS_MOBILE%%

Replaced with 1 or 0 when calling BidRequest's has_mobile().

%%HAS_VIDEO%%

Replaced with 1 (true) or 0 (false) when calling BidRequest's has_video().

%%HOSTED_MATCH_DATA%%

Replaced with the value of the hosted_match_data field from the BidRequest.

%%MOBILE_IS_APP%%

Replaced with 1 (true) or 0 (false) from BidRequest's mobile.is_app field.

Adapting to deprecated fields

At any time, some fields in the BidRequest may appear with the prefix DEPRECATED_. This means that after a specified period of time those fields will no longer appear in the BidRequest. The exact period of time in each case—called a notification period—is announced in Release Notes, blog posts, and the email newsletter. During the notification period, you should update your bidder code to remove any dependencies on deprecated fields. Otherwise, your bidder may rely on information from the BidRequest that is no longer being sent.

Deprecated fields (updated May 1, 2013)

The fields in the following table are no longer being sent:

Message Field
BidRequest protocol_version
excluded_click_through_url
company_name
country
region
city
metro
Mobile submessage of the BidRequest (Formerly called the MobileApp submessage) app_name
company_name
carrier_name
carrier_country
MatchingAdData submessage of the BidRequest campaign_id

The following table describes fields in the BidRequest that have been deprecated:

Message Field
MatchingAdData submessage of the BidRequest buyer_minimum_cpm
fixed_cpm_micros
Ad submessage of BidRequest allowed_attribute
publisher_settings
excluded_click_through_url
BidRequest protocol_version
click_tracking_url
cookie
hashed_cookie
excluded_click_through_url
seller_network
publisher_settings
MatchingNetwork network_id
google_user_id

Find mobile app ID from transaction URL

Mobile application transactions will report URLs that look like this:

mbappgewtimrzgyytanjyg4888888.com

You'll have to base-32 decode the portion of the string in bold (gewtimrzgyytanjyg4888888).

You can use an online decoder but you'll have to capitalize the letters and replace trailing 8s with = values.

So, you would decode this value:

GEWTIMRZGYYTANJYG4======

Which results in:

1-429610587

The string 429610587 is the app ID for the iOS app iFunny.

Here's another example. The reported URL is:

mbappgewtgmjug4ytmmrtgm888888.com
Decode this value:
GEWTGMJUG4YTMMRTGM======

The result is:

1-314716233

The result 314716233 is the app ID for the iOS app TextNow.

Find mobile app name from transaction URL

Here's an example of getting the app name. The reported URL is as follows:

mbappMFUXELTDN5WS42DZOBQWQLTJN4XHG3DJORUGK4Q888.com

You would decode this value:

MFUXELTDN5WS42DZOBQWQLTJN4XHG3DJORUGK4Q===

The result is:

air.com.hypah.io.slither

The result equates to the Android app slither.io.

Open Bidding fields

Bid requests sent to exchange and network bidders participating in Open Bidding are similar to those of Authorized Buyers participating in standard real-time bidding. Open Bidding customers will receive a small number of additional fields, and a few existing fields may have alternative uses. These include the following:

OpenRTB Authorized Buyers Details
BidRequest.imp[].ext.dfp_ad_unit_code BidRequest.adslot[].dfp_ad_unit_code

Contains the publisher's Ad Manager network code followed by the ad unit hierarchy, separated by forward slashes.

As an example, this would appear with formatting similar to: /1234/cruises/mars.

BidRequest.user.data[].segment[] BidRequest.adslot[].exchange_bidding.key_value[]

Repeated key-value pairs sent from publisher to exchange bidder.

For OpenRTB, note that this can also represent detected verticals. You can determine that the values are key-value pairs sent by the publisher when BidRequest.user.data[].name is set to “Publisher Passed”.

BidRequest.imp[].ext.buyer_generated_request_data BidRequest.adslot[].buyer_generated_request_data

Data, generated by the buyer's SDK within the publisher’s mobile app. This is sent to Open Bidding customers that use their own SDK, as opposed to the Google Mobile Ads SDK.

BidRequest.app.ext.installed_sdk[] BidRequest.mobile.installed_sdk[]

Identification and details about the SDK installed in the publisher’s app that the bidder has access to. This is sent to Open Bidding customers that use their own SDK, as opposed to the Google Mobile Ads SDK.

In order for your SDK to appear in this field, you must contact your Technical Account Manager in order to link your SDK to your account.

Declare allowed vendors

Technology vendors which provide services such as research, remarketing, and ad serving may play a role in the interaction between buyers and sellers. Only vendors which Google has vetted for participation in Authorized Buyers interactions are allowed.

To understand the BidRequest and create your BidResponse, you need to be aware of the two different possibilities for declaring technology vendors:

  1. Some vendors do not need to be declared; these vendors are listed in the Authorized Buyers Help.
  2. Other vendors can only participate if they are declared in both the BidRequest and BidResponse:
    • In the BidRequest, the allowed_vendor_type field specifies which vendors the seller allows. Vendors that will be sent in the allowed_vendor_type field of the BidRequest are listed in the Vendors.txt dictionary file.
    • In the BidResponse, the vendor_type field specifies which of those allowed vendors the buyer intends to use.

Example bid request

The following examples represent human-readable samples of the Protobuf and JSON requests.

Google

OpenRTB JSON

OpenRTB Protobuf

To convert the bid request into a binary form, like you would get from the POST payload in a real request, you can do the following (in C++). Note, however, that this is not applicable to OpenRTB JSON.

string text_format_example = /* example from above */;
BidRequest bid_request;
if (TextFormat::ParseFromString(text_format_example, &bid_request)) {
  string post_payload;
  if (bid_request.SerializeToString(&post_payload)) {
    // post_payload is a binary serialization of the protocol buffer
  }
}

Remarketing

Authorized Buyers passes a mobile advertising ID in bid requests from a mobile application. The mobile advertising ID can be an iOS IDFA or Android's advertising ID, which is sent via the %%EXTRA_TAG_DATA%% macro in the JavaScript tag managed by Authorized Buyers.

The %%ADVERTISING_IDENTIFIER%% macro allows buyers to receive iOS IDFA or Android's Advertising ID on impression rendering. It returns an encrypted proto buffer MobileAdvertisingId like %%EXTRA_TAG_DATA%%:

message MobileAdvertisingId {
  optional bytes advertising_id = 1;
  optional int32 user_id_type = 2;
}

The user_id_type is one of the values defined in the enum AdxMobileIdType:

enum AdxMobileIdType {
  MOBILE_ID_UNKNOWN = 0,
  IDFA = 1,
  ANDROID_ID = 2,
};

You can create user lists from mobile advertising IDs using advertising IDs you've collected during impression rendering. These user lists can be maintained on your server or on ours. To create user lists on Google's servers you can use our bulk upload facility.

When the mobile advertising ID matches a user list, you can use it to run remarketing.

Real-time feedback

Real-time feedback is available to Authorized Buyers, as well as exchanges and networks using Open Bidding.

Bid response feedback is supported on the subsequent bid request for both AdX Protocol and OpenRTB. For OpenRTB, it is sent in BidRequestExt.

In addition to the default fields sent in Bid Response Feedback, you can also send custom data in the bid response (in either AdX Proto or OpenRTB) using an event_notification_token that is returned in the BidResponse. The event_notification_token is arbitrary data known only to the bidder that might help with debugging, for example: a new targeting ID or bidding ID representing a new tactic, or metadata associated with the creative known only to the bidder. For details, see OpenRTB Extensions Protocol Buffer for RTB and AdX Proto for AdX.

When Authorized Buyers sends a bid request to a bidder, the bidder replies with a BidResponse. If the bidder has real-time feedback enabled, then in a subsequent bid request, Authorized Buyers sends feedback on the response in a BidResponseFeedback message, as shown below:

// Feedback on bids submitted in previous responses. This is only set if
// real-time feedback is enabled for your bidder. Please contact your account
// manager if you wish to enable real-time feedback.
//
message BidResponseFeedback {
  // The unique id from BidRequest.id
  optional bytes request_id = 1;

  // The index of the BidResponse_Ad if there was more than one. The index
  // starts at zero for the first creative.
  optional int32 creative_index = 2;

  // The status code for the ad. See creative-status-codes.txt in the
  // technical documentation for a list of ids.
  optional int32 creative_status_code = 3;

  // If the bid won the auction, this is the price paid in your account
  // currency.  If the bid participated in the auction but was out-bid, this
  // is the CPM that should have been exceeded in order to win.  This is not
  // set if the bid was filtered prior to the auction, if the publisher or
  // winning bidder has opted out of price feedback or if your account has
  // opted out of sharing winning prices with other bidders. For first price
  // auctions, minimum_bid_to_win is also populated.
  optional int64 cpm_micros = 4;

  // The minimum bid value necessary to have won the auction, in micros of
  // your account currency. If your bid won the auction, this is the second
  // highest bid that was not filtered (including the floor price). If your
  // bid did not win the auction, this is the winning candidate's bid. This
  // field will only be populated if your bid participated in a first-price
  // auction, and will not be populated if your bid was filtered prior to the
  // auction.
  optional int64 minimum_bid_to_win = 7;

  // Event notification token that was included in the bid response.
  optional bytes event_notification_token = 5;

  // Buyer creative ID that was included in the bid response.
  optional string buyer_creative_id = 6;
}
repeated BidResponseFeedback bid_response_feedback = 44;

From this message, the first field you should check is bid_response_feedback.creative_status_code; you can find the code meaning in creative-status-codes.txt. Note that if you win the bid, you can opt out from the price feedback. For more information, see How to opt-out.

The real-time feedback includes the bid request ID and one of the following:

Auction outcome Real-time feedback
The buyer didn't submit a bid. Nothing.
The buyer submitted a bid that was filtered out before reaching the auction. The creative status code (see creative-status-codes.txt).
The buyer submitted a bid but lost the auction. The creative status code 79 (outbid in auction).
The buyer submitted a bid that won the auction. The clearing price and creative status code 1.

Bid flattening

Bid flattening describes the processing of a single complex BidRequest into multiple bid requests that are sent to your application. Because they retain identical IDs (BidRequest.google_query_id in the Authorized Buyers RTB Protocol or BidRequestExt.google_query_id in the OpenRTB protocol) you can determine which bid requests are correlated after flattening.

Video pods

Bid requests for a video pod with multiple ad opportunities are flattened, such that each bid request is for an individual ad opportunity from that pod. This enables you to bid on multiple ad opportunities for a given pod.

Deals

An ad opportunity for a given bidder can be applicable to various deal types, in addition to the open auction. With bid flattening for deals, one bid request will be sent for the open auction, and one for each type of fixed-price deal. In practice, ad constraints can differ between auctions and fixed-price deal types—for example, for a given video ad opportunity that is available to both the open auction and a fixed-price deal, a bidder will receive distinct bid requests for each where constraints such as maximum ad duration and whether skippable ads are allowed can differ. As a result, flattening applied to the ad opportunity allows you to more easily discern the ad constraints for the open auction and the fixed-price deal.

Open Measurement

Open Measurement allows you to specify third-party vendors that provide independent measurement and verification services for ads served to mobile app environments.

You can determine whether a publisher supports Open Measurement in the bid request by checking whether the ad opportunity excludes the OmsdkType: OMSDK 1.0 attribute found in Publisher-excludable creative attributes. For the Authorized Buyers protocol, this would be found under BidRequest.adslot[].excluded_attribute. For the OpenRTB protocol, this would be found under the battr attribute for Banner or Video, depending on the format.

For more information on how to interpret bid requests containing Open Measurement signals, refer to the Open Measurement SDK Help Center article.

Sample bid requests

The following sections show sample bid requests for different ad types.

App banner

The following sections show sample bid responses for different ad types.

Google

OpenRTB JSON

OpenRTB Protobuf

App Interstitial

Google

OpenRTB JSON

OpenRTB Protobuf

App interstitial video

Google

OpenRTB JSON

OpenRTB Protobuf

App native

Google

OpenRTB JSON

OpenRTB Protobuf

Web video

Google

OpenRTB JSON

OpenRTB Protobuf

Mobile web video and banner

Google

OpenRTB JSON

OpenRTB Protobuf

Mobile web banner for exchange bidder

OpenRTB Protobuf

Open Bidding third-party SDK rendered ad

OpenRTB JSON

Send feedback about...

Real-Time Bidding
Real-Time Bidding