Advertising
You can generate revenue from placing ad units in your games. To do this:
- Learn about the tips and recommendations for ad placement.
- Set up ad calls using the SDK.
- Enable monetization in the Yandex Games Developer Console.
Tips and recommendations for placing ads
- Ad calls should be placed in such a way that the user clearly perceives them as ads, not as an actual gameplay element.
- It is recommended to show ads after a user action or on a timer if completing a level takes more than 5 minutes. For more information, see Ad placement.
- You can call rewarded video ads as often as you want.
- The frequency of calling an interstitial ad unit is controlled by Yandex Games.
Alert
The Yandex Advertising Network considers incidental user clicks on ad units as ad fraud and reduces revenue from in-game advertising.
To avoid this, do not call ads during gameplay, when users may unintentionally click on the ad unit.
Example of an improper ad call:
setInterval(() => ysdk.adv.showFullscreenAdv(), 180000)
Configure ad calls
Interstitial ad
Interstitial ad units completely cover the app background and are shown after certain data requests from the user (for example, when transitioning to the next game level) but before this data is returned.
To call an ad, use the ysdk.adv.showFullscreenAdv() method.
Method signature:
1function showFullscreenAdv(callbacks?: {
2 onOpen?: () => void;
3 onClose?: (wasShown: boolean) => void;
4 onError?: (error: object) => void;
5}) => void {}
The callbacks parameter can include optional callback functions:
onOpen— called when the ad is opened successfully.onClose— called when the ad closes, after an error, or after an ad failed to open due to too frequent calls. It's used with thewasShownargument (booleantype), the value of which indicates whether the ad was shown or not.onError— called when an error occurs. The error object is passed to the callback function.
Example
1const ysdk = await YaGames.init();
2
3ysdk.adv.showFullscreenAdv({
4 callbacks: {
5 onOpen: () => console.log('Ad opened.'),
6 onClose: (wasShown) => console.log(wasShown ? 'Shown and closed.' : 'Not shown.'),
7 onError: (error) => console.log('Call error.'),
8 }
9})
Rewarded video
Rewarded video is a video ad block that rewards the user for watching it, for example, with in-game currency.
To call an ad, use the ysdk.adv.showRewardedVideo() method.
Method signature:
1function showRewardedVideo(callbacks?: {
2 onOpen?: () => void;
3 onRewarded?: () => void;
4 onClose?: (wasShown: boolean) => void;
5 onError?: (error: object) => void;
6}) => void {}
The callbacks parameter can include optional callback functions:
onOpen— called when the video ad is shown on the screen.onRewarded— called when a video ad impression is counted. This function should specify a reward for viewing the ad.onClose— called when the video ad closes.onError— called when an error occurs. The error object is passed to the callback function.
Example
1const ysdk = await YaGames.init();
2
3ysdk.adv.showRewardedVideo({
4 callbacks: {
5 onOpen: () => console.log('Ad opened.'),
6 onRewarded: () => console.log('User received reward.'),
7 onClose: (wasShown) => console.log(wasShown ? 'Shown and closed.' : 'Not shown.'),
8 onError: (error) => console.log('Call error.'),
9 }
10})
Enable sticky banner display
A sticky banner is an ad unit that is displayed during the game. To enable sticky banner display:
- Open the Developer Console and go to the Advertising tab.
- In the Sticky banners section, set up the display of banners:
-
For mobile devices:
- Sticky banner in portrait orientation: Select the At the bottom or At the top position.
- Sticky banner in landscape orientation: Select the At the bottom, At the top, or On the right position.
-
For computers: Enable the Sticky banner on the desktop option. The banner will be displayed on the right.
-
Manage sticky banner display
By default, the sticky banner appears upon launch and remains visible throughout the entire session. To manage sticky banner display using SDK methods, enable the Use the API to display a sticky-banner option.
ysdk.adv.getBannerAdvStatus()
Get the current status of the sticky banner.
Method signature:
1function getBannerAdvStatus(): Promise<{
2 stickyAdvIsShowing: boolean;
3 reason?: 'ADV_IS_NOT_CONNECTED' | 'UNKNOWN';
4}> {}
Returns the sticky banner display status stickyAdvIsShowing. If the banner is not shown, it also returns the optional reason field, which indicates why the banner is not displayed:
ADV_IS_NOT_CONNECTED: Banners are not enabled.UNKNOWN: Error displaying ads on the Yandex side.
ysdk.adv.showBannerAdv()
Show the sticky banner.
Method signature:
1function showBannerAdv(): Promise<{
2 stickyAdvIsShowing: boolean;
3 reason?: 'ADV_IS_NOT_CONNECTED' | 'UNKNOWN';
4}>
Returns values are similar to ysdk.adv.getBannerAdvStatus().
ysdk.adv.hideBannerAdv()
Hide the sticky banner.
Method signature:
1function hideBannerAdv(): Promise<{
2 stickyAdvIsShowing: boolean;
3}>
Returns the sticky banner display status stickyAdvIsShowing.
Example
1const ysdk = await YaGames.init();
2
3const { stickyAdvIsShowing , reason } = await ysdk.adv.getBannerAdvStatus();
4
5if (stickyAdvIsShowing) {
6 // Ad is displayed.
7} else if (reason) {
8 // Ad is not displayed.
9 console.log(reason);
10} else {
11 ysdk.adv.showBannerAdv();
12}
Note
Our support team can help publish finished games on Yandex Games. If you have any questions about development or testing, ask them in the Discord channel.
If you are facing an issue or have a question regarding the use of Yandex Games SDK, please contact support:
callbacks: Optional callback functions. They are configured individually for each ad unit.
onOpen: Called when a video ad is displayed on the screen.
onRewarded: The function called when a video ad impression is counted. Specify, in this function, the reward the user will receive after viewing.
onClose: Called when the ad is closed, on error, or if the ad failed to open due to too frequent calls. It's used with the wasShown argument (boolean type), which indicates whether the ad was shown or not.
onClose: Called when a user closes a video ad.
onError: Called when an error occurs. The error object is passed to the callback function.