Notification

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.

On this page

How to place the code

  1. Copy the code shown below:
    <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1234567890123456" 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
yourdomain.com/games/mygame The page where your game is hosted.
<head>  
<script async
src="https://pagead2.googlesyndication.com
/pagead/js/adsbygoogle.js?client=ca-pub-1234567890123456" crossorigin="anonymous">
</script>
This section is the AdSense code.
<script>window.adsbygoogle =
window.adsbygoogle || [];
var adBreak = adConfig = function(o) {adsbygoogle.push(o);}
</script>
This section initializes the H5 Ad Placement API.
</head>

 

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

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.

Example:

data-ad-client="ca-pub-1234567890123456"

data-ad-host Optional

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

Example:

data-ad-host="ca-host-pub-123"

data-admob-interstitial-slot Optional

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

Example:

data-ad-host="ca-app-pub-1234567890123456/456"

data-admob-rewarded-slot Optional

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

Example:

data-ad-host="ca-app-pub-1234567890123456/789"

data-ad-channel Optional

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

Example:

data-ad-channel="1234"

data-adbreak-test Optional

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

Example:

data-adbreak-test="on"

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, refer to: Tag a site or ad request for child-directed treatment.

Example:

data-tag-for-child-directed-treatment="1"

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, refer to: Tag an ad request for EEA and UK users under the age of consent (TFUA).

Example:

data-tag-for-under-age-of-consent="1"

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.

Example:

data-ad-frequency-hint="120s"

Was this helpful?

How can we improve it?
true
Unlock Growth Potential

Don't miss out on valuable AdSense insights. Opt in to receive performance reports, personalized tips, and webinar invites that can help boost your earnings

Opt in

Search
Clear search
Close search
Main menu
4074995867413502144
true
Search Help Center
true
true
true
true
true
157
false
false