Skip to content

Commit

Permalink
Add new method set_customer_user_id.
Browse files Browse the repository at this point in the history
Add `script_api` file
  • Loading branch information
AGulev committed Sep 19, 2021
1 parent a81446c commit 1a9bcfc
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 3 deletions.
56 changes: 56 additions & 0 deletions extension-appsflyer/api/appsflyer.script_api
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
- name: appsflyer
type: table
desc: Functions and constants for interacting with mnu APIs

members:

#*****************************************************************************************************

- name: start_sdk
type: function

#*****************************************************************************************************

- name: set_callback
type: function

parameters:
- name: callback
type: function

#*****************************************************************************************************

- name: set_debug_log
type: function

parameters:
- name: is_debug
type: boolean

#*****************************************************************************************************

- name: set_customer_user_id
type: function

parameters:
- name: user_id
type: string

#*****************************************************************************************************

- name: log_event
type: function

parameters:
- name: event_name
type: string
- name: event_params
type: table

#*****************************************************************************************************

- name: CONVERSION_DATA_SUCCESS
type: number

- name: CONVERSION_DATA_FAIL
type: number
9 changes: 9 additions & 0 deletions extension-appsflyer/src/appsflyer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,21 @@ static int Lua_LogEvent(lua_State* L)
return 0;
}

static int Lua_SetCustomerUserId(lua_State* L)
{
DM_LUA_STACK_CHECK(L, 0);
const char *customerUserId = luaL_checkstring(L, 1);
SetCustomerUserId(customerUserId);
return 0;
}

static const luaL_reg Module_methods[] =
{
{"start_sdk", Lua_StartSDK},
{"set_callback", Lua_SetCallback},
{"set_debug_log", Lua_SetDebugLog},
{"log_event", Lua_LogEvent},
{"set_customer_user_id", Lua_SetCustomerUserId},
{0, 0}
};

Expand Down
17 changes: 17 additions & 0 deletions extension-appsflyer/src/appsflyer_android.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,28 @@ struct Appsflyer
jmethodID m_StartSDK;
jmethodID m_SetDebugLog;
jmethodID m_LogEvent;
jmethodID m_SetCustomerUserId;
};

static Appsflyer g_appsflyer;

static void CallVoidMethodChar(jobject instance, jmethodID method, const char* cstr)
{
ThreadAttacher attacher;
JNIEnv *env = attacher.env;

jstring jstr = env->NewStringUTF(cstr);
env->CallVoidMethod(instance, method, jstr);
env->DeleteLocalRef(jstr);
}

static void InitJNIMethods(JNIEnv* env, jclass cls)
{
g_appsflyer.m_InitializeSDK = env->GetMethodID(cls, "initializeSDK", "(Ljava/lang/String;)V");
g_appsflyer.m_StartSDK = env->GetMethodID(cls, "startSDK", "()V");
g_appsflyer.m_SetDebugLog = env->GetMethodID(cls, "setDebugLog", "(Z)V");
g_appsflyer.m_LogEvent = env->GetMethodID(cls, "logEvent", "(Ljava/lang/String;Ljava/util/Map;)V");
g_appsflyer.m_SetCustomerUserId = env->GetMethodID(cls, "setCustomerUserId", "(Ljava/lang/String;)V");
}

void Initialize_Ext()
Expand Down Expand Up @@ -101,6 +113,11 @@ void LogEvent(const char* eventName, dmArray<TrackData>* trackData)
env->DeleteLocalRef(jEventName);
}

void SetCustomerUserId(const char* userId)
{
CallVoidMethodChar(g_appsflyer.m_AppsflyerJNI, g_appsflyer.m_SetCustomerUserId, userId);
}

} // namespace

#endif // platform
1 change: 1 addition & 0 deletions extension-appsflyer/src/appsflyer_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ void InitializeSDK(const char* key, const char* appleAppID);
void StartSDK();
void SetDebugLog(bool is_debug);
void LogEvent(const char* eventName, dmArray<TrackData>* trackData);
void SetCustomerUserId(const char* userId);

} // namespace

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,9 @@ public void logEvent(String eventName, Map<String, Object> eventValue) {
Log.d(TAG, "Log event: " + eventName);
AppsFlyerLib.getInstance().logEvent(activity, eventName, eventValue);
}

public void setCustomerUserId(String userId) {
Log.d(TAG, "Set customer user id: " + userId);
AppsFlyerLib.getInstance().setCustomerUserId(userId);
}
}
6 changes: 3 additions & 3 deletions game.project
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ main_collection = /main/main.collectionc
include_dirs = extension-appsflyer

[apps_flyer]
key = UTyntqm3XiXzg6Tj2PCN4G
apple_app_id = 1255979825
key =
apple_app_id = 1480533744
is_debug = 1

[android]
package = com.agulev.test
package = com.agulev.testappsflyer
minimum_sdk_version = 21

[ios]
Expand Down
2 changes: 2 additions & 0 deletions main/main.script
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ end

function init(self)
if appsflyer then
appsflyer.set_debug_log(true)
appsflyer.set_customer_user_id("test_user_id")
appsflyer.set_callback(appsflyer_callback)
appsflyer.start_sdk()
timer.delay(5, false, function()
Expand Down

0 comments on commit 1a9bcfc

Please sign in to comment.