‹ AdColony Doc Home

AdColony Integration Guide

For the Javascript version of cocos2d-x v3.x - (all other versions)

Prerequisites

Certain SDKBOX plugins do not work together. If you use AdColony, then you cannot also use the Fyber and SOOMLA GROW services, in the same project.

Start from AdColony 3.0 it requires you to config your app to support all orientations, please read the details here

SDK Version

Integration

Open a terminal and use the following command to install the SDKBOX AdColony plugin. Make sure you setup the SDKBOX installer correctly.

$ sdkbox import adcolony

Important Notice

Please make sure the following settings in your project to make the plugin work well.

Disable App Transport Security

Adding the following entry to the info.plist file:

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>

It should look like this:

Disable Bitcode support

You have to turn off Bitcode support. If you don't, cocos2d-x will fail to build.

Set your game requires full screen

If your game doesn't support all screen orientations, you will need to check Requires full screen in Xcode. If you do not, your app will fail Apple's submission process.

Whitelist canOpenURL function

This setting depends on what plugins are in your project. You may need to add the required entry to the info.plist, under LSApplicationQueriesSchemes.

JSON Configuration

SDKBOX Installer will automatically inject a sample configuration to your res/sdkbox_config.json, that you have to modify it before you can use it for your own app

Here is an example of the AdColony configuration, you need to replace <app id> and <zone id> items with your specific AdColony account information.

"AdColony":{
    "id":"<app id>",
    "debug":true,
    "ads":{
        "video":{
            "zone": "<zone id>",
            "v4vc": false
        },
        "v4vc":{
            "zone": "<zone id>",
            "v4vc": true,
            "pre_popup" : true,
            "post_popup": true
        },
        "banner": {
            "zone": "<zone id>",
            "type":"banner",
            "alignment":"bottom",
            "width": 320,
            "height": 50
        }
    }
}

banner.width: when banner.width is smaller than 10, we will take banner.width as special value, which means we will create adcolony preset banner. now we used following value.

as the above, set banner.width 0 will create a standard(320X250) banner, set banner.width 1 will create a medium(300X250) banner, height should be 0 when width is special value.

banner.alignment: available values:

Usage

Register Javascript Functions

You need to register all the Adcolony JS functions with cocos2d-x before using them.

To do this: * Modify ./frameworks/runtime-src/Classes/AppDelegate.cpp to include the following headers:

#include "PluginAdColonyJS.hpp"
#include "PluginAdColonyJSHelper.h"
sc->addRegisterCallback(register_all_PluginAdColonyJS);
sc->addRegisterCallback(register_all_PluginAdColonyJS_helper);

Initialize AdColony

Initialize the plugin by calling init() where appropriate in your code. We recommend to do this in the app.js. Example:

sdkbox.PluginAdColony.init();

Showing Ads

Display an ad wherever you want from your code, by specifying ad type:

sdkbox.PluginAdColony.show("video");

or:

sdkbox.PluginAdColony.show("v4vc");

Catch AdColony events (optional)

This allows you to catch the AdColony events so that you can perform operations such as providing player rewards for watching the video.

/**
 * The structure of data
 * data.name : name of the ad (in sdkbox_config.json)
 * data.zoneID : the zoneID of the ad
 * data.shown : indicates wether the ad gets shown or closed by user
 * data.iapEnabled : indicating whether or not the associated ad is an IAP
 * data.iapProductID : product identifier for the associated ad's IAP
 * data.iapQuantity : he number of items the user wishes to purchase
 * data.iapEngagementType : indicating the IAP engagement mechanism
 */

sdkbox.PluginAdColony.setListener({
    adColonyInterstitialDidLoad: function(interstitial) {
    },
    adColonyInterstitialDidFailToLoad: function(error) {
    },
    adColonyInterstitialWillOpen: function(interstitial) {
    },
    adColonyInterstitialDidClose: function(interstitial) {
    },
    adColonyInterstitialExpired: function(interstitial) {
    },
    adColonyInterstitialWillLeaveApplication: function(interstitial) {
    },
    adColonyInterstitialDidReceiveClick: function(interstitial) {
    },
    adColonyInterstitialIapOpportunity: function(interstitial, iapProductID, engagement) {
    },
    adColonyAdViewDidLoad: function(adView) {
    },
    adColonyAdViewDidFailToLoad: function(error) {
    },
    adColonyAdViewWillLeaveApplication: function(adView) {
    },
    adColonyAdViewWillOpen: function(adView) {
    },
    adColonyAdViewDidClose: function(adView) {
    },
    adColonyAdViewDidReceiveClick: function(adView) {
    },
    adColonyReward: function(name, currencyName, amount, success) {
    }
});

API Reference

Methods

sdkbox.PluginAdColony.setGDPR(enabled);

Set GDPR

>>NOTE>>: please call before 'init' function
sdkbox.PluginAdColony.init();

initialize the plugin instance.

sdkbox.PluginAdColony.show(name);

play video ad using provided name that was specified in sdkbox_config.json

sdkbox.PluginAdColony.setListener(listener);

Set listener to listen for adcolony events

sdkbox.PluginAdColony.zoneStatusForZone(zoneID);

Returns the zone status for the specified zone.

@deprecated please use getStatus(name) instead
sdkbox.PluginAdColony.getStatus(name);

Check the availability of the adcolony ads by name

sdkbox.PluginAdColony.setCustomID(customID);

Assigns your own custom identifier to the current app user.

Once you've provided an identifier, AdColony will persist it across app
restarts (stored on disk only) until you update it. If using this method,
call it before `+ configureWithAppID:zoneIDs:delegate:logging:` so that the
identifier is used consistently across all server communications. The
identifier will also pass through to server-side V4VC callbacks.
@see getCustomID
sdkbox.PluginAdColony.getCustomID();

Returns the device's current custom identifier.

@return The custom identifier string most recently set using `+ setCustomID:`.
@see setCustomID:
sdkbox.PluginAdColony.getUniqueDeviceID();

Returns an AdColony-defined device identifier.

This identifier should remain constant across the lifetime of an iOS device.
The identifier is a SHA-1 hash of the lowercase colon-separated MAC address of the device's WiFi interface.
We do not recommend using this
identifier for new integrations. This method is provided for backwards compatibility.
@return The string representation of the device's AdColony identifier.
sdkbox.PluginAdColony.getAdvertisingIdentifier();

Returns the device's advertising identifier.

This value can change if the user restores their device or resets ad tracking.
@return The string representation of the device's advertising identifier, introduced in iOS 6. Returns `nil` on iOS 5 or below.
@note this function only available on ios
sdkbox.PluginAdColony.getVendorIdentifier();

Returns the device's vendor identifier.

@return As of version 2.3 of our iOS SDK, AdColony no longer collects the vendor identifier and this method will return `nil`. This method is provided for backwards compatibility.
@note this function only available on ios
sdkbox.PluginAdColony.getVideosPerReward(currencyName);

Returns the number of ads that the user must play to earn the designated reward.

@note this function only available on ios
sdkbox.PluginAdColony.getVideoCreditBalance(currencyName);

Returns the number of ads that the user has seen towards their next reward.

@note this function only available on ios
sdkbox.PluginAdColony.cancelAd();

Cancels any full-screen ad that is currently playing and returns control to the app.

No earnings or V4VC rewards will occur if an ad is canceled programmatically by the app.
This should only be used by apps that must immediately respond to non-standard incoming events,
like a VoIP phone call. This should not be used for standard app interruptions such as
multitasking or regular phone calls.
sdkbox.PluginAdColony.videoAdCurrentlyRunning();

Whether a full-screen AdColony ad is currently being played.

@return A boolean indicating if AdColony is currently playing an ad.
@note this function only available on ios
sdkbox.PluginAdColony.turnAllAdsOff();

This method permanently turns off all AdColony ads for this app on the current device.

After this method is called, no ads will be played unless the app is deleted and reinstalled.
This method could be used in the implementation of an In-App Purchase to disable ads;
make sure to allow In-App Purchases to be restored by the user in the case of deleting and reinstalling the app.
@note this function only available on ios
sdkbox.PluginAdColony.setUserMetadata(metadataType, value);

Provide AdColony with per-user non personally-identifiable information for ad targeting purposes.

Providing non personally-identifiable information using this API will improve targeting and unlock
improved earnings for your app. [This support article](http://support.adcolony.com/customer/portal/articles/700183-sdk-user-metadata-pass-through) contains usage guidelines.
@note this function only available on ios
sdkbox.PluginAdColony.userInterestedIn(topic);

Provide AdColony with real-time feedback about what a user is interested in.

Providing non personally-identifiable information using this API will improve targeting and unlock
improved earnings for your app. [This support article](http://support.adcolony.com/customer/portal/articles/700183-sdk-user-metadata-pass-through) contains usage guidelines.
You can call this as often as you want with various topics that the user has engaged in
within your app or as the user engages in them. For example, if the user has started browsing
the finance section of a news app, a developer should call: `[AdColony userInterestedIn:@"finance"]`.
@note this function only available on ios
sdkbox.PluginAdColony.notifyIAPComplete(transactionID,
                                         productID,
                                         quantity,
                                         price,
                                         currencyCode);

Call this method to report IAPs within your application. Note that this API can be leveraged to report standard IAPs as well as those triggered by AdColony’s IAP Promo (IAPP) advertisements and will improve overall ad targeting.

@see onAdColonyIAPRequest:quantity
sdkbox.PluginAdColony.requestAllAds();

Request all ads

Listeners

adColonyInterstitialDidLoad(adName);

called when AdColony interstitial has loaded.

adColonyInterstitialDidFailToLoad(error);

called when AdColony interstitial loaded failed.

adColonyAdViewDidLoad(adName);

called when AdColony banner has loaded.

adColonyAdViewDidFailToLoad(error);

called when AdColony banner loaded failed.

adColonyReward(name, currencyName, amount, success);

reward was received.

Manual Integration

If the SDKBOX Installer fails to complete successfully, it is possible to integrate SDKBOX manually. If the installer complete successfully, please do not complete anymore of this document. It is not necessary.

These steps are listed last in this document on purpose as they are seldom needed. If you find yourself using these steps, please, after completing, double back and re-read the steps above for other integration items.

Manual Integration For iOS

Drag and drop the following frameworks from the plugins/ios folder of the AdColony bundle into your Xcode project, check Copy items if needed when adding frameworks:

sdkbox.framework

PluginAdColony.framework

AdColony.framework

The above frameworks depend upon a large number of other frameworks. You also need to add the following system frameworks, if you don't already have them:

libz.1.2.5.dylib

AdSupport.framework (Set to Optional)

AudioToolbox.framework

AVFoundation.framework

CoreGraphics.framework

CoreMedia.framework

CoreTelephony.framework

EventKit.framework

EventKitUI.framework

MediaPlayer.framework

MessageUI.framework

QuartzCore.framework

Security.framework

GameController.framework

Social.framework (Set to Optional)

StoreKit.framework (Set to Optional)

SystemConfiguration.framework

WebKit.framework (Set to Optional)

Add two separate linker flags to: Target -> Build Settings -> Linking -> Other Linker Flags:

-ObjC

-fobjc-arc (this allows AdColony to use ARC even if your project does not)

Copy all source and header files from plugin/jsbindings/ to your projects Classes folder.

NOTE: plugin/jsbindings/jsb2 for creator 1.7.

Add these same files, that you just copied, to Xcode by either dragging and dropping them into Xcode or by using File -> Add files to....

Manual Integration For Android

SDKBOX supports three different kinds of Android projects command-line, eclipse and Android Studio.

Copy Files

Copy the following jar files from plugin/android/libs folder of this bundle into your project's /libs folder.

adcolony.jar

PluginAdColony.jar

sdkbox.jar

Copy jni libs

Copy and overwrite all the folders from plugin/android/jni to your <project_root>/jni/ directory.

Edit AndroidManifest.xml

Include the following permissions above the application tag:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />

To enable hardware acceleration in your application tag. This tag is optional on newer SDK versions and doesn't work on version 2.3.3.

<android:hardwareAccelerated="true" />

Copy and paste the following three activity definitions just before the end of the application tags, near the bottom.

<activity android:name="com.jirbo.adcolony.AdColonyOverlay"
      android:configChanges="keyboardHidden|orientation"
      android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" />
<activity android:name="com.jirbo.adcolony.AdColonyFullscreen"
      android:configChanges="keyboardHidden|orientation"
      android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" />
<activity android:name="com.jirbo.adcolony.AdColonyBrowser"
      android:configChanges="keyboardHidden|orientation"
      android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" />

Note: if your application targets below API 13, you will likely need to remove screenSize from the configChanges property of the above activity tags.

Edit Android.mk

Edit <project_root>/jni/Android.mk to:

Add additional requirements to LOCAL_WHOLE_STATIC_LIBRARIES:

LOCAL_WHOLE_STATIC_LIBRARIES += PluginAdColony
LOCAL_WHOLE_STATIC_LIBRARIES += sdkbox

Add a call to:

$(call import-add-path,$(LOCAL_PATH))

before any import-module statements.

Add additional import-module statements at the end:

$(call import-module, ./sdkbox)
$(call import-module, ./pluginadcolony)

This means that your ordering should look similar to this:

$(call import-add-path,$(LOCAL_PATH))
$(call import-module, ./sdkbox)
$(call import-module, ./pluginadcolony)

Note: It is important to make sure these statements are above the existing $(call import-module,./prebuilt-mk) statement, if you are using the pre-built libraries.

Modify Application.mk (Cocos2d-x v3.0 to v3.2 only)

Edit <project_root>/jni/Application.mk to make sure APP_STL is defined correctly. If Application.mk contains APP_STL := c++_static, it should be changed to:

APP_STL := gnustl_static

Copy all source and header files from plugin/jsbindings/ to your projects Classes folder.

NOTE: plugin/jsbindings/jsb2 for creator 1.7.

Add all .cpp files, that you just copied, to Android.mk in the LOCAL_SRC_FILES section. Example

LOCAL_SRC_FILES := hellocpp/main.cpp \
                  ../../Classes/AppDelegate.cpp \
                  ../../Classes/HelloWorldScene.cpp \
                                    ../../Classes/NewSourceFile.cpp

Modify AppActivity.java

Plugin >= 2.4.0.3

  1. Find the AppActivity.java
find . -name "AppActivity.java"
  1. Replace extends Cocos2dxActivity with extends com.sdkbox.plugin.SDKBoxActivity

Example of the directory where the AppActivity.java file is located:

cpp
  - proj.android/src/org/cocos2dx/cpp/AppActivity.java
  - proj.android-studio/app/src/org/cocos2dx/cpp/AppActivity.java
  - proj.android/app/src/org/cocos2dx/cpp/AppActivity.java ( from cocos2d-x 3.17)

lua
  - frameworks/runtime-src/proj.android/src/org/cocos2dx/lua/AppActivity.java
  - frameworks/runtime-src/proj.android-studio/app/src/org/cocos2dx/lua/AppActivity.java
  - frameworks/runtime-src/proj.android/app/src/org/cocos2dx/lua/AppActivity.java (from cocos2d-x 3.17)

js
  - frameworks/runtime-src/proj.android/src/org/cocos2dx/javascript/AppActivity.java
  - frameworks/runtime-src/proj.android/app/src/org/cocos2dx/javascript/AppActivity.java ( from cocos2d-x 3.17)

Plugin < 2.4.0.3

Note: When using Cocos2d-x from source, different versions have Cocos2dxActivity.java in a different location. One way to find the location is to look in proj.android/project.properties. Example: android.library.reference.1=../../cocos2d-x/cocos/platform/android/java

In this case, Cocos2dxActivity.java should be located at:

../../cocos2d-x/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxActivity.java
import android.content.Intent;
import com.sdkbox.plugin.SDKBox;
onLoadNativeLibraries();
SDKBox.init(this);
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
          if(!SDKBox.onActivityResult(requestCode, resultCode, data)) {
            super.onActivityResult(requestCode, resultCode, data);
          }
    }
    @Override
    protected void onStart() {
          super.onStart();
          SDKBox.onStart();
    }
    @Override
    protected void onStop() {
          super.onStop();
          SDKBox.onStop();
    }
    @Override
    protected void onResume() {
          super.onResume();
          SDKBox.onResume();
    }
    @Override
    protected void onPause() {
          super.onPause();
          SDKBox.onPause();
    }
    @Override
    public void onBackPressed() {
          if(!SDKBox.onBackPressed()) {
            super.onBackPressed();
          }
    }

Proguard (optional)

proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
# adcolony
-dontwarn android.webkit.**

-dontwarn com.jirbo.adcolony.**
-keep public class com.jirbo.adcolony.** { public *; }


# cocos2d-x
-keep public class org.cocos2dx.** { *; }
-dontwarn org.cocos2dx.**
-keep public class com.chukong.** { *; }
-dontwarn com.chukong.**

# google play service
-keep public class com.google.android.gms.** { public *; }
-dontwarn com.google.android.gms.**

-keep class com.google.protobuf.** { *; }
-dontwarn com.google.protobuf.**

-keep class * extends java.util.ListResourceBundle {
    protected Object[][] getContents();
}

-keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
    public static final *** NULL;
}

-keepnames @com.google.android.gms.common.annotation.KeepName class *
-keepclassmembernames class * {
    @com.google.android.gms.common.annotation.KeepName *;
}

-keepnames class * implements android.os.Parcelable {
    public static final ** CREATOR;
}

#sdkbox
-keep public class com.sdkbox.** { *; }
-dontwarn com.sdkbox.**

Note: Proguard only works with Release builds (i.e cocos run -m release) debug builds do not invoke Proguard rules.