Ad tags

The AdSense ad tag enables ad serving and revenue sharing. You need to place the AdSense ad tag on every page where your users can opt-in to monetize their content with AdSense.

How you approach this step will likely depend on the ad settings control and ads experience you want to give your users: - If you're in control of the ad settings, you can decide which ad types and placements you want to support and add the ad tags to your users' sites as if they were your own sites. You create ad units inside your AdSense account, but modify the data-ad-client and data-ad-host parameters - If you're delegating control of the ad settings to your users, you might want to ask your users what their preferences are for ad types and placements (left, right, top, bottom, etc.) and use those preferences to do the tagging. Note that in order to support Native ads, the ad tags require an ad unit ID which you will need to collect from your users.

Ad tag parameters

There are two required parameters in the ad tag that you need to modify. These parameters determine ad serving and revenue sharing with your users. Set these parameters to specify the platform's publisher ID and the user’s 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 Your user’s AdSense for Content publisher ID (string). This value is provided by the user through the sign up flow. This value is required to initiate revenue sharing.

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 child (data-ad-client) 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-host parameter is not present in your ad code, AdSense will continue ad serving using the value provided by the data-ad-client parameter. However, your the platform account won't receive any impressions in their account and no revenue sharing. You can alternatively use the google-adsense-platform meta tag to ensure your host publisher ID is included in the ad request.

Also, make sure that you place the correct data-ad-client publisher ID in the code tag to avoid attributing revenue to the wrong user.

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>