Skip to content

Commit de2db94

Browse files
committed
feat: add ability to resolve deep links
1 parent 1858c72 commit de2db94

File tree

4 files changed

+101
-0
lines changed

4 files changed

+101
-0
lines changed

Assets/Adjust/Android/AdjustAndroid.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public class AdjustAndroid
1919
private static SessionTrackingFailedListener onSessionTrackingFailedListener;
2020
private static SessionTrackingSucceededListener onSessionTrackingSucceededListener;
2121
private static VerificationInfoListener onVerificationInfoListener;
22+
private static DeeplinkResolutionListener onDeeplinkResolvedListener;
2223

2324
public static void Start(AdjustConfig adjustConfig)
2425
{
@@ -684,6 +685,14 @@ public static void VerifyPlayStorePurchase(AdjustPlayStorePurchase purchase, Act
684685
ajcAdjust.CallStatic("verifyPurchase", ajoPurchase, onVerificationInfoListener);
685686
}
686687

688+
public static void ProcessDeeplink(string url, Action<string> resolvedLinkCallback)
689+
{
690+
onDeeplinkResolvedListener = new DeeplinkResolutionListener(resolvedLinkCallback);
691+
AndroidJavaClass ajcUri = new AndroidJavaClass("android.net.Uri");
692+
AndroidJavaObject ajoUri = ajcUri.CallStatic<AndroidJavaObject>("parse", url);
693+
ajcAdjust.CallStatic("processDeeplink", ajoUri, ajoCurrentActivity, onDeeplinkResolvedListener);
694+
}
695+
687696
// Used for testing only.
688697
public static void SetTestOptions(Dictionary<string, string> testOptions)
689698
{
@@ -1024,6 +1033,24 @@ public void onVerificationFinished(AndroidJavaObject verificationInfo)
10241033
}
10251034
}
10261035

1036+
private class DeeplinkResolutionListener : AndroidJavaProxy
1037+
{
1038+
private Action<string> callback;
1039+
1040+
public DeeplinkResolutionListener(Action<string> pCallback) : base("com.adjust.sdk.OnDeeplinkResolvedListener")
1041+
{
1042+
this.callback = pCallback;
1043+
}
1044+
1045+
public void onDeeplinkResolved(string resolvedLink)
1046+
{
1047+
if (callback != null)
1048+
{
1049+
callback(resolvedLink);
1050+
}
1051+
}
1052+
}
1053+
10271054
// Private & helper methods.
10281055
private static bool IsAppSecretSet(AdjustConfig adjustConfig)
10291056
{

Assets/Adjust/Unity/Adjust.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ public class Adjust : MonoBehaviour
8686
private static Action<string> skadUpdateConversionValueDelegate = null;
8787
private static Action<string> skad4UpdateConversionValueDelegate = null;
8888
private static Action<AdjustPurchaseVerificationInfo> verificationInfoDelegate = null;
89+
private static Action<string> deeplinkResolutionDelegate = null;
8990
#endif
9091

9192
void Awake()
@@ -959,6 +960,28 @@ public static void verifyPlayStorePurchase(
959960
#endif
960961
}
961962

963+
public static void processDeeplink(
964+
string url,
965+
Action<string> resolvedLinkDelegate,
966+
string sceneName = "Adjust")
967+
{
968+
if (IsEditor())
969+
{
970+
return;
971+
}
972+
973+
#if UNITY_IOS
974+
Adjust.deeplinkResolutionDelegate = resolvedLinkDelegate;
975+
AdjustiOS.ProcessDeeplink(url, sceneName);
976+
#elif UNITY_ANDROID
977+
AdjustAndroid.ProcessDeeplink(url, resolvedLinkDelegate);
978+
#elif (UNITY_WSA || UNITY_WP8)
979+
Debug.Log("[Adjust]: Deep link processing is only supported for Android and iOS platform.");
980+
#else
981+
Debug.Log(errorMsgPlatform);
982+
#endif
983+
}
984+
962985
#if UNITY_IOS
963986
public void GetNativeAttribution(string attributionData)
964987
{
@@ -1178,6 +1201,22 @@ public void GetNativeVerificationInfo(string verificationInfoData)
11781201
var verificationInfo = new AdjustPurchaseVerificationInfo(verificationInfoData);
11791202
Adjust.verificationInfoDelegate(verificationInfo);
11801203
}
1204+
1205+
public void GetNativeResolvedLink(string resolvedLink)
1206+
{
1207+
if (IsEditor())
1208+
{
1209+
return;
1210+
}
1211+
1212+
if (Adjust.deeplinkResolutionDelegate == null)
1213+
{
1214+
Debug.Log("[Adjust]: Deep link reoslution delegate was not set.");
1215+
return;
1216+
}
1217+
1218+
Adjust.deeplinkResolutionDelegate(resolvedLink);
1219+
}
11811220
#endif
11821221

11831222
private static bool IsEditor()

Assets/Adjust/iOS/AdjustUnity.mm

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,33 @@ void _AdjustVerifyAppStorePurchase(const char* transactionId,
896896
}];
897897
}
898898

899+
void _AdjustProcessDeeplink(const char* url, const char* sceneName) {
900+
NSString *strSceneName = isStringValid(sceneName) == true ? [NSString stringWithUTF8String:sceneName] : nil;
901+
if (url != NULL) {
902+
NSString *stringUrl = [NSString stringWithUTF8String:url];
903+
NSURL *nsUrl;
904+
if ([NSString instancesRespondToSelector:@selector(stringByAddingPercentEncodingWithAllowedCharacters:)]) {
905+
nsUrl = [NSURL URLWithString:[stringUrl stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLFragmentAllowedCharacterSet]]];
906+
} else {
907+
#pragma clang diagnostic push
908+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
909+
nsUrl = [NSURL URLWithString:[stringUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
910+
}
911+
#pragma clang diagnostic pop
912+
913+
[Adjust processDeeplink:nsUrl completionHandler:^(NSString * _Nonnull resolvedLink) {
914+
if (strSceneName == nil) {
915+
return;
916+
}
917+
if (resolvedLink == nil) {
918+
return;
919+
}
920+
const char* resolvedLinkCString = [resolvedLink UTF8String];
921+
UnitySendMessage([strSceneName UTF8String], "GetNativeResolvedLink", resolvedLinkCString);
922+
}];
923+
}
924+
}
925+
899926
void _AdjustSetTestOptions(const char* baseUrl,
900927
const char* gdprUrl,
901928
const char* subscriptionUrl,

Assets/Adjust/iOS/AdjustiOS.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,9 @@ private static extern void _AdjustVerifyAppStorePurchase(
203203
string receipt,
204204
string sceneName);
205205

206+
[DllImport("__Internal")]
207+
private static extern void _AdjustProcessDeeplink(string url, string sceneName);
208+
206209
public AdjustiOS() {}
207210

208211
public static void Start(AdjustConfig adjustConfig)
@@ -542,6 +545,11 @@ public static void VerifyAppStorePurchase(AdjustAppStorePurchase purchase, strin
542545
cSceneName);
543546
}
544547

548+
public static void ProcessDeeplink(string url, string sceneName)
549+
{
550+
_AdjustProcessDeeplink(url, sceneName);
551+
}
552+
545553
// Used for testing only.
546554
public static void SetTestOptions(Dictionary<string, string> testOptions)
547555
{

0 commit comments

Comments
 (0)