AdSense For Search - Above the Fold
Description

This is an example of AdSense for Search (AFS) ads placed above the fold. See the reference documentation for more information about AFS.

AMP ad attributes:
  • type - Must be set to "csa".
  • height - Must be at least 300px to avoid ad clipping.
  • data-afs-page-options - AFS page options as a string, in the same way you would specify the options in a normal web request.
  • data-afs-adblock-options - AFS block options as a string.
    • You must use the maxTop parameter instead of the number parameter to specify the number of ads.
    • You can only request one ad ("maxTop": 1) in an ad unit that is above the fold.
    • Set the width parameter to "auto" for best results.
    • No need to set the container parameter.
Additional requirements & information:
  • You must use a fallback div to show alternate content when no ads are returned. If no ads are returned the ad will not be collapsed because it is above the fold.
  • Although the page options containing the query parameter are passed as a string, you must dynamically change the query to match the actual search query.
  • Each amp-ad tag contains one adblock; only one data-afs-adblock-options attribute can be specified in the tag.


AMP Ad Tag


<amp-ad 
  height=300
  type="csa"
  data-afs-page-options='{"pubId": "partner-pub-id", "query": "user search query", "sellerRatings": true, "siteLinks": true}'
  data-afs-adblock-options='{"width": "auto", "maxTop": 1}'>
  <div fallback>Content for when no ads are returned.</div>
</amp-ad> 
              
AMP Demo
Note: Emulate with a mobile user agent for accurate rendering.