Banners
Requesting banners
The banner
module contains functionality for displaying banners in game. To begin, you need to have an HTML container of the banner size present on the screen.
To define a banner, open Project/Export and add another line to the Head Include
of your CrazyGames preset:
<div id="banner-container" style="width: 300px; height: 250px; position: fixed; top:0; left:0; z-index:9999"></div>
Available sizes are:
- 728x90
- 300x250
- 320x50
- 468x60
- 320x100
Within the singleton managing your SDK, request a banner like this:
func requestBanner(width : int, height : int):
var params = JavaScript.create_object("Object")
params["id"] = "banner-container"
params["width"] = width
params["height"] = height
SDK.banner.requestBanner(params)
The id has to be the one you used in the head include, and the banner has to fit inside the container. You can have no more than 2 banners of the same size in your game.
Request responsive banners
The responsive banners feature will requests ads that fit into your container, without the need to specify or select a size beforehand. The resulting banners will have one of the following sizes: 970x90, 320x50, 160x600, 336x280, 728x90, 300x600, 468x60, 970x250, 300x250, 250x250 and 120x600. Only banners that fit into your container will be displayed, if your container cannot fit any of these sizes no ad will be rendered. The rendered banner is automatically vertically and horizontally centered into your container.
Define a container in the Head Include
of your CrazyGames preset with a non-null size:
<div id="responsive-banner-container" style="width: 500px; height: 500px; position: fixed; top:0; left:0; z-index:9999"></div>
Make sure to position the container in a way so it does not cover gameplay or interface. Now request a responsive banner in script:
Refreshing banners and limitations
To refresh the banners, simply call again the requestBanner
or requestResponsiveBanner
methods.
The banners have the following limitations:
- There is a minimum delay of 60 seconds between banner refreshes. If you call the request banner methods more often, you will receive the following error:
A banner has already been requested for container banner-container less than 57 seconds ago, please wait.
- During a gaming session the banners can be refreshed up to 60 times (this applies to each banner size separately).
Clearing the banners
The SDK provides 2 methods for clearing the banners:
We recommend that you clear the banners after hiding them. Otherwise, when you request new banners again, the old banners may still appear for a fraction of a second, which negatively impacts the user experience.