Skip to content

Commit 1c8eabc

Browse files
authored
Merge pull request #49 from AppsFlyerSDK/releases/6.x.x/6.1.x/6.1.0
6.1.0
2 parents e4ae33c + c9694dc commit 1c8eabc

File tree

15 files changed

+290
-39
lines changed

15 files changed

+290
-39
lines changed

Assets/AppsFlyer/AppsFlyer.cs

Lines changed: 88 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.Collections.Generic;
23
using UnityEngine;
34

@@ -6,8 +7,11 @@ namespace AppsFlyerSDK
67
public class AppsFlyer : MonoBehaviour
78
{
89

9-
public static readonly string kAppsFlyerPluginVersion = "6.0.7";
10-
10+
public static readonly string kAppsFlyerPluginVersion = "6.1.0";
11+
public static string CallBackObjectName = null;
12+
private static EventHandler onRequestResponse;
13+
private static EventHandler onInAppResponse;
14+
1115

1216
/// <summary>
1317
/// Initialize the AppsFlyer SDK with your devKey and appID.
@@ -41,6 +45,12 @@ public static void initSDK(string devKey, string appID)
4145
/// </example>
4246
public static void initSDK(string devKey, string appID, MonoBehaviour gameObject)
4347
{
48+
49+
if(gameObject != null)
50+
{
51+
CallBackObjectName = gameObject.name;
52+
}
53+
4454
#if UNITY_IOS && !UNITY_EDITOR
4555
AppsFlyeriOS.setAppsFlyerDevKey(devKey);
4656
AppsFlyeriOS.setAppleAppID(appID);
@@ -63,9 +73,9 @@ public static void initSDK(string devKey, string appID, MonoBehaviour gameObject
6373
public static void startSDK()
6474
{
6575
#if UNITY_IOS && !UNITY_EDITOR
66-
AppsFlyeriOS.startSDK();
76+
AppsFlyeriOS.startSDK(onRequestResponse != null, CallBackObjectName);
6777
#elif UNITY_ANDROID && !UNITY_EDITOR
68-
AppsFlyerAndroid.startSDK();
78+
AppsFlyerAndroid.startSDK(onRequestResponse != null, CallBackObjectName);
6979
#else
7080

7181
#endif
@@ -80,9 +90,9 @@ public static void startSDK()
8090
public static void sendEvent(string eventName, Dictionary<string, string> eventValues)
8191
{
8292
#if UNITY_IOS && !UNITY_EDITOR
83-
AppsFlyeriOS.sendEvent(eventName, eventValues);
93+
AppsFlyeriOS.sendEvent(eventName, eventValues, onInAppResponse != null, CallBackObjectName);
8494
#elif UNITY_ANDROID && !UNITY_EDITOR
85-
AppsFlyerAndroid.sendEvent(eventName, eventValues);
95+
AppsFlyerAndroid.sendEvent(eventName, eventValues, onInAppResponse != null, CallBackObjectName);
8696
#else
8797

8898
#endif
@@ -475,6 +485,78 @@ public static void generateUserInviteLink(Dictionary<string, string> parameters,
475485

476486
#endif
477487
}
488+
489+
/// <summary>
490+
/// Start callback event.
491+
/// </summary>
492+
public static event EventHandler OnRequestResponse
493+
{
494+
add
495+
{
496+
onRequestResponse += value;
497+
}
498+
remove
499+
{
500+
onRequestResponse -= value;
501+
}
502+
}
503+
504+
/// <summary>
505+
/// In-App callback event.
506+
/// </summary>
507+
public static event EventHandler OnInAppResponse
508+
{
509+
add
510+
{
511+
onInAppResponse += value;
512+
}
513+
remove
514+
{
515+
onInAppResponse -= value;
516+
}
517+
}
518+
519+
/// <summary>
520+
/// Used to accept start callback from UnitySendMessage on native side.
521+
/// </summary>
522+
public void inAppResponseReceived(string response)
523+
{
524+
if (onInAppResponse != null)
525+
{
526+
onInAppResponse.Invoke(null, parseRequestCallback(response));
527+
}
528+
}
529+
530+
/// <summary>
531+
/// Used to accept in-app callback from UnitySendMessage on native side.
532+
/// </summary>
533+
public void requestResponseReceived(string response)
534+
{
535+
if (onRequestResponse != null)
536+
{
537+
onRequestResponse.Invoke(null, parseRequestCallback(response));
538+
}
539+
}
540+
541+
private static AppsFlyerRequestEventArgs parseRequestCallback(string response)
542+
{
543+
int responseCode = 0;
544+
string errorDescription = "";
545+
546+
try
547+
{
548+
Dictionary<string, object> dictionary = CallbackStringToDictionary(response);
549+
var errorResponse = dictionary.ContainsKey("errorDescription") ? dictionary["errorDescription"] : "";
550+
errorDescription = (string)errorResponse;
551+
responseCode = (int)(long) dictionary["statusCode"];
552+
}
553+
catch (Exception e)
554+
{
555+
AFLog("parseRequestCallback", String.Format("{0} Exception caught.", e));
556+
}
557+
558+
return new AppsFlyerRequestEventArgs(responseCode, errorDescription);
559+
}
478560

479561
/// <summary>
480562
/// Helper method to convert json strings to dictionary.

Assets/AppsFlyer/AppsFlyerAndroid.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,13 @@ public static void initSDK(string devkey, MonoBehaviour gameObject)
3232
/// <param name="devkey"> AppsFlyer's Dev-Key, which is accessible from your AppsFlyer account under 'App Settings' in the dashboard.</param>
3333
public static void startSDK()
3434
{
35+
startSDK(false, AppsFlyer.CallBackObjectName);
36+
}
37+
38+
public static void startSDK(bool shouldCallback, string callBackObjectName)
39+
{
3540
#if !UNITY_EDITOR
36-
appsFlyerAndroid.CallStatic("startTracking");
41+
appsFlyerAndroid.CallStatic("startTracking", shouldCallback, callBackObjectName);
3742
#endif
3843
}
3944

@@ -328,8 +333,13 @@ public static void recordLocation(double latitude, double longitude)
328333
/// <param name="eventValues">Event Values as Dictionary.</param>
329334
public static void sendEvent(string eventName, Dictionary<string, string> eventValues)
330335
{
336+
sendEvent(eventName, eventValues, false, AppsFlyer.CallBackObjectName);
337+
}
338+
339+
public static void sendEvent(string eventName, Dictionary<string, string> eventValues, bool shouldCallback, string callBackObjectName)
340+
{
331341
#if !UNITY_EDITOR
332-
appsFlyerAndroid.CallStatic("trackEvent", eventName, convertDictionaryToJavaMap(eventValues));
342+
appsFlyerAndroid.CallStatic("trackEvent", eventName, convertDictionaryToJavaMap(eventValues), shouldCallback, callBackObjectName);
333343
#endif
334344
}
335345

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using System;
2+
3+
namespace AppsFlyerSDK
4+
{
5+
6+
/// <summary>
7+
/// Event args for AppsFlyer requests.
8+
/// Used for sessions and in-app events.
9+
/// Used to handle post request logic.
10+
///
11+
/// Examples:
12+
/// statusCode / errorDescription
13+
///
14+
/// 200 - null
15+
///
16+
/// 10 - "Event timeout. Check 'minTimeBetweenSessions' param"
17+
/// 11 - "Skipping event because 'isStopTracking' enabled"
18+
/// 40 - Network error: Error description comes from Android
19+
/// 41 - "No dev key"
20+
/// 50 - "Status code failure" + actual response code from the server
21+
///
22+
/// </summary>
23+
public class AppsFlyerRequestEventArgs : EventArgs
24+
{
25+
public AppsFlyerRequestEventArgs(int code, string description)
26+
{
27+
statusCode = code;
28+
errorDescription = description;
29+
}
30+
31+
public int statusCode { get; }
32+
public string errorDescription { get; }
33+
}
34+
}

Assets/AppsFlyer/AppsFlyeriOS.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,14 @@ public class AppsFlyeriOS
1414
/// This will record a session and then record all background forground sessions during the lifecycle of the app.
1515
/// </summary>
1616
public static void startSDK()
17+
{
18+
startSDK(false, AppsFlyer.CallBackObjectName);
19+
}
20+
21+
public static void startSDK(bool shouldCallback, string callBackObjectName)
1722
{
1823
#if !UNITY_EDITOR
19-
_startSDK();
24+
_startSDK(shouldCallback, callBackObjectName);
2025
#endif
2126
}
2227

@@ -27,9 +32,14 @@ public static void startSDK()
2732
/// <param name="eventName">Name of event.</param>
2833
/// <param name="eventValues">Contains dictionary of values for handling by backend.</param>
2934
public static void sendEvent(string eventName, Dictionary<string, string> eventValues)
35+
{
36+
sendEvent(eventName, eventValues, false, AppsFlyer.CallBackObjectName);
37+
}
38+
39+
public static void sendEvent(string eventName, Dictionary<string, string> eventValues, bool shouldCallback, string callBackObjectName)
3040
{
3141
#if !UNITY_EDITOR
32-
_afSendEvent(eventName, AFMiniJSON.Json.Serialize(eventValues));
42+
_afSendEvent(eventName, AFMiniJSON.Json.Serialize(eventValues), shouldCallback, callBackObjectName);
3343
#endif
3444
}
3545

@@ -489,7 +499,7 @@ public static void disableSKAdNetwork(bool isDisabled)
489499
*/
490500

491501
[DllImport("__Internal")]
492-
private static extern void _startSDK();
502+
private static extern void _startSDK(bool shouldCallback, string objectName);
493503

494504
[DllImport("__Internal")]
495505
private static extern void _getConversionData(string objectName);
@@ -546,7 +556,7 @@ public static void disableSKAdNetwork(bool isDisabled)
546556
private static extern void _setPhoneNumber(string phoneNumber);
547557

548558
[DllImport("__Internal")]
549-
private static extern void _afSendEvent(string eventName, string eventValues);
559+
private static extern void _afSendEvent(string eventName, string eventValues, bool shouldCallback, string objectName);
550560

551561
[DllImport("__Internal")]
552562
private static extern void _validateAndSendInAppPurchase(string productIdentifier, string price, string currency, string tranactionId, string additionalParameters, string objectName);

Assets/AppsFlyer/Editor/AppsFlyerDependencies.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
<dependencies>
33

44
<androidPackages>
5-
<androidPackage spec="com.appsflyer:af-android-sdk:5.4.3">
5+
<androidPackage spec="com.appsflyer:af-android-sdk:6.1.0">
66
</androidPackage>
7-
<androidPackage spec="com.appsflyer:unity-wrapper:5.4.3">
7+
<androidPackage spec="com.appsflyer:unity-wrapper:6.1.1">
88
</androidPackage>
99
<androidPackage spec="com.android.installreferrer:installreferrer:2.1">
1010
</androidPackage>
1111
</androidPackages>
1212

1313
<iosPods>
14-
<iosPod name="AppsFlyerFramework" version="6.0.7" minTargetSdk="8.0">
14+
<iosPod name="AppsFlyerFramework" version="6.1.1" minTargetSdk="8.0">
1515
</iosPod>
1616
</iosPods>
1717

Assets/AppsFlyer/Plugins/iOS/AppsFlyeriOSWrapper.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ static const char* OAOA_CALLBACK = "onAppOpenAttribution";
3131
static const char* OAOA_ERROR_CALLBACK = "onAppOpenAttributionFailure";
3232
static const char* GENERATE_LINK_CALLBACK = "onInviteLinkGenerated";
3333
static const char* OPEN_STORE_LINK_CALLBACK = "onOpenStoreLinkGenerated";
34+
static const char* START_REQUEST_CALLBACK = "requestResponseReceived";
35+
static const char* IN_APP_RESPONSE_CALLBACK = "inAppResponseReceived";
3436

3537
static NSString* validateObjectName = @"";
3638
static NSString* openStoreObjectName = @"";
3739
static NSString* generateInviteObjectName = @"";
40+
static NSString* startRequestObjectName = @"";
41+
static NSString* inAppRequestObjectName = @"";
42+

Assets/AppsFlyer/Plugins/iOS/AppsFlyeriOSWrapper.mm

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,23 @@ static void unityCallBack(NSString* objectName, const char* method, const char*
1515
}
1616

1717
extern "C" {
18-
19-
const void _startSDK() {
20-
[[AppsFlyerLib shared] start];
18+
19+
const void _startSDK(bool shouldCallback, const char* objectName) {
20+
startRequestObjectName = stringFromChar(objectName);
21+
22+
[[AppsFlyerLib shared] startWithCompletionHandler:^(NSDictionary<NSString *,id> *dictionary, NSError *error) {
23+
if(shouldCallback){
24+
if (error) {
25+
NSDictionary *callbackDictionary = @{@"statusCode":[NSNumber numberWithLong:[error code]]};
26+
unityCallBack(startRequestObjectName, START_REQUEST_CALLBACK, stringFromdictionary(callbackDictionary));
27+
return;
28+
}
29+
if (dictionary) {
30+
unityCallBack(startRequestObjectName, START_REQUEST_CALLBACK, stringFromdictionary(dictionary));
31+
return;
32+
}
33+
}
34+
}];
2135
}
2236

2337
const void _setCustomerUserID (const char* customerUserID) {
@@ -84,8 +98,21 @@ const void _setOneLinkCustomDomains (int length, const char **oneLinkCustomDomai
8498
}
8599
}
86100

87-
const void _afSendEvent (const char* eventName, const char* eventValues) {
88-
[[AppsFlyerLib shared] logEvent:stringFromChar(eventName) withValues:dictionaryFromJson(eventValues)];
101+
const void _afSendEvent (const char* eventName, const char* eventValues, bool shouldCallback, const char* objectName) {
102+
inAppRequestObjectName = stringFromChar(objectName);
103+
[[AppsFlyerLib shared] logEventWithEventName:stringFromChar(eventName) eventValues:dictionaryFromJson(eventValues) completionHandler:^(NSDictionary<NSString *,id> *dictionary, NSError *error) {
104+
if(shouldCallback){
105+
if (error) {
106+
NSDictionary *callbackDictionary = @{@"statusCode":[NSNumber numberWithLong:[error code]]};
107+
unityCallBack(inAppRequestObjectName, IN_APP_RESPONSE_CALLBACK, stringFromdictionary(callbackDictionary));
108+
return;
109+
}
110+
if (dictionary) {
111+
unityCallBack(inAppRequestObjectName, IN_APP_RESPONSE_CALLBACK, stringFromdictionary(dictionary));
112+
return;
113+
}
114+
}
115+
}];
89116
}
90117

91118
const void _recordLocation (double longitude, double latitude) {

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Versions
22

3+
## v6.1.0
4+
5+
* iOS SDK Version - 6.1.1
6+
* Android SDK Version - 6.1.0
7+
* Added onRequestResponse and onInAppResponse events.
38

49
## v6.0.7
510

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222

2323
### <a id="plugin-build-for"> This plugin is built for
2424

25-
- Android AppsFlyer SDK **v5.4.3**
26-
- iOS AppsFlyer SDK **v6.0.7**
25+
- Android AppsFlyer SDK **v6.1.0**
26+
- iOS AppsFlyer SDK **v6.1.1**
2727

2828

2929

android-unity-wrapper/gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ android.enableJetifier=true
2020

2121
GROUP=com.appsflyer
2222

23-
VERSION_CODE=6
24-
VERSION_NAME=5.4.3
23+
VERSION_CODE=8
24+
VERSION_NAME=6.1.1
2525

2626
POM_ARTIFACT_ID=unity-wrapper
2727
POM_PACKAGING=aar

0 commit comments

Comments
 (0)