Cocos Creator
Set up the Cocos project
Add this line first in the script where you’ll implement MAS.
import Yodo1Ads from "./Yodo1Ads";
To Initialize MAS, call the
getInstance
method and initialize it using your app's AppKey. You can find your AppKey in the MAS dashboard. The second parameter is to show the default PrivacyDialog set it to true to show our built-in privacy dialog (recommended), otherwise to false.Yodo1Ads.getInstance().initializeMasSdk("YourAppkey", true);
Configure Legal Frameworks
We recommend using our privacy dialog for complete and automated compliance. If you choose to not use our privacy dialog, you have to set the legal frameworks manually and ensure to set them before you initialize the SDK.
COPPA
If the user is above 13, set COPPA to false, otherwise to true.
Yodo1Ads.getInstance().setCOPPA(false);
GDPR
If the user is in the European Economic Area (EEA), above 16 and gives consent, set GDPR to true, otherwise to false.
Yodo1Ads.getInstance().setGDPR(true);
CCPA
If the user is in California, gives consent, set CCPA to true, otherwise to false.
Yodo1Ads.getInstance().setCCPA(false);
Configure Ad Types
Interstitial Ads
To initialize, show and listen to different ad events of the interstitials ads, use the following methods available through Yodo1Ads.ts
.
// Initialize Interstitial Ads
Yodo1Ads.getInstance().initializeInterstitialAds();
// Show Interstitial Ads
Yodo1Ads.getInstance().showInterstitialAds();
// Listen to Interstitial Ads Events
public onInterstitialAdLoaded() {
}
public onInterstitialAdFailedToLoad() {
}
public onInterstitialAdOpened() {
}
public onInterstitialAdFailedToOpen() {
}
public onInterstitialAdClosed() {
}
Rewarded Ads
To initialize, show and listen to different ad events of the rewarded ads, use the following methods available through Yodo1Ads.ts
.
// Initialize Rewarded Ads
Yodo1Ads.getInstance().initializeRewardAds();
// Show Rewarded Ads
Yodo1Ads.getInstance().showRewardAds();
// Listen to Rewarded Ads Events
public onRewardAdLoaded() {
}
public onRewardAdFailedToLoad() {
}
public onRewardAdOpened() {
}
public onRewardAdFailedToOpen() {
}
public onRewardAdClosed() {
}
public onRewardAdEarned() {
// Reward the user here
}
Banner Ad(s)
The following code will both load and show the banner ads in your app. It exposes the banner size (AdSize
) with it's horizontal and vertical position as parameters.
Yodo1Ads.getInstance().loadBannerAds("Banner", "RIGHT", "TOP");
Size in dp | Description | Availability | AdSize Constant |
---|---|---|---|
320×50 | Banner | Phones and Tablets | Banner |
320×100 | Large Banner | Phones and Tablets | LargeBanner |
300×250 | IAB Medium Rectangle | Phones and Tablets | IABMediumRectangle |
Full-screen width xAdaptive height | Adaptive Banner | Phones and Tablets | AdaptiveBanner |
To hide and show the banner ads programmatically you can use the hideBannerAds
and showBannerAds
methods, as needed.
Yodo1Ads.getInstance().hideBannerAds();
Yodo1Ads.getInstance().showBannerAds();
To listen to different banner ads events use the following methods available through Yodo1Ads.ts
.
public onBannerAdLoaded() {
}
public onBannerAdFailedToLoad() {
}
public onBannerAdOpened() {
}
public onBannerAdFailedToOpen() {
}
public onBannerAdClosed() {
}