Skip to content

Commit

Permalink
Merge pull request #285 from adjust/v4370
Browse files Browse the repository at this point in the history
Version 4.37.0
  • Loading branch information
uerceg authored Jan 16, 2024
2 parents cbb6e64 + 6212727 commit 9336643
Show file tree
Hide file tree
Showing 19 changed files with 196 additions and 11 deletions.
29 changes: 28 additions & 1 deletion Assets/Adjust/Android/AdjustAndroid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace com.adjust.sdk
#if UNITY_ANDROID
public class AdjustAndroid
{
private const string sdkPrefix = "unity4.36.0";
private const string sdkPrefix = "unity4.37.0";
private static bool launchDeferredDeeplink = true;
private static AndroidJavaClass ajcAdjust = new AndroidJavaClass("com.adjust.sdk.Adjust");
private static AndroidJavaObject ajoCurrentActivity = new AndroidJavaClass("com.unity3d.player.UnityPlayer").GetStatic<AndroidJavaObject>("currentActivity");
Expand All @@ -19,6 +19,7 @@ public class AdjustAndroid
private static SessionTrackingFailedListener onSessionTrackingFailedListener;
private static SessionTrackingSucceededListener onSessionTrackingSucceededListener;
private static VerificationInfoListener onVerificationInfoListener;
private static DeeplinkResolutionListener onDeeplinkResolvedListener;

public static void Start(AdjustConfig adjustConfig)
{
Expand Down Expand Up @@ -684,6 +685,14 @@ public static void VerifyPlayStorePurchase(AdjustPlayStorePurchase purchase, Act
ajcAdjust.CallStatic("verifyPurchase", ajoPurchase, onVerificationInfoListener);
}

public static void ProcessDeeplink(string url, Action<string> resolvedLinkCallback)
{
onDeeplinkResolvedListener = new DeeplinkResolutionListener(resolvedLinkCallback);
AndroidJavaClass ajcUri = new AndroidJavaClass("android.net.Uri");
AndroidJavaObject ajoUri = ajcUri.CallStatic<AndroidJavaObject>("parse", url);
ajcAdjust.CallStatic("processDeeplink", ajoUri, ajoCurrentActivity, onDeeplinkResolvedListener);
}

// Used for testing only.
public static void SetTestOptions(Dictionary<string, string> testOptions)
{
Expand Down Expand Up @@ -1024,6 +1033,24 @@ public void onVerificationFinished(AndroidJavaObject verificationInfo)
}
}

private class DeeplinkResolutionListener : AndroidJavaProxy
{
private Action<string> callback;

public DeeplinkResolutionListener(Action<string> pCallback) : base("com.adjust.sdk.OnDeeplinkResolvedListener")
{
this.callback = pCallback;
}

public void onDeeplinkResolved(string resolvedLink)
{
if (callback != null)
{
callback(resolvedLink);
}
}
}

// Private & helper methods.
private static bool IsAppSecretSet(AdjustConfig adjustConfig)
{
Expand Down
Binary file modified Assets/Adjust/Android/Test/adjust-test-library.aar
Binary file not shown.
Binary file modified Assets/Adjust/Android/adjust-android.jar
Binary file not shown.
14 changes: 14 additions & 0 deletions Assets/Adjust/Test/CommandExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public void ExecuteCommand(Command command)
case "trackAdRevenueV2": TrackAdRevenueV2(); break;
case "getLastDeeplink": GetLastDeeplink(); break;
case "verifyPurchase": VerifyPurchase(); break;
case "processDeeplink": ProcessDeeplink(); break;
default: CommandNotFound(_command.ClassName, _command.MethodName); break;
}
}
Expand Down Expand Up @@ -1010,6 +1011,12 @@ private void VerifyPurchase()
#endif
}

private void ProcessDeeplink()
{
var deeplink = _command.GetFirstParameterValue("deeplink");
Adjust.processDeeplink(deeplink, DeeplinkResolvedCallback);
}

// helper methods

private void VerificationInfoCallback(AdjustPurchaseVerificationInfo verificationInfo)
Expand All @@ -1021,6 +1028,13 @@ private void VerificationInfoCallback(AdjustPurchaseVerificationInfo verificatio
_testLibrary.SendInfoToServer(localExtraPath);
}

private void DeeplinkResolvedCallback(string resolvedLink)
{
string localExtraPath = ExtraPath;
_testLibrary.AddInfoToSend("resolved_link", resolvedLink);
_testLibrary.SendInfoToServer(localExtraPath);
}

private void CommandNotFound(string className, string methodName)
{
TestApp.Log("Adjust Test: Method '" + methodName + "' not found for class '" + className + "'");
Expand Down
39 changes: 39 additions & 0 deletions Assets/Adjust/Unity/Adjust.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public class Adjust : MonoBehaviour
private static Action<string> skadUpdateConversionValueDelegate = null;
private static Action<string> skad4UpdateConversionValueDelegate = null;
private static Action<AdjustPurchaseVerificationInfo> verificationInfoDelegate = null;
private static Action<string> deeplinkResolutionDelegate = null;
#endif

void Awake()
Expand Down Expand Up @@ -959,6 +960,28 @@ public static void verifyPlayStorePurchase(
#endif
}

public static void processDeeplink(
string url,
Action<string> resolvedLinkDelegate,
string sceneName = "Adjust")
{
if (IsEditor())
{
return;
}

#if UNITY_IOS
Adjust.deeplinkResolutionDelegate = resolvedLinkDelegate;
AdjustiOS.ProcessDeeplink(url, sceneName);
#elif UNITY_ANDROID
AdjustAndroid.ProcessDeeplink(url, resolvedLinkDelegate);
#elif (UNITY_WSA || UNITY_WP8)
Debug.Log("[Adjust]: Deep link processing is only supported for Android and iOS platform.");
#else
Debug.Log(errorMsgPlatform);
#endif
}

#if UNITY_IOS
public void GetNativeAttribution(string attributionData)
{
Expand Down Expand Up @@ -1178,6 +1201,22 @@ public void GetNativeVerificationInfo(string verificationInfoData)
var verificationInfo = new AdjustPurchaseVerificationInfo(verificationInfoData);
Adjust.verificationInfoDelegate(verificationInfo);
}

public void GetNativeResolvedLink(string resolvedLink)
{
if (IsEditor())
{
return;
}

if (Adjust.deeplinkResolutionDelegate == null)
{
Debug.Log("[Adjust]: Deep link reoslution delegate was not set.");
return;
}

Adjust.deeplinkResolutionDelegate(resolvedLink);
}
#endif

private static bool IsEditor()
Expand Down
2 changes: 1 addition & 1 deletion Assets/Adjust/Unity/AdjustConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class AdjustConfig
internal bool? playStoreKidsAppEnabled;
internal bool? allowSuppressLogLevel;
internal bool? needsCost;
internal bool? readDeviceInfoOnceEnabled;
internal bool launchDeferredDeeplink;
internal AdjustLogLevel? logLevel;
internal AdjustEnvironment environment;
Expand All @@ -62,7 +63,6 @@ public class AdjustConfig
internal string preinstallFilePath;
internal bool? finalAndroidAttributionEnabled;
internal string fbAppId;
internal bool? readDeviceInfoOnceEnabled;
// iOS specific members
internal bool? allowAdServicesInfoReading;
internal bool? allowIdfaReading;
Expand Down
6 changes: 6 additions & 0 deletions Assets/Adjust/Unity/AdjustEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class AdjustEvent
internal List<string> callbackList;
// iOS specific members
internal string receipt;
internal string receiptBase64;
internal bool isReceiptSet;
// Android specific members
internal string purchaseToken;
Expand Down Expand Up @@ -81,6 +82,11 @@ public void setReceipt(string receipt)
this.receipt = receipt;
}

public void setReceiptBase64(string receiptBase64)
{
this.receiptBase64 = receiptBase64;
}

// Android specific methods
public void setPurchaseToken(string purchaseToken)
{
Expand Down
2 changes: 1 addition & 1 deletion Assets/Adjust/Windows/AdjustWindows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace com.adjust.sdk
{
public class AdjustWindows
{
private const string sdkPrefix = "unity4.36.0";
private const string sdkPrefix = "unity4.37.0";
private static bool appLaunched = false;

public static void Start(AdjustConfig adjustConfig)
Expand Down
5 changes: 5 additions & 0 deletions Assets/Adjust/iOS/ADJConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,4 +291,9 @@
*/
@property (nonatomic, assign) BOOL coppaCompliantEnabled;

/**
* @brief Enables caching of device ids to read it only once
*/
@property (nonatomic, assign) BOOL readDeviceInfoOnceEnabled;

@end
16 changes: 15 additions & 1 deletion Assets/Adjust/iOS/Adjust.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Adjust.h
// Adjust SDK
//
// V4.36.0
// V4.37.0
// Created by Christian Wellenbrock (@wellle) on 23rd July 2013.
// Copyright (c) 2012-2021 Adjust GmbH. All rights reserved.
//
Expand All @@ -17,6 +17,8 @@
#import "ADJPurchase.h"
#import "ADJPurchaseVerificationResult.h"

typedef void(^AdjustResolvedDeeplinkBlock)(NSString * _Nonnull resolvedLink);

@interface AdjustTestOptions : NSObject

@property (nonatomic, copy, nullable) NSString *baseUrl;
Expand Down Expand Up @@ -137,6 +139,15 @@ extern NSString * __nonnull const ADJDataResidencyUS;
*/
+ (void)appWillOpenUrl:(nonnull NSURL *)url;

/**
* @brief Process the deep link that has opened an app and potentially get a resolved link.
*
* @param deeplink URL object which contains info about adjust deep link.
* @param completionHandler Completion handler where either resolved or echoed deep link will be sent.
*/
+ (void)processDeeplink:(nonnull NSURL *)deeplink
completionHandler:(void (^_Nonnull)(NSString * _Nonnull resolvedLink))completionHandler;

/**
* @brief Set the device token used by push notifications.
*
Expand Down Expand Up @@ -407,6 +418,9 @@ extern NSString * __nonnull const ADJDataResidencyUS;

- (void)appWillOpenUrl:(nonnull NSURL *)url;

- (void)processDeeplink:(nonnull NSURL *)deeplink
completionHandler:(void (^_Nonnull)(NSString * _Nonnull resolvedLink))completionHandler;

- (void)setOfflineMode:(BOOL)enabled;

- (void)setDeviceToken:(nonnull NSData *)deviceToken;
Expand Down
Binary file modified Assets/Adjust/iOS/AdjustSdk.a
Binary file not shown.
42 changes: 42 additions & 0 deletions Assets/Adjust/iOS/AdjustUnity.mm
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ void _AdjustLaunchApp(const char* appToken,
int linkMeEnabled,
int needsCost,
int coppaCompliant,
int readDeviceInfoOnce,
int64_t secretId,
int64_t info1,
int64_t info2,
Expand Down Expand Up @@ -222,6 +223,11 @@ void _AdjustLaunchApp(const char* appToken,
[adjustConfig setCoppaCompliantEnabled:(BOOL)coppaCompliant];
}

// Read device info just once.
if (readDeviceInfoOnce != -1) {
[adjustConfig setReadDeviceInfoOnceEnabled:(BOOL)readDeviceInfoOnce];
}

// User agent.
if (stringUserAgent != nil) {
[adjustConfig setUserAgent:stringUserAgent];
Expand Down Expand Up @@ -270,6 +276,7 @@ void _AdjustTrackEvent(const char* eventToken,
double revenue,
const char* currency,
const char* receipt,
const char* receiptBase64,
const char* productId,
const char* transactionId,
const char* callbackId,
Expand Down Expand Up @@ -324,6 +331,14 @@ void _AdjustTrackEvent(const char* eventToken,
[event setReceipt:[stringReceipt dataUsingEncoding:NSUTF8StringEncoding]];
}

// Base64 encoded receipt.
if (receiptBase64 != NULL) {
// If both (receipt and receiptBase64) set, receiptBase64 will be used.
NSString *stringReceiptBase64 = [NSString stringWithUTF8String:receiptBase64];
NSData *decodedData = [[NSData alloc] initWithBase64EncodedString:stringReceiptBase64 options:0];
[event setReceipt:decodedData];
}

// Callback ID.
if (callbackId != NULL) {
NSString *stringCallbackId = [NSString stringWithUTF8String:callbackId];
Expand Down Expand Up @@ -881,6 +896,33 @@ void _AdjustVerifyAppStorePurchase(const char* transactionId,
}];
}

void _AdjustProcessDeeplink(const char* url, const char* sceneName) {
NSString *strSceneName = isStringValid(sceneName) == true ? [NSString stringWithUTF8String:sceneName] : nil;
if (url != NULL) {
NSString *stringUrl = [NSString stringWithUTF8String:url];
NSURL *nsUrl;
if ([NSString instancesRespondToSelector:@selector(stringByAddingPercentEncodingWithAllowedCharacters:)]) {
nsUrl = [NSURL URLWithString:[stringUrl stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLFragmentAllowedCharacterSet]]];
} else {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
nsUrl = [NSURL URLWithString:[stringUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
}
#pragma clang diagnostic pop

[Adjust processDeeplink:nsUrl completionHandler:^(NSString * _Nonnull resolvedLink) {
if (strSceneName == nil) {
return;
}
if (resolvedLink == nil) {
return;
}
const char* resolvedLinkCString = [resolvedLink UTF8String];
UnitySendMessage([strSceneName UTF8String], "GetNativeResolvedLink", resolvedLinkCString);
}];
}
}

void _AdjustSetTestOptions(const char* baseUrl,
const char* gdprUrl,
const char* subscriptionUrl,
Expand Down
Loading

0 comments on commit 9336643

Please sign in to comment.