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
- Example game page with the AdSense code and additional code added
- AdSense code parameter descriptions
How to place the code
- Copy the code shown below:
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ignored1234567890123456" 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 theadBreak()
andadConfig()
functions otherwise your ads won't work. - In your code, replace
"ignored1234567890123456"
with your own Publisher ID. Learn how to find your Publisher ID. - If your game runs in a mobile app, you’ll need to specify two additional parameters as follows:
After
data-ad-client="ignored1234567890123456"
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, whiledata-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.
- 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 |
This section is the AdSense code. |
<script>window.adsbygoogle = |
This section initializes the H5 Ad Placement API. |
</head>
<body> |
|
<canvas id="game_canvas" |
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.
Parameter | Description and examples |
---|---|
data-ad-client |
Required
Your publisher ID and publisher code. Example:
|
data-ad-host |
Optional
If you share your revenue with a host platform, use this parameter to specify the host platform. Example:
|
data-admob-interstitial-slot |
Optional
If your game runs in a mobile app, use this parameter to request interstitial ads. Example:
|
data-admob-rewarded-slot |
Optional
If your game runs in a mobile app, use this parameter to request rewarded ads. Example:
|
data-ad-channel |
Optional
You may include a custom channel ID for tracking the performance of your ads. Example:
|
data-adbreak-test |
Optional
Use this parameter to enable testing mode. This let's you test your placements using fake ads. Example:
|
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-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-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:
|