Skip to main content

Cocos Creator

Set up the Cocos project

  1. Add this line first in the script where you’ll implement MAS.

    import Yodo1Ads from "./Yodo1Ads";
  2. 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);

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 dpDescriptionAvailabilityAdSize Constant
320×50BannerPhones and TabletsBanner
320×100Large BannerPhones and TabletsLargeBanner
300×250IAB Medium RectanglePhones and TabletsIABMediumRectangle
Full-screen width xAdaptive heightAdaptive BannerPhones and TabletsAdaptiveBanner

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() {
}