Skip to content

Commit e210515

Browse files
authored
Merge pull request #1 from AppsFlyerSDK/cuid-stop
added SetCustomerUserID() & Stop()
2 parents ce3b550 + ccf2720 commit e210515

5 files changed

Lines changed: 177 additions & 5 deletions

File tree

Assets/AppsflyerModule.cs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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
}

Assets/AppsflyerScript.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@ public class AppsflyerScript : MonoBehaviour
88
{
99
public string DEV_KEY;
1010
public string APP_ID;
11+
public bool IS_SANDBOX;
1112

1213
void Start()
1314
{
14-
AppsflyerModule afm = new AppsflyerModule(DEV_KEY, APP_ID, this);
15+
AppsflyerModule afm = new AppsflyerModule(DEV_KEY, APP_ID, this, IS_SANDBOX);
16+
afm.SetCustomerUserId("testTEST12345");
1517
afm.Start();
18+
afm.SetCustomerUserId("testTESTNOPE");
19+
afm.Stop();
1620

1721
// set event name
1822
string event_name = "af_purchase";

Assets/Scenes/SampleScene.unity

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,9 @@ MonoBehaviour:
152152
m_Script: {fileID: 11500000, guid: baec666e5d68e6e449e5490b387c3be7, type: 3}
153153
m_Name:
154154
m_EditorClassIdentifier:
155-
devkey:
156-
appid:
155+
DEV_KEY:
156+
APP_ID:
157+
IS_SANDBOX: 0
157158
--- !u!4 &425522096
158159
Transform:
159160
m_ObjectHideFlags: 0

ProjectSettings/ProjectSettings.asset

Lines changed: 93 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,99 @@ PlayerSettings:
270270
AndroidValidateAppBundleSize: 1
271271
AndroidAppBundleSizeToValidate: 150
272272
m_BuildTargetIcons: []
273-
m_BuildTargetPlatformIcons: []
273+
m_BuildTargetPlatformIcons:
274+
- m_BuildTarget: Android
275+
m_Icons:
276+
- m_Textures: []
277+
m_Width: 432
278+
m_Height: 432
279+
m_Kind: 2
280+
m_SubKind:
281+
- m_Textures: []
282+
m_Width: 324
283+
m_Height: 324
284+
m_Kind: 2
285+
m_SubKind:
286+
- m_Textures: []
287+
m_Width: 216
288+
m_Height: 216
289+
m_Kind: 2
290+
m_SubKind:
291+
- m_Textures: []
292+
m_Width: 162
293+
m_Height: 162
294+
m_Kind: 2
295+
m_SubKind:
296+
- m_Textures: []
297+
m_Width: 108
298+
m_Height: 108
299+
m_Kind: 2
300+
m_SubKind:
301+
- m_Textures: []
302+
m_Width: 81
303+
m_Height: 81
304+
m_Kind: 2
305+
m_SubKind:
306+
- m_Textures: []
307+
m_Width: 192
308+
m_Height: 192
309+
m_Kind: 1
310+
m_SubKind:
311+
- m_Textures: []
312+
m_Width: 144
313+
m_Height: 144
314+
m_Kind: 1
315+
m_SubKind:
316+
- m_Textures: []
317+
m_Width: 96
318+
m_Height: 96
319+
m_Kind: 1
320+
m_SubKind:
321+
- m_Textures: []
322+
m_Width: 72
323+
m_Height: 72
324+
m_Kind: 1
325+
m_SubKind:
326+
- m_Textures: []
327+
m_Width: 48
328+
m_Height: 48
329+
m_Kind: 1
330+
m_SubKind:
331+
- m_Textures: []
332+
m_Width: 36
333+
m_Height: 36
334+
m_Kind: 1
335+
m_SubKind:
336+
- m_Textures: []
337+
m_Width: 192
338+
m_Height: 192
339+
m_Kind: 0
340+
m_SubKind:
341+
- m_Textures: []
342+
m_Width: 144
343+
m_Height: 144
344+
m_Kind: 0
345+
m_SubKind:
346+
- m_Textures: []
347+
m_Width: 96
348+
m_Height: 96
349+
m_Kind: 0
350+
m_SubKind:
351+
- m_Textures: []
352+
m_Width: 72
353+
m_Height: 72
354+
m_Kind: 0
355+
m_SubKind:
356+
- m_Textures: []
357+
m_Width: 48
358+
m_Height: 48
359+
m_Kind: 0
360+
m_SubKind:
361+
- m_Textures: []
362+
m_Width: 36
363+
m_Height: 36
364+
m_Kind: 0
365+
m_SubKind:
274366
m_BuildTargetBatching: []
275367
m_BuildTargetShaderSettings: []
276368
m_BuildTargetGraphicsJobs:

README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ AppsflyerModule afm = new AppsflyerModule(<< DEV_KEY >>, << APP_ID >>, this, tru
4747

4848
- `DEV_KEY`: Get from the marketer or [AppsFlyer HQ](https://support.appsflyer.com/hc/en-us/articles/211719806-App-settings-#general-app-settings).
4949
- `APP_ID`: The app id on Appsflyer HQ
50+
- `MonoBehaviour mono`:
51+
- `bool isSandbox`: Whether to activate sandbox mode. False by default.
5052

5153
### Start
5254

@@ -69,6 +71,28 @@ bool skipFirst = [SOME_CONDITION];
6971
afm.Start(skipFirst);
7072
```
7173

74+
75+
### Stop
76+
77+
Once this method is invoked, our SDK no longer communicates with our servers and stops functioning.
78+
Useful when implementing user opt-in/opt-out.
79+
80+
**Method signature**
81+
82+
```c#
83+
void Stop()
84+
```
85+
86+
**Usage**:
87+
88+
```c#
89+
// Starting the SDK
90+
afm.Start();
91+
// ...
92+
// Stopping the SDK, preventing further communication with AppsFlyer
93+
afm.Stop();
94+
```
95+
7296
### LogEvent
7397

7498
This method receives an event name and JSON object and sends an in-app event to AppsFlyer.
@@ -121,6 +145,27 @@ bool IsInstallOlderThanDate = afm.IsInstallOlderThanDate("2023-02-11T10:00:00+00
121145
afm.Start(!IsInstallOlderThanDate);
122146
```
123147

148+
149+
### SetCustomerUserId
150+
151+
Setting your own customer ID enables you to cross-reference your own unique ID with AppsFlyer’s unique ID and other devices’ IDs.
152+
This ID is available in raw-data reports and in the Postback APIs for cross-referencing with your internal IDs.
153+
Can be used only before calling `Start()`.
154+
155+
**Method signature**
156+
157+
```c#
158+
void SetCustomerUserId(string cuid)
159+
```
160+
161+
**Usage**:
162+
163+
```c#
164+
AppsflyerSteamModule afm = new AppsflyerSteamModule(DEV_KEY, STEAM_APP_ID, this);
165+
afm.SetCustomerUserId("15667737-366d-4994-ac8b-653fe6b2be4a");
166+
afm.Start();
167+
```
168+
124169
### GetAppsFlyerUID
125170

126171
Get AppsFlyer's unique device ID. The SDK generates an AppsFlyer unique device ID upon app installation. When the SDK is started, this ID is recorded as the ID of the first app install.

0 commit comments

Comments
 (0)