adjust-icon

Cocos2d-x SDK integration guide

The Adjust Android SDK enables you to record attribution, events, and more in your Cocos2d-x app. Follow the steps in this guide to set up your app to work with the Adjust SDK.

1. Install the SDK

To start using SDK v5, you need to add it as a dependency in your project. To do this:

  1. Download the SDK archive from GitHub

  2. Copy the C++ files from the dist directory and add them to your Cocos2d-x project

  3. (Android only): add the paths of the C++ files to the LOCAL_SRC_FILES section of your Android.mk file.

    $(LOCAL_PATH)/../../../Classes/Adjust/AdjustConfig2dx.cpp \
    $(LOCAL_PATH)/../../../Classes/Adjust/AdjustAttribution2dx.cpp \
    $(LOCAL_PATH)/../../../Classes/Adjust/AdjustProxy2dx.cpp \
    $(LOCAL_PATH)/../../../Classes/Adjust/AdjustEvent2dx.cpp \
    $(LOCAL_PATH)/../../../Classes/Adjust/Adjust2dx.cpp \
    $(LOCAL_PATH)/../../../Classes/Adjust/AdjustEventFailure2dx.cpp \
    $(LOCAL_PATH)/../../../Classes/Adjust/AdjustEventSuccess2dx.cpp \
    $(LOCAL_PATH)/../../../Classes/Adjust/AdjustSessionFailure2dx.cpp \
    $(LOCAL_PATH)/../../../Classes/Adjust/AdjustSessionSuccess2dx.cpp \
    $(LOCAL_PATH)/../../../Classes/Adjust/AdjustAppStoreSubscription2dx.cpp \
    $(LOCAL_PATH)/../../../Classes/Adjust/AdjustPlayStoreSubscription2dx.cpp \
    $(LOCAL_PATH)/../../../Classes/Adjust/AdjustThirdPartySharing2dx.cpp \
    $(LOCAL_PATH)/../../../Classes/Adjust/AdjustAdRevenue2dx.cpp
    $(LOCAL_PATH)/../../../Classes/Adjust/AdjustAppStorePurchase2dx.cpp \
    $(LOCAL_PATH)/../../../Classes/Adjust/AdjustPlayStorePurchase2dx.cpp \
    $(LOCAL_PATH)/../../../Classes/Adjust/AdjustDeeplink2dx.cpp \
    $(LOCAL_PATH)/../../../Classes/Adjust/AdjustPurchaseVerificationResult2dx.cpp \

    If you're using CMake, add the following list of sources and headers to your CMakeLists.txt file:

    # add cross-platforms source files and header files
    list(APPEND GAME_SOURCE
    Classes/Adjust/AdjustConfig2dx.cpp
    Classes/Adjust/AdjustAttribution2dx.cpp
    Classes/Adjust/AdjustProxy2dx.cpp
    Classes/Adjust/AdjustEvent2dx.cpp
    Classes/Adjust/AdjustAdRevenue2dx.cpp
    Classes/Adjust/AdjustAppStoreSubscription2dx.cpp
    Classes/Adjust/AdjustPlayStoreSubscription2dx.cpp
    Classes/Adjust/AdjustAppStorePurchase2dx.cpp
    Classes/Adjust/AdjustPlayStorePurchase2dx.cpp
    Classes/Adjust/Adjust2dx.cpp
    Classes/Adjust/AdjustEventFailure2dx.cpp
    Classes/Adjust/AdjustEventSuccess2dx.cpp
    Classes/Adjust/AdjustSessionFailure2dx.cpp
    Classes/Adjust/AdjustSessionSuccess2dx.cpp
    Classes/Adjust/AdjustThirdPartySharing2dx.cpp
    Classes/Adjust/AdjustDeeplink2dx.cpp
    Classes/Adjust/AdjustPurchaseVerificationResult2dx.cpp
    )
    list(APPEND GAME_HEADER
    Classes/Adjust/AdjustConfig2dx.h
    Classes/Adjust/AdjustAttribution2dx.h
    Classes/Adjust/AdjustProxy2dx.h
    Classes/Adjust/AdjustEvent2dx.h
    Classes/Adjust/AdjustAdRevenue2dx.h
    Classes/Adjust/AdjustAppStoreSubscription2dx.h
    Classes/Adjust/AdjustPlayStoreSubscription2dx.h
    Classes/Adjust/AdjustAppStorePurchase2dx.h
    Classes/Adjust/AdjustPlayStorePurchase2dx.h
    Classes/Adjust/Adjust2dx.h
    Classes/Adjust/AdjustEventFailure2dx.h
    Classes/Adjust/AdjustEventSuccess2dx.h
    Classes/Adjust/AdjustSessionFailure2dx.h
    Classes/Adjust/AdjustSessionSuccess2dx.h
    Classes/Adjust/AdjustThirdPartySharing2dx.h
    Classes/Adjust/AdjustDeeplink2dx.h
    Classes/Adjust/AdjustPurchaseVerificationResult2dx.h
    )
  4. (Android only): download the latest adjust-android.aar from the GitHub releases page and import it into your Android Studio project.

  5. (iOS only): download the latest AdjustSdk.framework from the GitHub releases page and link it in your Xcode project.

2. Set up the Signature library

SDK v5 uses the SDK signature library to encrypt information sent from the Adjust SDK to Adjust's servers. You MUST add the signature library to your project to use SDK v5.

Android apps

  1. Download the latest adjust-android-signature.aar from the Adjust Signature library GitHub repository.
  2. Add the .aar to your Android Studio project.

iOS apps

  1. Download the latest AdjustSigSdk-iOS-Static.a from the Adjust Signature library GitHub repository.
  2. Link the .a in your Xcode project.

3. Configure Android settings

Follow these steps to configure the Adjust SDK for Android devices.

Permissions

The Adjust Android SDK comes with required permissions preconfigured. This includes the com.google.android.gms.permission.AD_ID permission. If your app needs to be compliant with the Children's Online Privacy Protection Act (COPPA), you MUST remove this permission by adding the following to your AndroidManifest.xml file:

<uses-permission android:name="com.google.android.gms.permission.AD_ID" tools:node="remove"/>

To learn more about COPPA, read Adjust's COPPA compliance article.

Add Google Play Services

Apps that target the Google Play Store must use the Google Advertising ID (gps_adid) to identify devices. To do this, add the following dependency to the dependencies section of your build.gradle file.

dependencies: {
implementation 'com.google.android.gms:play-services-ads-identifier:18.1.0'
}

Set up install referrer

The install referrer is an attribution mechanism you can use to attribute an app install to a source. It consists of two parts:

  • A set of APIs from these app stores that allow developers to retrieve referral content in their apps.
  • A referrer parameter that app stores, such as Google Play and Huawei App Gallery, accept in their app page URLs on their store websites. Here is how the referrer parameter is populated:
    • When a user clicks on an Adjust link, the Adjust server passes a unique identifier called reftag. This identifier is assigned to the click and into the referrer parameter. To learn more about reftag, see the Reftag article in the Help Center.
    • When you run Google Ads campaigns, Google passes a unique identifier called gclid into the referrer parameter. You MUST enable Auto-tagging in your Google Ads account.

Google Play Referrer API

To support the Google Play Referrer API, follow these steps:

  1. Add the Google Maven repository to your build.gradle file.

    allprojects {
    repositories {
    maven {
    url "https://maven.google.com"
    }
    }
    }
  2. Add the Install Referrer library to your build.gradle file.

    dependencies {
    implementation 'com.android.installreferrer:installreferrer:2.2'
    }

Meta Install Referrer

The Adjust SDK supports the Meta Install Referrer using the Adjust Meta Install Referrer plugin. See the Cocos2d-x Meta Install Referrer plugin for integration details.

4. Configure iOS settings

Follow these steps to configure the Adjust SDK for iOS devices.

Link the following frameworks to your Xcode project to give the Adjust SDK access to device-level information.

FrameworkPurposeNotes
AdSupport.frameworkRequired to enable the Adjust SDK to read the device IDFA.You MUST NOT add this framework if your app targets the "Kids" category
AdServices.frameworkRequired for handling Apple Search Ads
StoreKit.frameworkRequired to access the SKAdNetwork framework and for the Adjust SDK to handle communications with SKAdNetwork.
AppTrackingTransparency.frameworkRequired in iOS 14 and later to enable the Adjust SDK to wrap the ATT consent dialog and access the user's consent response.You SHOULD NOT add this framework if your app targets the "Kids" category

Copy additional source files

To complete iOS setup, you MUST copy all Objective-C++ (.h and .mm) files from the dist directory of the unzipped SDK archive to your Xcode project. Ensure that all .mm files are listed in the Build Phases --> Compile Sources section.

Update your app's privacy manifest

To inform the App Store of the Adjust SDK's privacy requirements, you need to merge your privacy manifest with Adjust's privacy manifests.

  1. Add the Adjust SDK privacy manifest properties to your app's privacy manifest.
  2. Add the Signature library privacy manifest properties to your app's privacy manifest.

6. Integrate the Adjust SDK

Once you've updated your project settings, you can integrate the Adjust SDK into your app. To do this:

  1. Find your application delegate file in the Project Navigator and open it.

  2. Include the Adjust/Adjust2dx.h class at the top of the file.

  3. Instantiate an AdjustConfig2dx object with the following arguments:

    appToken (std::string)

    Your Adjust app token

    environment (std::string)

    PassAdjustEnvironmentSandbox2dxto test your app in a sandbox environment.

  4. Optionally adjust your logging level to adjust the verbosity of your logging.

  5. Call the Adjust2dx::initSdk method and pass your AdjustConfig2dx instance as an argument as soon as possible after the app is launched.

#include "Adjust/Adjust2dx.h"
std::string appToken = "{YOUR_APP_TOKEN}";
std::string environment = AdjustEnvironmentSandbox2dx;
AdjustConfig2dx adjustConfig = AdjustConfig2dx(appToken, environment);
adjustConfig.setLogLevel(AdjustLogLevel2dxVerbose);
Adjust2dx::initSdk(adjustConfig);

7. Build your app

Well done! You should now be able to build and run your Cocos2d-x app. Enable logging to check for any issues. Check your logs to see the Install tracked message.

You are ready to start attributing your users with the Adjust SDK.