@@ -18,6 +18,8 @@ public class AppsflyerModule
1818 private string appid { get ; }
1919 private int af_counter { get ; set ; }
2020 private string af_device_id { get ; }
21+ private string cuid { get ; set ; }
22+ private bool isStopped { get ; set ; }
2123 private MonoBehaviour mono { get ; }
2224
2325 public AppsflyerModule ( string devkey , string appid , MonoBehaviour mono , bool isSandbox = false )
@@ -26,6 +28,7 @@ public AppsflyerModule(string devkey, string appid, MonoBehaviour mono, bool isS
2628 this . devkey = devkey ;
2729 this . appid = appid ;
2830 this . mono = mono ;
31+ this . isStopped = true ;
2932
3033 this . af_counter = PlayerPrefs . GetInt ( "af_counter" ) ;
3134 // Debug.Log("af_counter: " + af_counter);
@@ -59,7 +62,9 @@ private RequestData CreateRequestData()
5962 app_version = "1.0.0" , //TODO: Insert your app version
6063 device_ids = deviceids ,
6164 request_id = GenerateGuid ( ) ,
62- limit_ad_tracking = false
65+ limit_ad_tracking = false ,
66+ customer_user_id = cuid
67+
6368 } ;
6469 return req ;
6570 }
@@ -87,6 +92,7 @@ private static string TrimDeviceOsVer(string device_os_ver)
8792 // report first open event to AppsFlyer (or session if counter > 2)
8893 public void Start ( bool skipFirst = false )
8994 {
95+ this . isStopped = false ;
9096 // generating the request data
9197 RequestData req = CreateRequestData ( ) ;
9298
@@ -100,9 +106,21 @@ public void Start(bool skipFirst = false)
100106 mono . StartCoroutine ( SendUnityPostReq ( req , REQ_TYPE ) ) ;
101107 }
102108
109+ public void Stop ( )
110+ {
111+ isStopped = true ;
112+ Debug . LogWarning ( "Appsflyer SDK has been stopped." ) ;
113+ }
114+
103115 // report inapp event to AppsFlyer
104116 public void LogEvent ( string event_name , Dictionary < string , object > event_parameters )
105117 {
118+ if ( isStopped )
119+ {
120+ Debug . LogWarning ( "Cannot send LogEvent, the Appsflyer SDK is stopped" ) ;
121+ return ;
122+ }
123+
106124 // generating the request data
107125 RequestData req = CreateRequestData ( ) ;
108126 // setting the event name and value
@@ -140,6 +158,17 @@ public string GetAppsFlyerUID()
140158 return this . af_device_id ;
141159 }
142160
161+ public void SetCustomerUserId ( string cuid )
162+ {
163+ if ( ! isStopped )
164+ {
165+ Debug . LogWarning ( "Cannot set CustomerUserID while the SDK has started." ) ;
166+ return ;
167+ }
168+ Debug . Log ( "Customer User ID has been set" ) ;
169+ this . cuid = cuid ;
170+ }
171+
143172 // send post request with Unity HTTP Client
144173 private IEnumerator SendUnityPostReq ( RequestData req , AppsflyerRequestType REQ_TYPE )
145174 {
@@ -292,6 +321,7 @@ class RequestData
292321 public DeviceIDs [ ] device_ids ;
293322 public string request_id ;
294323 public bool limit_ad_tracking ;
324+ public string customer_user_id ;
295325 public string event_name ;
296326 public Dictionary < string , object > event_parameters ;
297327}
0 commit comments