Cocos Plugin Integration

Before You Start

  • We support Cocos version 2.4.3.
  • We support Android Operation Systems Version 4.1(API level 16) and up.
  • We support Xcode 9.0 and up as well as CocoaPods.

Overview

This Guideline is intended for publishers who need to monetize for an Cocos app.

OpenMediation offers diversified and competent monetization services and supports a variety of Ad formats including Native Ad, Interstitial Ad, Banner Ad, and Incentive Video Ad. The OpenMediation platform mediates AdTiming, AdMob, Facebook, UnityAds, Vungle, Tapjoy, AppLovin, AdColony, Chartboost, Pangle, MoPub and IronSource.

Step 1. Add the OpenMediation Cocos Package to Your Project

Follow these steps to add the OpenMediation Coccos Package to your project:

  1. Download OpenMediation Cocos Package
  2. Make sure your Cocos project is opened in the Cocos editor.
    • The OpenMediation SDK is designed to work with the Android & iOS platform. The Cocos Editor contains a Simulator to work with Cocos code. In order to work with our Package, you must target either an Android or iOS build to test the integration.
  3. Import the Cocos package
    • Find the packages directory in the same level directory of the project and Assets, and put the downloaded package/OpenMediation into this directory.
    • Open the project to view the extended menu, you can see the OpenMediation submenu.

Step 2. Cocos Integration Manager

OpenMediation Cocos integrated management tool can download or update the latest version of OpenMediation SDK and aggregation adapter through the "Extension" menu.

cocos_manager_en.png

cocos_mediation_manager.png

Note: The Adapter version number displayed in the Cocos integrated management tool is not the iOS/Android OpenMediation***Adapter version number.

After importing the Cocos package, you will be able to view the OpenMediation submenu in the extended menu bar.

  • Open the integrated management tool:OpenMediation > Integration Manager(For traffic applications in China, please select Integration Manager (CN))
  • Select "Install" or "Update"

If you already have the latest version of OpenMediation SDK or aggregation adapter, the button will change to "Updated" and it will be disabled.

 

Step 3. Register Event Listener

The OpenMediation Cocos plugin will trigger a series of advertising-related event callbacks, and have notified you of the status and information of the advertising SDK. Add the following code to register to the event:

cc.Class({
    extends: cc.Component,

    onLoad: function () {
        this.initPlugin();
    },

    initPlugin: function () {
        const self = this;
        OpenMediation.Ads.setListener({
            onInitSuccess: function () {
                //initialization success
            },

            onInitFailed: function (msg) {
                // initialization failed
            },

            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
            },

            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
            },

            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
            },

            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
            },

            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
            },

            onImpressionDataError: function (msg) {
                // If ILRD function is not enabled. It is called when ad is displayed
            },

            onImpressionData: function (msg) {
                // If ILRD function is enabled. It is called when ad is displayed
            },
        });
        OpenMediation.Ads.init(appKey);
    },

    showRewardedVideo: function () {
        OpenMediation.Ads.showRewardedVideo();
    },

    showInterstitial: function () {
        OpenMediation.Ads.showInterstitial();
    },

    LoadBanner: function () {
        OpenMediation.Ads.loadBanner(bannerPlacementID, 0, 0);
    },

    showBanner: function () {
        OpenMediation.Ads.showBanner(bannerPlacementID);
    },

    hideBanner: function () {
        OpenMediation.Ads.hideBanner(bannerPlacementID);
    },

    showPromotionAd: function () {
        OpenMediation.Ads.showPromotionAd('scene', 132, 153, 0, 0.3, 20);
    },

    hidePromotionAd: function () {
        OpenMediation.Ads.hidePromotionAd();
    },

    loadSplash: function () {
        OpenMediation.Ads.loadSplash(splashPlacementID);
    },

    showSplash: function () {
        OpenMediation.Ads.showSplash(splashPlacementID);
    },
});

 

Step 4. Initialize the Ad Units

Before loading ads, initialize the OpenMediation SDK by calling OpenMediation.Ads.init('appKey') with your AppKey. This is best done at the time of the app launch, and only needs to be done once. Here’s an example of how to call Init() within the onLoad method of a script. 

OpenMediation.Ads.init('appKey');

 

Add the following code to register to the events, the Plugin will notify the Listener of all possible events listed below: 

onInitSuccess: function () {
    //initialization success
},

onInitFailed: function (msg) {
    // initialization failed
},

 

IsInitialized

After calling the init() method, you can also use the following code to determine whether the SDK has been successfully initialized.

// To determine the result of init()
OpenMediation.Ads.initialized()

 

Remove event listener

OpenMediation.Ads.removeListener();

 

Get Plugin Version

OpenMediation.Ads.getVersion();

 

Set GDPR Consent, it is best to call before init

OpenMediation.Ads.setGDPRConsent(consent);

 

Get GDPR Consent

OpenMediation.Ads.getGDPRConsent();

 

The use of personal information is restricted in accordance with the California Consumer Privacy Act (CCPA).

OpenMediation.Ads.setUSPrivacyLimit(true);

 

Set User Age

OpenMediation.Ads.setUserAge(25);

 

Set User Gender

gender int, 0:Unknown; 1:Male; 2:Female

OpenMediation.Ads.setUserGender(gender);

 

Set IAP Parameter(optional)

IAP, an acronym for in-App Purchase, can be understood as an in-app purchase. We need you to pass the current device user's IAP data to the SDK through the setIAP method in the APP so that we can provide more accurate advertising.

OpenMediation.Ads.setIAP(10, 'USD'); 

The parameter currency is a String represents the currency code of the ISO, based on the International Organization for Standardization's national code, is published in the ISO 4217:2008 standard and is used to represent money and funds.

 

Tips:

Enable local logging: (For local debugging only. Remove it before going live.)

OpenMediation.Ads.debug(true);

 

 

Was this article helpful?
0 out of 2 found this helpful

Comments

0 comments

Please sign in to leave a comment.