Working with ads
You can earn revenue by placing ad units in your games. To do this:
-
Study the features and recommendations for placing ads.
-
Set up ad calls using the SDK.
-
Connect monetization in the Yandex Games developer console.
Features and recommendations for placing ads
-
Place ad calls so that the user understands that it is not part of the game, but an ad unit.
-
Recommended places for placing ads in the game: before the start of the game, when moving to the next level, after losing.
-
The frequency of calling rewarded video ads is not limited.
-
The frequency of calling a full-screen ad unit is controlled by the Yandex Games platform.
Setting up ad calls
Fullscreen AD
Fullscreen ADs are ad units that completely cover the background of the application and are displayed between the user's request for some information (for example, when moving to the next level of the game) and its receipt.
To call an ad, use the ysdk.adv.show_fullscreen_adv()
method.
ysdk.adv.show_fullscreen_adv(callbacks: table)
callbacks: table
— optional callback functions. Configured individually for each ad
unit.
-
on_close
— called when the ad is closed, after an error, and if the ad did not open due to too frequent calls. Used with thewas_shown
argument (typeboolean
), the value of which indicates whether the ad was shown. -
on_open
— called when the ad is successfully opened. -
on_error
— called when an error occurs. The error object is passed to the callback function. -
on_offline
— called when the network connection is lost (switched to offline mode).
Example
ysdk.adv.show_fullscreen_adv({
on_close = function (self, was_shown)
-- some action after close
end,
on_error = function (self, error)
-- some action after error
end
})
Rewarded video
Rewarded video is an ad unit that is used to monetize games. For watching a video, the user receives a reward or in-game currency.
To call an ad, use the ysdk.adv.show_rewarded_video()
method.
ysdk.adv.show_rewarded_video(callbacks: table)
callbacks: table
— optional callback functions. Configured individually for each ad
unit.
-
on_close
— called when the video ad is closed. -
on_open
— called when the video ad is displayed on the screen. -
on_error
— called when an error occurs. The error object is passed to the callback function. -
on_rewarded
— called when the video ad view is counted. Specify in this function what reward the user will receive after watching.
Example
ysdk.adv.show_rewarded_video({
on_open = function (self)
print("Video ad open")
end,
on_close = function (self)
print("Rewarded!")
end,
on_rewarded = function (self)
print("Video ad closed.")
end,
on_error = function (self, error)
print("Error while open video ad: " .. error)
end
})
Sticky banner
To enable the display of a sticky banner:
-
Open the developer console and go to the Draft tab.
-
In the Sticky banners block, configure the display of banners:
-
For mobile devices:
- Sticky banner in portrait orientation — select the location Bottom or Top;
- Sticky banner in landscape orientation — select the location Bottom, Top, or Right.
-
For computers — enable the Sticky banner on desktop option. The banner will be displayed on the right.
-
By default, the sticky banner appears when the game starts and is displayed throughout the session. To configure the moment of displaying the banner:
-
In the Sticky banners block, enable the Disable showing the sticky banner at startup option.
-
Set the display of banners using the methods:
ysdk.adv.get_banner_adv_status()
— shows the status of the banner;ysdk.adv.show_banner_adv()
— calls the banner;ysdk.adv.hide_banner_adv()
— removes the banner.
The ysdk.adv.get_banner_adv_status()
method returns the value
sticky_adv_is_showing: boolean
. If sticky_adv_is_showing = false
, the
ysdk.adv.get_banner_adv_status()
method can return an optional reason
field with
possible reasons:
- ADV_IS_NOT_CONNECTED — banners are not connected;
- UNKNOWN — error displaying ads on the Yandex side.
Example
ysdk.adv.get_banner_adv_status(
function (self, sticky_adv_is_showing, reason)
if sticky_adv_is_showing then
-- ad is showing
elseif reason then
-- ad is not showing
print(reason)
else
ysdk.adv.show_banner_adv()
end
end
)