Skip to content

Commit

Permalink
Merge pull request #46 from AppsFlyerSDK/dev/DELIVERY-55467/supportin…
Browse files Browse the repository at this point in the history
…g-dma

Dev/delivery 55467/supporting dma
  • Loading branch information
morisgateno-appsflyer authored Mar 7, 2024
2 parents 19ab441 + f56b368 commit e024773
Show file tree
Hide file tree
Showing 16 changed files with 453 additions and 60 deletions.
21 changes: 15 additions & 6 deletions Classes/AppDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,18 @@ static void didResolveDeepLink(AppsFlyerXDeepLinkResult result){
bool AppDelegate::applicationDidFinishLaunching() {

AppsFlyerX::stop(false);

// AppsFlyerX::enableTCFDataCollection(true);
AppsFlyerX::setIsDebug(true);
// AppsFlyerX::setConsentData(AppsFlyerXConsent::initNonGDPRUser());
// AppsFlyerX::setConsentData(AppsFlyerXConsent::initForGDPRUser(true,true));
//AppsFlyerX::setMinTimeBetweenSessions(9);
AppsFlyerX::setAppsFlyerDevKey("devkey");

#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
AppsFlyerX::setAppleAppID("appid");
// // In case you want to use manual mode.
// AppsFlyerX::setManualStart(true);
// //
AppsFlyerX::setAppleAppID("appleAppId");
// AppsFlyerX::waitForATTUserAuthorizationWithTimeoutInterval(60);

#endif
Expand All @@ -166,10 +171,12 @@ bool AppDelegate::applicationDidFinishLaunching() {
data["isLegacy"] = false;
AppsFlyerX::setPartnerData("partnerID", data);

AppsFlyerX::logEvent(AFEventPurchase, {{ "key1", cocos2d::Value("value1")},
{ "key2", cocos2d::Value("value2")}});
// AppsFlyerX::logEvent(AFEventPurchase, {{ "key1", cocos2d::Value("value1")},
// { "key2", cocos2d::Value("value2")}});
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
AppsFlyerX::start();
// remove this to use manual mode.
AppsFlyerX::start();
//
#endif

// initialize director
Expand Down Expand Up @@ -241,7 +248,9 @@ void AppDelegate::applicationWillEnterForeground() {
//CCLOG("%s", "~+~+~+~+~ applicationWillEnterForeground ~+~+~+~+~");

#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
AppsFlyerX::start();
// remove this to use manual mode.
AppsFlyerX::start();
//
#endif

#if USE_AUDIO_ENGINE
Expand Down
22 changes: 22 additions & 0 deletions Classes/AppsFlyer/AppsFlyerX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,28 @@
#include "AppsFlyerXApple.h"
#endif

bool AppsFlyerX::manualStart = false;

void AppsFlyerX::setManualStart(bool isManualStart) {
manualStart = isManualStart;
}

//static void enableTCFDataCollection(bool shouldCollectConsentData);
void AppsFlyerX::enableTCFDataCollection(bool shouldCollectConsentData) {
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
AppsFlyerXAndroid::enableTCFDataCollection(shouldCollectConsentData);
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
AppsFlyerXApple::enableTCFDataCollection(shouldCollectConsentData);
#endif
}

void AppsFlyerX::setConsentData(const AppsFlyerXConsent& consentData){
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
AppsFlyerXAndroid::setConsentData(consentData);
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
AppsFlyerXApple::setConsentData(consentData);
#endif
}

void AppsFlyerX::setCustomerUserID(const std::string& customerUserID) {
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
Expand Down
9 changes: 8 additions & 1 deletion Classes/AppsFlyer/AppsFlyerX.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,18 @@
#include "EmailCryptTypeX.h"
#include "AppsFlyerXMacro.h"
#include "AppsFlyerXDeepLinkResult.h"
#include "AppsFlyerXConsent.cpp"


class AppsFlyerX {
public:

static bool manualStart;
static void setManualStart(bool isManualStart);

static void enableTCFDataCollection(bool shouldCollectConsentData);

static void setConsentData(const AppsFlyerXConsent& consentData);

static void setCustomerUserID(const std::string& customerUserID);
static std::string customerUserID();

Expand Down
166 changes: 136 additions & 30 deletions Classes/AppsFlyer/AppsFlyerXAndroid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ std::string afDevKey;
bool isConveriosnListenerInitialized = false;
bool isSubscribedForDeepLink = false;

const char *pluginVersion = "6.10.3";
const char *pluginVersion = "6.13.0";

// Headers
void initConvertionCallback();
Expand Down Expand Up @@ -50,6 +50,72 @@ cocos2d::JniMethodInfo getAppsFlyerInstance() {
return jniGetInstance;
}

/*
* AppsFlyerLib.getInstance().enableTCFDataCollection(true);
*/

void AppsFlyerXAndroid::enableTCFDataCollection(bool shouldCollectConsentData) {
callVoidMethodWithBoolParam(shouldCollectConsentData, "enableTCFDataCollection", "(Z)V");
}

void AppsFlyerXAndroid::setConsentData(const AppsFlyerXConsent& consentData){
cocos2d::JniMethodInfo jniGetConsentInstance;
jobject resultConsent;

if (consentData.IsUserSubjectToGDPR()) {
bool hasConsentForDataUsage = consentData.HasConsentForDataUsage();
bool hasConsentForAdsPersonalization = consentData.HasConsentForAdsPersonalization();
jboolean jHasConsentForDataUsage = (jboolean)hasConsentForDataUsage;
jboolean jHasConsentForAdsPersonalization = (jboolean)hasConsentForAdsPersonalization;
if (cocos2d::JniHelper::getStaticMethodInfo(jniGetConsentInstance,
"com/appsflyer/AppsFlyerConsent",
"forGDPRUser",
"(ZZ)Lcom/appsflyer/AppsFlyerConsent;")) {

resultConsent = (jobject) jniGetConsentInstance.
env->CallStaticObjectMethod(jniGetConsentInstance.classID, jniGetConsentInstance.methodID,
jHasConsentForDataUsage,
jHasConsentForAdsPersonalization);
}
else{
CCLOG("%s", "'AppsFlyerConsent' is not loaded");
return;
}
}
else{
if (cocos2d::JniHelper::getStaticMethodInfo(jniGetConsentInstance,
"com/appsflyer/AppsFlyerConsent",
"forNonGDPRUser",
"()Lcom/appsflyer/AppsFlyerConsent;")) {
resultConsent = (jobject) jniGetConsentInstance.
env->CallStaticObjectMethod(jniGetConsentInstance.classID, jniGetConsentInstance.methodID);
}
else{
CCLOG("%s", "'AppsFlyerConsent' is not loaded");
return;
}
}
cocos2d::JniMethodInfo jniGetInstance = getAppsFlyerInstance();

jobject afInstance = (jobject) jniGetInstance.env->CallStaticObjectMethod(
jniGetInstance.classID, jniGetInstance.methodID);

if (NULL != afInstance) {

jclass cls = jniGetInstance.env->GetObjectClass(afInstance);

jmethodID methodId = jniGetInstance.env->GetMethodID(cls, "setConsentData", "(Lcom/appsflyer/AppsFlyerConsent;)V");

jniGetInstance.env->CallVoidMethod(afInstance, methodId, resultConsent);

jniGetInstance.env->DeleteLocalRef(resultConsent);
jniGetInstance.env->DeleteLocalRef(afInstance);
jniGetInstance.env->DeleteLocalRef(jniGetInstance.classID);
} else {
CCLOGERROR("%s", "'AppsFlyerLib' is not loaded");
}

}

void AppsFlyerXAndroid::stop(bool shouldStop) {

Expand Down Expand Up @@ -277,26 +343,8 @@ void AppsFlyerXAndroid::start() {
jniGetInstance.classID, jniGetInstance.methodID);

if (NULL != afInstance) {
//CCLOG("%s", "com/appsflyer/AppsFlyerLib is loaded");

jclass cls = jniGetInstance.env->GetObjectClass(afInstance);

jclass clsExtension = jniGetInstance.env->FindClass("com/appsflyer/internal/platform_extension/PluginInfo");



jmethodID extensionConstructor = jniGetInstance.env->GetMethodID(clsExtension,
"<init>","(Lcom/appsflyer/internal/platform_extension/Plugin;Ljava/lang/String;)V");

jclass enumClass = jniGetInstance.env->FindClass("com/appsflyer/internal/platform_extension/Plugin");
jfieldID fid = jniGetInstance.env->GetStaticFieldID(enumClass, "COCOS_2DX","Lcom/appsflyer/internal/platform_extension/Plugin;");
jobject plugin = jniGetInstance.env->GetStaticObjectField(enumClass, fid);
jstring version = jniGetInstance.env->NewStringUTF(pluginVersion);
jobject extensionObject = jniGetInstance.env->NewObject(clsExtension, extensionConstructor, plugin, version);

callSetPluginInfo(extensionObject);


cocos2d::JniMethodInfo jniGetContext;

if (!cocos2d::JniHelper::getStaticMethodInfo(jniGetContext,
Expand All @@ -312,17 +360,6 @@ void AppsFlyerXAndroid::start() {

jstring jAppsFlyerDevKey = jniGetInstance.env->NewStringUTF(afDevKey.c_str());

// call Init if no GCD registered
if (!isConveriosnListenerInitialized) {
jmethodID initMethodId = jniGetInstance.env->GetMethodID(cls,
"init",
"(Ljava/lang/String;Lcom/appsflyer/AppsFlyerConversionListener;Landroid/content/Context;)Lcom/appsflyer/AppsFlyerLib;");

// This is what we actually do: afLib.init(appsFlyerDevKey, null)
jniGetInstance.env->CallObjectMethod(afInstance, initMethodId, jAppsFlyerDevKey, NULL, jContext);
}

//public void trackAppLaunch(Context ctx, String devKey)
jmethodID startTrackingMethodId = jniGetInstance.env->GetMethodID(cls,
"start",
"(Landroid/content/Context;Ljava/lang/String;)V");
Expand Down Expand Up @@ -412,6 +449,75 @@ void AppsFlyerXAndroid::setUserEmails(std::vector<std::string> userEmails, Email

void AppsFlyerXAndroid::setAppsFlyerDevKey(const std::string &appsFlyerDevKey) {
afDevKey = appsFlyerDevKey;

if (afDevKey.empty()) {
CCLOGWARN("%s", "AppsFlyer Dev Key is not provided");
return;
}

cocos2d::JniMethodInfo jniGetInstance = getAppsFlyerInstance();

//AppsFlyerLib afLib instance
jobject afInstance = (jobject) jniGetInstance.env->CallStaticObjectMethod(
jniGetInstance.classID, jniGetInstance.methodID);

if (NULL != afInstance) {
//CCLOG("%s", "com/appsflyer/AppsFlyerLib is loaded");

jclass cls = jniGetInstance.env->GetObjectClass(afInstance);

jclass clsExtension = jniGetInstance.env->FindClass(
"com/appsflyer/internal/platform_extension/PluginInfo");


jmethodID extensionConstructor = jniGetInstance.env->GetMethodID(clsExtension,
"<init>",
"(Lcom/appsflyer/internal/platform_extension/Plugin;Ljava/lang/String;)V");

jclass enumClass = jniGetInstance.env->FindClass(
"com/appsflyer/internal/platform_extension/Plugin");
jfieldID fid = jniGetInstance.env->GetStaticFieldID(enumClass, "COCOS_2DX",
"Lcom/appsflyer/internal/platform_extension/Plugin;");
jobject plugin = jniGetInstance.env->GetStaticObjectField(enumClass, fid);
jstring version = jniGetInstance.env->NewStringUTF(pluginVersion);
jobject extensionObject = jniGetInstance.env->NewObject(clsExtension, extensionConstructor,
plugin, version);

callSetPluginInfo(extensionObject);


cocos2d::JniMethodInfo jniGetContext;

if (!cocos2d::JniHelper::getStaticMethodInfo(jniGetContext,
"org/cocos2dx/lib/Cocos2dxActivity",
"getContext",
"()Landroid/content/Context;")) {
return;
}

jobject jContext = (jobject) jniGetContext.env->CallStaticObjectMethod(
jniGetContext.classID, jniGetContext.methodID);


jstring jAppsFlyerDevKey = jniGetInstance.env->NewStringUTF(afDevKey.c_str());

// call Init if no GCD registered
if (!isConveriosnListenerInitialized) {
jmethodID initMethodId = jniGetInstance.env->GetMethodID(cls,
"init",
"(Ljava/lang/String;Lcom/appsflyer/AppsFlyerConversionListener;Landroid/content/Context;)Lcom/appsflyer/AppsFlyerLib;");

// This is what we actually do: afLib.init(appsFlyerDevKey, null)
jniGetInstance.env->CallObjectMethod(afInstance, initMethodId, jAppsFlyerDevKey, NULL,
jContext);

jniGetInstance.env->DeleteLocalRef(afInstance);
jniGetInstance.env->DeleteLocalRef(jniGetInstance.classID);
}
}
else {
CCLOGERROR("%s", "'AppsFlyerLib' is not loaded");
}
}

std::string AppsFlyerXAndroid::appsFlyerDevKey() {
Expand Down
6 changes: 6 additions & 0 deletions Classes/AppsFlyer/AppsFlyerXAndroid.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

#include "EmailCryptTypeX.h"
#include "AppsFlyerXDeepLinkResult.h"
#include "AppsFlyerX.h"


class AppsFlyerXAndroid {
private:
Expand All @@ -24,6 +26,10 @@ class AppsFlyerXAndroid {

static AppsFlyerXAndroid* getInstance();

static void enableTCFDataCollection(bool shouldCollectConsentData);

static void setConsentData(const AppsFlyerXConsent& consentData);

static void didEnterBackground();

static void setCustomerUserID(const std::string& customerUserID);
Expand Down
4 changes: 4 additions & 0 deletions Classes/AppsFlyer/AppsFlyerXApple.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ class AppsFlyerXApple {

static AppsFlyerXApple* getInstance();

static void enableTCFDataCollection(bool shouldCollectConsentData);

static void setConsentData(const AppsFlyerXConsent& consentData);

static void setCustomerUserID(const std::string& customerUserID);
static std::string customerUserID();

Expand Down
23 changes: 20 additions & 3 deletions Classes/AppsFlyer/AppsFlyerXApple.mm
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
//



#include "AppsFlyerX.h"
#include "AppsFlyerXApple.h"
#include "AppsFlyerXAppleHelper.h"
#include "AppsFlyerXAppleDelegate.h"
#include "AppsFlyerXAppleDeepLinkDelegate.h"
#import "libAppsFlyer/AppsFlyerLib.h"
#import <UIKit/UIKit.h>


/* Null, because instance will be initialized on demand. */
AppsFlyerXApple* AppsFlyerXApple::instance = 0;
Expand All @@ -37,6 +39,19 @@

AppsFlyerXApple::AppsFlyerXApple() {}

void AppsFlyerXApple::enableTCFDataCollection(bool shouldCollectConsentData){
[[AppsFlyerLib shared] enableTCFDataCollection:shouldCollectConsentData];
}

void AppsFlyerXApple::setConsentData(const AppsFlyerXConsent& consentData){
if (consentData.IsUserSubjectToGDPR()){
[[AppsFlyerLib shared] setConsentData:[[AppsFlyerConsent alloc] initForGDPRUserWithHasConsentForDataUsage:consentData.HasConsentForDataUsage() hasConsentForAdsPersonalization:consentData.HasConsentForAdsPersonalization()]];
}
else{
[[AppsFlyerLib shared] setConsentData:[[AppsFlyerConsent alloc] initNonGDPRUser]];
}
}

void AppsFlyerXApple::setCustomerUserID(const std::string& customerUserID) {
[[AppsFlyerLib shared] setCustomerUserID: [NSString stringWithUTF8String:customerUserID.c_str()]];
}
Expand All @@ -59,7 +74,7 @@
static AppsFlyerXApple *xApple = nil;
static AppsFlyerXAppleDelegate *delegate = nil;
[[AppsFlyerLib shared] setPluginInfoWith: AFSDKPluginCocos2dx
pluginVersion:@"6.10.3"
pluginVersion:@"6.13.1"
additionalParams:nil];
dispatch_once(&onceToken, ^{

Expand All @@ -71,7 +86,9 @@
object: nil
queue: nil
usingBlock: ^ (NSNotification * note) {
[[AppsFlyerLib shared] start];
if (AppsFlyerX::manualStart == false) {
[[AppsFlyerLib shared] start];
}
}];
});

Expand Down
Loading

0 comments on commit e024773

Please sign in to comment.