Before You Start
Before integrating ads unit in your app, you must:
- In the OpenMediation UI, create an account, create an app, and create an ad placement. You can follow guides here.
- Follow our steps to Cocos Plugin Integration by integrating the Cocos Plugin into your project.
The OpenMediation SDK is now included in your app when you deploy it to either the Android or iOS platform. You're now ready to implement ad unit. OpenMediation Cocos Plugin offers multiple ad types.. You can choose the one that best fits your user experience needs.
Rewarded Video Ad
Rewarded video ads with strong interactive ability has become the mainstream form of mobile advertising industry. It is becoming increasingly common for mobile game developers to rely more on built-in ads than IAP to monetize.
The OpenMediation Rewarded Video ad unit offers an engaging ad experience that rewards your users with valuable virtual content in exchange for a completed view. This user-initiated ad unit is great for gaming apps, and enhances your apps experience. This section tells you how to init, load, and show Rewarded Video Ads.
Step 1. Implement Rewarded Video Events
The OpenMediation Cocos Plugin fires several events to inform you of ad availability.
The Plugin will notify the Listener of all possible events listed below:
OpenMediation.Ads.setListener({
onRewardedVideoAvailabilityChanged: function (available) {
// Invoked when the ad availability status is changed
},
onRewardedVideoShow: function (scene) {
// Invoked when the RewardedVideo ad view has opened
},
onRewardedVideoShowFailed: function (scene) {
// Invoked when the call to show a rewarded video has failed
},
onRewardedVideoClosed: function (scene) {
// Invoked when the RewardedVideo ad is closed
},
onRewardedVideoStarted: function (scene) {
// Invoked when the RewardedVideo ad start to play
},
onRewardedVideoEnded: function (scene) {
// Invoked when the RewardedVideo ad play end
},
onRewardedVideoReceiveRewarded: function (scene) {
// Invoked when the video is completed and the user should be rewarded
},
onRewardedVideoClicked: function (scene) {
// Invoked when the user clicked on the RewardedVideo ad
},
});
Note: Do not assume the callbacks are always running on the main thread. Any UI interaction or updates resulting from callbacks need to be passed to the main thread before executing.
Step 2. Check Ad Availability
After the Rewarded Ad is successfully loaded, you will be notified when the ad is available to be shown through the onRewardedVideoAvailabilityChanged callback which will inform you the availability of ad inventory.
onRewardedVideoAvailabilityChanged: function (available) {
// Invoked when the ad availability status is changed
}
Another way to check if the ad is available is by calling the isRewardedVideoReady function directly.
if (OpenMediation.Ads.rewardedVideoIsReady()) {
OpenMediation.Ads.showRewardedVideo("SceneName");
}
Step 3. Show a RewardedVideo Ad
We strongly recommend checking the ad's availability by calling the isRewardedVideoReady method before you serve Rewarded Video .
if (Om.Agent.isRewardedVideoReady()) {
Om.Agent.showRewardedVideo("Your Video SceneName");
}
Interstitial Ad
The Interstitial is a full-screen ad unit, usually served at natural transition points during an app's lifecycle. Both static and video interstitials are supported.
Step 1. Implement Interstitial Events
The Plugin will notify the Listener of all possible events listed below:
OpenMediation.Ads.setListener({
onInterstitialAvailabilityChanged: function (available) {
// Invoked when the interstitial ad availability status is changed
},
onInterstitialShow: function (scene) {
// Invoked when the Interstitial ad has opened
},
onInterstitialShowFailed: function (scene) {
// Invoked when the Interstitial ad has showed failed
},
onInterstitialClosed: function (scene) {
// Invoked when the Interstitial ad is closed
},
onInterstitialClicked: function (scene) {
// Invoked when the user clicked on the Interstitial ad
},
});
Step 2. Check Ad Availability
After the Interstitial Ad is successfully loaded, you will be notified when the ad is available to be shown through the onInterstitialAvailabilityChanged callback which will inform you the availability of ad inventory.
onInterstitialAvailabilityChanged: function (available) {
// Invoked when the interstitial ad availability status is changed
}
Another way to check if the ad is available is by calling the interstitialIsReady function directly.
OpenMediation.Ads.interstitialIsReady();
Step 3. Show a Interstitial Ad
We strongly recommend checking the ad's availability by calling the interstitialIsReady method before you serve Interstitial Ad.
if (OpenMediation.Ads.interstitialIsReady()) {
OpenMediation.Ads.showInterstitial("SceneName");
}
Banner Ad
Mobile banner ads are typically displayed at the top or bottom of the screen, and stick to the screen for the duration of the user’s session. Banner ads are a very popular ad unit for mobile apps because they are easy to implement and are a great tool for promoting advertiser awareness.
Step 1. Implement Banner Events
The Plugin will notify the Listener of all possible events listed below:
OpenMediation.Ads.setListener({
onBannerLoadSuccess: function (placementId) {
// Invoked when Banner Ad load success
},
onBannerLoadFailed: function (placementId, msg) {
// Invoked when Banner Ad load failed
},
onBannerClicked: function (placementId) {
// Invoked when the user clicked on the Banner Ad
},
});
Step 2. Load Banner Ad
To load a Banner ad, call the following method:
Load the Banner view by calling this method:
// placementId string
// adSize int 0:Banner; 1:MediumRectangle; 2:Leaderboard; 3:Smart
// position int 0:Bottom; 1:Top
OpenMediation.Ads.loadBanner(placementId, 0, 0)
see table below for details about our supported standard banner sizes:
BannerSize | Description | Dimensions (WxH) (points in iOS, dp in Android) |
BANNER | Standard Banner | 320 x 50 |
LARGE | Large Banner | 320 x 90 |
RECTANGLE | Medium Rectangular Banner | 300 x 250 |
SMART |
Smart Banner (Adjusted for both mobile and tablet) |
iOS: If (iPhone) 320 x 50 If (iPad) 728 x 90 Android: If (screen height ≤ 720) 320 x 50 If (screen height > 720) 728 x 90 |
See table below for details about our supported standard banner positions:
BannerPosition | Description |
TOP | Banner will be positioned at the top center of the screen |
BOTTOM | Banner will be positioned at the bottom center of the screen |
You will receive the onBannerLoadSuccess
and the banner will show on your app.
Hide & Display Banner
In order to provide maximum flexibility in the ad experience, you now have the ability to hide and present banners on your app.
Unlike with the Android and iOS native implementations, when banner is loaded for the first time, it will show itself, and there won’t be a need to call displayBanner().
Once you’ve loaded and served a banner, you can choose to hide this banner and re-show it at a later point in your app.
To hide the banner, call this function:
OpenMediation.Ads.hideBanner(placementId);
To then show this same banner again, call this function:
OpenMediation.Ads.showBanner(placementId);
Step 3.Destroy Banner Ad
To destroy a banner, call the following method:
OpenMediation.Ads.destroyBanner(placementId);
A destroyed banner can no longer be loaded. If you want to serve it again, you must initiate it again.
Promotion Ad
Step 1. Implement Promotion Events
The Plugin will notify the Listener of all possible events listed below:
OpenMediation.Ads.setListener({
onPromotionAdAvailabilityChanged: function (available) {
// Invoked when PromotionAd availability changed
},
onPromotionAdShow: function (scene) {
// Invoked when the PromotionAd has opened
},
onPromotionAdViewWillDisappear: function (scene) {
// Invoked when the PromotionAd is closed
},
onPromotionAdClicked: function (scene) {
// Invoked when the user clicked on the PromotionAd
},
});
Step 2. Check Ad Availability
After the Promotion Ad is successfully loaded, you will be notified when the ad is available to be shown through the onPromotionAdAvailabilityChanged callback which will inform you the availability of ad inventory.
onPromotionAdAvailabilityChanged: function (available) {
// Invoked when PromotionAd availability changed
}
Another way to check if the ad is available is by calling the promotionAdIsReady function directly.
OpenMediation.Ads.promotionAdIsReady();
Step 3. Show a Promotion Ad
We recommend checking the ad's availability by calling the promotionAdIsReady method before you serve Promotion Ad.
if (OpenMediation.Ads.promotionAdIsReady()) {
// Scene name
// Ad width
// Ad height
// The distance from the left side of the screen, the value is 0~1, default 0
// The distance from the top side of the screen, the value is 0~1, default 0
// Take the center as the dot and rotate the angle clockwise, default 0
OpenMediation.Ads.showPromotionAd('scene', 132, 153, 0, 0.3, 20);
}
Splash Ad
Step 1. Implement SplashAd Events
The Plugin will notify the Listener of all possible events listed below:
OpenMediation.Ads.setListener({
onSplashLoadSuccess: function (placementId) {
// Invoked when Splash Ad load success
},
onSplashLoadFailed: function (placementId, msg) {
// Invoked when Splash Ad load failed
},
onSplashShow: function (placementId) {
// Invoked when Splash Ad has opened
},
onSplashShowFailed: function (placementId, msg) {
// Invoked when Splash Ad has showed failed
},
onSplashClicked: function (placementId) {
// Invoked when the user clicked on the Splash Ad
},
onSplashClosed: function (placementId) {
// Invoked when the Splash Ad is closed
},
});
Step 2. Load Splash Ad
To load a Splash ad, call the following method:
OpenMediation.Ads.loadSplash(placementId);
Step 3. Check Ad Availability
After the SplashAd is successfully loaded, you will be notified when the ad is available to be shown through the onSplashLoadSuccess callback which will inform you the availability of ad inventory.
Another way to check if the ad is available is by calling the isSplashAdReady function directly.
OpenMediation.Ads.splashAdIsReady(placementId);
Step 4. Show a Splash Ad
We recommend checking the ad's availability by calling the splashAdIsReady method before you serve Splash Ad.
if (OpenMediation.Ads.splashAdIsReady(placementId)) {
OpenMediation.Ads.showSplash(placementId);
}
Tips:
Enable local logging: (For local debugging only. Remove it before going live.)
OpenMediation.Ads.debug(true);
Comments
Please sign in to leave a comment.