‹ AdColony Doc Home

AdColony Integration Guide

For the C++ 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

Initialize AdColony

#include "PluginAdColony/PluginAdColony.h"
AppDelegate::applicationDidFinishLaunching()
{
     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.

#include "PluginAdColony/PluginAdColony.h"
class MyClass : public sdkbox::AdColonyListener
{
private:

    /*
     * Interstitial Callback
     */
    void adColonyInterstitialDidLoad(const std::string& interstitial);
    void adColonyInterstitialDidFailToLoad(const std::string& error);
    void adColonyInterstitialWillOpen(const std::string& interstitial);
    void adColonyInterstitialDidClose(const std::string& interstitial);
    void adColonyInterstitialExpired(const std::string& interstitial);
    void adColonyInterstitialWillLeaveApplication(const std::string& interstitial);
    void adColonyInterstitialDidReceiveClick(const std::string& interstitial);
    void adColonyInterstitialIapOpportunity(const std::string& interstitial, const std::string& iapProductID, int engagement);

    /*
     * Banner Callback
     */
    void adColonyAdViewDidLoad(const std::string& adView);
    void adColonyAdViewDidFailToLoad(const std::string& error);
    void adColonyAdViewWillLeaveApplication(const std::string& adView);
    void adColonyAdViewWillOpen(const std::string& adView);
    void adColonyAdViewDidClose(const std::string& adView);
    void adColonyAdViewDidReceiveClick(const std::string& adView);

    /*
     * Rewards Callback
     */
    void adColonyReward(const std::string name, const std::string& currencyName, int amount, bool success);

};
sdkbox::PluginAdColony::setListener(this);

API Reference

Methods

static void setGDPR ( bool enabled ) ;

Set GDPR

>>NOTE>>: please call before 'init' function
static void init ( ) ;

initialize the plugin instance.

static void show ( const std::string & name ) ;

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

static void setListener ( AdColonyListener * listener ) ;

Set listener to listen for adcolony events

static AdColonyListener * getListener ( ) ;

Get the listener

static void removeListener ( ) ;

Remove the listener, and can't listen to events anymore

static int zoneStatusForZone ( const std::string & zoneID ) ;

Returns the zone status for the specified zone.

@deprecated please use getStatus(name) instead
static AdColonyAdStatus getStatus ( const std::string & name ) ;

Check the availability of the adcolony ads by name

static void setCustomID ( const std::string & 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
static std::string getCustomID ( ) ;

Returns the device's current custom identifier.

@return The custom identifier string most recently set using `+ setCustomID:`.
@see setCustomID:
static std::string 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.
static std::string 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
static std::string 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
static int getVideosPerReward ( const std::string & currencyName ) ;

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

@note this function only available on ios
static int getVideoCreditBalance ( const std::string & currencyName ) ;

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

@note this function only available on ios
static void 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.
static bool 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
static void 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
static void setUserMetadata ( const std::string & metadataType ,
                              const std::string & 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
static void userInterestedIn ( const std::string & 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
static void notifyIAPComplete ( const std::string & transactionID ,
                                const std::string & productID ,
                                int quantity ,
                                float price ,
                                const std::string & 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
static void requestAllAds ( ) ;

Request all ads

Listeners

void adColonyInterstitialDidLoad(const std::string& interstitial) = 0;

called when AdColony interstitial is loaded

void adColonyInterstitialDidFailToLoad(const std::string& error) = 0;

called when AdColony interstitial fails to load

void adColonyInterstitialWillOpen(const std::string& interstitial) {};

called when AdColony interstitial will open

void adColonyInterstitialDidClose(const std::string& interstitial) {};

called when AdColony interstitial did close

void adColonyInterstitialExpired(const std::string& interstitial) {};

called when AdColony interstitial expired

void adColonyInterstitialWillLeaveApplication(const std::string& interstitial) {};

called when AdColony interstitial will leave application

void adColonyInterstitialDidReceiveClick(const std::string& interstitial) {};

called when AdColony interstitial did receive click

void adColonyInterstitialIapOpportunity(const std::string& interstitial, const std::string& iapProductID, int 
engagement) {};
void adColonyAdViewDidLoad(const std::string& adView) = 0;

called when AdColony banner is loaded

void adColonyAdViewDidFailToLoad(const std::string& error) = 0;

called when AdColony banner fails to load

void adColonyAdViewWillLeaveApplication(const std::string& adView) {};

called when AdColony banner will leave application

void adColonyAdViewWillOpen(const std::string& adView) {};

called when AdColony banner will open

void adColonyAdViewDidClose(const std::string& adView) {};

called when AdColony banner did close

void adColonyAdViewDidReceiveClick(const std::string& adView) {};

called when AdColony banner did receive click

void adColonyReward(const std::string& name, const std::string& currencyName, int amount, bool success) {};

called when AdColony banner reward

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)

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

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.