‹ Valuepotion Doc Home

Valuepotion Integration Guide

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

SDK Version


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

$ sdkbox import valuepotion

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:


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 ValuePotion configuration, you need to replace <client id> and <secret key> items with your specific Valuepotion ID account information. <sender id> item valid on android, which is GCM(google cloud message) project number id



Initialize Valuepotion

Initialize the plugin where appropriate in your code. We recommend to do this in the AppDelegate::applicationDidFinishLaunching() or AppController:didFinishLaunchingWithOptions(). Make sure to include the appropriate headers:

#include "PluginValuePotion/PluginValuePotion.h"

Using Valuepotion

After initialization you can begin to use the Valuepotion functionality.


sdkbox::PluginValuePotion::trackEvent("test event");
sdkbox::PluginValuePotion::trackEvent("test event with value 23", 23);
sdkbox::PluginValuePotion::trackEvent("category", "event name", "label", 45);

sdkbox::PluginValuePotion::trackPurchaseEvent("test event", 56, "RMB", "order id", "product id");
sdkbox::PluginValuePotion::trackPurchaseEvent("test event", 67, "USD", "order id", "product id", "campaign id", "content id");
sdkbox::PluginValuePotion::trackPurchaseEvent("categroy", "event name", "label", 78, "ILY", "order id", "product id", "campaign id", "content id");

sdkbox::PluginValuePotion::userinfo("id", "user id");
sdkbox::PluginValuePotion::userinfo("serverid", "server id");
sdkbox::PluginValuePotion::userinfo("birth", "19991111"); //YYYYMMDD
sdkbox::PluginValuePotion::userinfo("gender", "M");
sdkbox::PluginValuePotion::userinfo("level", "9");
sdkbox::PluginValuePotion::userinfo("friends", "3");
sdkbox::PluginValuePotion::userinfo("accounttype", "facebook");

Catch Valuepotion events (optional)

This allows you to catch the Valuepotion events so that you can perform operations based upon responses. A simple example might look like this:

#include "PluginValuePotion/PluginValuePotion.h"
class MyClass : public sdkbox::ValuePotionListener
    virtual void onCacheInterstitial(const char *placement);

    virtual void onFailToCacheInterstitial(const char *placement, const char *errorMessage);

    virtual void onOpenInterstitial(const char *placement);

    virtual void onFailToOpenInterstitial(const char *placement, const char *errorMessage);

    virtual void onCloseInterstitial(const char *placement);

    virtual void onRequestOpenURL(const char *placement, const char *URL);

    virtual void onRequestPurchase(const char *placement, const char *name, const char *productId, int quantity, const char *campaignId, const char *contentId);

    virtual void onRequestRewards(const char *placement, std::vector<sdkbox::ValuePotionReward> rewards);

API Reference


static bool init ( ) ;

initialize the plugin instance.

static void setListener ( ValuePotionListener * listener ) ;

Set listener to listen for adcolony events

static ValuePotionListener * getListener ( ) ;

Get the listener

static void removeListener ( ) ;

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

static void setTest ( bool isTest ) ;

for intergation test

static bool hasCachedInterstitial ( const char * placement ) ;

check if ad is cached

static void cacheInterstitial ( const char * placement ) ;

cached ad

static void openInterstitial ( const char * placement ) ;

show ad

static void trackEvent ( const char * eventName ) ;

track game event

static void trackEvent ( const char * eventName , double eventValue ) ;
static void trackEvent ( const char * category ,
                         const char * eventName ,
                         const char * label ,
                         double eventValue ) ;
static void trackPurchaseEvent ( const char * eventName ,
                                 double revenueAmount ,
                                 const char * currency ,
                                 const char * orderId ,
                                 const char * productId ) ;

track purchase event

static void trackPurchaseEvent ( const char * eventName ,
                                 double revenueAmount ,
                                 const char * currency ,
                                 const char * orderId ,
                                 const char * productId ,
                                 const char * campaignId ,
                                 const char * contentId ) ;
static void trackPurchaseEvent ( const char * category ,
                                 const char * eventName ,
                                 const char * label ,
                                 double revenueAmount ,
                                 const char * currency ,
                                 const char * orderId ,
                                 const char * productId ,
                                 const char * campaignId ,
                                 const char * contentId ) ;
static void userinfo ( const char * attribute , const char * value ) ;

set user info

Field              Description
userId             User account id used in game
serverId           If you need to distinguish users by server which they belong to, you should set serverId. Then you can get statistics based on serverId.
birth              Date of birth in YYYYMMDD. If you know only year of birth, fill last four digits with "0" like "19840000". If you know only date of birth(but not year), fill first four digits with "0" like "00001109".
gender             "M" for male, "F" for female.
level              Level of user in game.
friends            Number of user's friends.
accountType        Type of user's account type. (facebook, google, guest, etc)


void onCacheInterstitial ( const char * placement ) 
void onFailToCacheInterstitial ( const char * placement ,
                                 const char * errorMessage ) 
void onOpenInterstitial ( const char * placement ) 
void onFailToOpenInterstitial ( const char * placement ,
                                const char * errorMessage ) 
void onCloseInterstitial ( const char * placement ) 
void onRequestOpenURL ( const char * placement , const char * URL ) 
void onRequestPurchase ( const char * placement ,
                         const char * name ,
                         const char * productId ,
                         int quantity ,
                         const char * campaignId ,
                         const char * contentId ) 
void onRequestRewards ( const char * placement ,
                        std::vector <ValuePotionReward> rewards ) 

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 ValuePotion bundle into your Xcode project, check Copy items if needed when adding frameworks:



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







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.




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.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

There are also a few necessary tags that also need to be added:



<meta-data android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />

<!-- Valuepotion Components -->
<!-- for interstital ad interface -->
        android:theme="@android:style/Theme.Translucent" >

<!-- for CPI tracking -->
        android:exported="true" >
                <action android:name="com.android.vending.INSTALL_REFERRER" />
<!-- Valuepotion Components End -->



Edit Android.mk

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

Add additional requirements to LOCAL_WHOLE_STATIC_LIBRARIES:


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, ./pluginvaluepotion)

This means that your ordering should look similar to this:

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

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 >=

  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:

  - 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)

  - 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)

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

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:

import android.content.Intent;
import com.sdkbox.plugin.SDKBox;
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
          if(!SDKBox.onActivityResult(requestCode, resultCode, data)) {
            super.onActivityResult(requestCode, resultCode, data);
    protected void onStart() {
    protected void onStop() {
    protected void onResume() {
    protected void onPause() {
    public void onBackPressed() {
          if(!SDKBox.onBackPressed()) {

Manual Integration for Google Play Services SDK (dependent library only)


Please try the SDKBOX installer first. It will do all the following step for you automatically.

$ sdkbox import googleplayservices

Modify project.properties

An Android Library Reference for Google Play Services is required. The path will be different depending upon your setup. Also, this is an additional download that does not come as part of a standard install. To install use the sdk installer and choose extras->google play services. Here is an example of what this line could look like:


Note: if you already have an android.library.reference.1 you can add another by incrementing the number as android.library.reference.2, etc.

Integration manually

We make a lite version of Google Play Services, the project repo is https://github.com/darkdukey/Google-Play-Service-Lite

Copy Files

Copy the gps folder from plugin folder of this bundle into your project's /libs folder.

Modify files for Eclipse

  1. Modify project.properties
# For source project

# Or
# For framework project

Modify files for Android Studio

1. Modify cocos2d/cocos/platform/android/libcocos2dx/build.gradle
 dependencies {
+    compile project(':gps')
     compile fileTree(dir: '../java/libs', include: ['*.jar'])
2. Modify proj.android-studio/app/project.properties
 # Project target.
3. Modify proj.android-studio/settings.gradle
 project(':libcocos2dx').projectDir = new File(settingsDir, '../cocos2d/cocos/platform/android/libcocos2dx')
 include ':your_project_name'
 project(':your_project_name').projectDir = new File(settingsDir, 'app')
+include ':gps'
+project(':gps').projectDir = new File(settingsDir, '../cocos2d/cocos/platform/android/java/libs/gps')

Proguard (optional)

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
#   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;

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

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

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