Ad tags

The AdSense ad tag enables ad serving, and attributes traffic correctly to your sub-accounts.

Ad tag parameters

There are two required parameters in the ad tag that you need to modify. These parameters determine ad serving settings, and the sub-account used for the ad request. Set these parameters to specify your platform publisher ID and the sub-account publisher ID. There are other additional parameters that can be modified depending on the ad format used.

Parameter Is required? Description and example
data-ad-client Yes The sub-account property ID (string). This value is provided via the APIs in the displayName field, or the last segment of the name field. This value is required to attribute traffic correctly to the sub-accounts.

For AdSense for content ads, prepend this string with "ca-".

Note that it also appears in the source URL of the script tag under the parameter name client.

Example:
data-ad-client="ca-pub-1234"
src=".../adsbygoogle.js?client=ca-pub-1234&host=ca-host-pub-5678"
data-ad-host Yes This is your platform's host property ID (string). This value identifies your platform's AdSense account and is required to initiate ad serving.

For AdSense for content ads, prepend this string with "ca-host-".

Note that it also appears in the source URL of the script tag under the parameter name host.

Example:
data-ad-host="ca-host-pub-5678"
src=".../adsbygoogle.js?client=ca-pub-1234&host=ca-host-pub-5678"
data-ad-slot No for Display ad units

Yes for other ad unit formats
This is the ID associated with an ad unit. For Display ad units, this ID is optional, but for other ad unit formats this is a required field. When the ad unit ID is present, settings associated with the ad unit are used during ad serving. During serving, we look for this ad unit ID in both the platform (data-ad-host) and (data-ad-client) sub-accounts. This parameter is also used to populate the Ad units report in AdSense (the report will only be populated in the account that the ad unit exists in).
data-ad-host-channel No This is used for reporting purposes. See the reporting section for more information.

Important: If the data-ad-client parameter is not present in your ad code, AdSense will continue ad serving using the value provided by the data-ad-host parameter. However, the traffic won't be attributed to the sub-account. Make sure that you place the correct data-ad-client publisher ID in the code tag to avoid attributing traffic to the wrong account.

Ad code examples

Below you'll find a code example for each ad type that AFP supports. Learn more about ad units and Auto ads in AdSense.

Display ad unit code (responsive)

<script async
     src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1234&host=ca-host-pub-5678"
     crossorigin="anonymous">
</script>
<ins class="adsbygoogle"
     style="display:block;"
     data-ad-client="ca-pub-1234"
     data-ad-host="ca-host-pub-5678"
     data-ad-format="auto">
</ins>
<script>
   (adsbygoogle = window.adsbygoogle || []).push({});
</script>

Display ad unit code (fixed size)

<script async
     src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1234&host=ca-host-pub-5678"
     crossorigin="anonymous">
</script>
<ins class="adsbygoogle"
     style="display:inline-block;width:728px;height:90px"
     data-ad-client="ca-pub-1234"
     data-ad-host="ca-host-pub-5678">
</ins>
<script>
   (adsbygoogle = window.adsbygoogle || []).push({});
</script>

Display AMP ad unit (responsive)

The following code needs to be placed in the <head> of the page:

<script async custom-element="amp-ad" src="https://cdn.ampproject.org/v0/amp-ad-0.1.js"></script>

And this is the snippet for the ad unit, placed in the <body>:

<amp-ad
  width="100vw"
  height="320"
  type="adsense"
  data-ad-client="ca-pub-1234"
  data-ad-host="ca-host-pub-5678"
  data-ad-slot=""
  data-auto-format="rspv"
  data-full-width="">
  <div overflow="">
</amp-ad>

Display AMP ad unit (fixed size)

The following code needs to be placed in the <head> of the page:

<script async custom-element="amp-ad" src="https://cdn.ampproject.org/v0/amp-ad-0.1.js"></script>

And this is the snippet for the ad unit, placed in the <body>:

<amp-ad
  layout="fixed"
  width="300"
  height="600"
  type="adsense"
  data-ad-client="ca-pub-1234"
  data-ad-host="ca-host-pub-5678">
</amp-ad>

Auto ads

Ideally, the following ad tag is placed in the <head> element, or as high up the page as possible.

<script async
    src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1234&host=ca-host-pub-5678"
    crossorigin="anonymous">
</script>

Ads via the ad placement API

The ad placement API currently supports interstitial and rewarded ads. Read the Ad Placement API developer documentation to learn about how to implement the API and customise it.

AdSense for Platforms is supported for these formats (currently only for web traffic). The only requirement is that the data-ad-host parameter is included in the main ad tag. See the example below.

<script async
    src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1234&host=ca-host-pub-5678"
    crossorigin="anonymous">
</script>
<script>
   window.adsbygoogle = window.adsbygoogle || [];
   var adBreak = adConfig = function(o) {adsbygoogle.push(o);}
</script>