Please make sure to visit Your AdSense Page where you can find personalized information about your account to help you succeed with AdSense.

H5 Games Ads (beta)

Add the AdSense code to your game page

H5 Games Ads (beta) use the AdSense code plus some additional code required to initialize the H5 Ad Placement API functions. There are also some optional AdSense code parameters available for you to configure additional settings.

How to place the code

  1. Copy the code shown below:
    <script async src="" crossorigin="anonymous"></script>
    <script>window.adsbygoogle = window.adsbygoogle || []; var adBreak = adConfig = function(o) {adsbygoogle.push(o);} </script>
    Note: Make sure you copy all the code including the additional code that initializes the adBreak() and adConfig() functions otherwise your ads won't work.
  2. In your code, replace "ca-pub-1234567890123456" with your own Publisher ID. Learn how to find your Publisher ID.
  3. If your game runs in a mobile app, you’ll need to specify two additional parameters as follows:

    After data-ad-client="ca-pub-1234567890123456" add:

    • data-admob-interstitial-slot="ca-app-pub-1234567890123456/11111111"
    • data-admob-rewarded-slot="ca-app-pub-1234567890123456/22222222"

    The parameter data-admob-interstitial-slot is used to request interstitial ads, while data-admob-rewarded-slot is used to request rewarded ads. At least one must be specified if your game is to display ads in a mobile app. Learn more about creating interstitial ad units and rewarded ad units in AdMob.

    If you don’t yet have an AdMob account, visit Google AdMob to create one.

  4. Place the code between the <head> and </head> tags of the page where your game is hosted.
    Note: Regardless of how you distribute your game (e.g., if you embed it directly into a page or iframe it into another site or part of your own site) you should always place the code on the page that contains your game.

Example game page with the AdSense code and additional code added

Example code Description The page where your game is hosted
<script async
/pagead/js/adsbygoogle.js?client=ca-pub-1234567890123456" crossorigin="anonymous">
This section is the AdSense code.
<script>window.adsbygoogle =
window.adsbygoogle || [];
var adBreak = adConfig = function(o) {adsbygoogle.push(o);}
This section initializes the H5 Ad Placement API.


<canvas id="game_canvas"
width="100%" height="100%">
<script src="game.js"><script>
This section is your game logic.

AdSense code parameter descriptions

You can use these AdSense code parameters to configure various settings for your game ads. The data-ad-client parameter is required but all other parameters are optional.

Note: These settings are initiated when the page containing the game canvas is loaded and can't be changed throughout the gameplay/pageview.
Parameter Description and examples
data-ad-client Required

Your publisher ID and publisher code.



data-ad-host Optional

If you share your revenue with a host platform, use this parameter to specify the host platform.



data-admob-interstitial-slot Optional

If your game runs in a mobile app, use this parameter to request interstitial ads.



data-admob-rewarded-slot Optional

If your game runs in a mobile app, use this parameter to request rewarded ads.



data-ad-channel Optional

You may include a custom channel ID for tracking the performance of your ads.



data-adbreak-test Optional

Use this parameter to enable testing mode. This let's you test your placements using fake ads.



data-tag-for-child-directed-treatment Optional

Use this parameter if you want to tag your ad requests for treatment as child directed. For more information, see: Tag a site or ad request for child-directed treatment.



data-tag-for-under-age-of-consent Optional

Use this parameter if you want to tag your European Economic Area (EEA), Switzerland, and UK ad requests for restricted data processing treatment. For more information, see : Tag an ad request for EEA and UK users under the age of consent (TFUA).



data-ad-frequency-hint Optional

The minimum average time interval between ads expressed in seconds. If this value is "120s" then ads will not be shown more frequently than once every two minutes on average. Note that this is a hint that could be ignored or overridden by a server control in future.



Was this helpful?

How can we improve it?
Your AdSense page

Introducing AdSense Page: a new resource in which you can find personalized information and new opportunities in your account to help to succeed with AdSense.

Clear search
Close search
Google apps
Main menu