支持深度链接
深度链接是引导用户访问应用程序中特定内容的 URL。当用户在已安装应用程序的设备上点击深层链接时,应用程序会直接打开到目标产品页面或体验。奇异跟踪链接支持深度链接和延迟深度链接。更多详情,请参阅我们的深度链接常见问题和奇异链接常见问题。
要求
-
完成奇异链接先决条件。
实施
更新 iOS AppDelegate
iOS 先决条件
为使 Singular SDK 能够处理启动相关数据并处理 iOS 应用程序中的深层链接,您需要在AppDelegate.m 文件中将launchOptions 和userActivity 对象传递给 Singular SDK。这些对象由 iOS 提供,包含有关应用程序启动方式和原因的重要信息,Singular 会将其用于归因跟踪和深层链接导航。
// Top of AppDelegate.m
#import "SingularAppDelegate.h"
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[GeneratedPluginRegistrant registerWithRegistry:self];
[SingularAppDelegate shared].launchOptions = launchOptions;
return [super application:application
didFinishLaunchingWithOptions:launchOptions];
}
- (BOOL)application:(UIApplication *)application
continueUserActivity:(NSUserActivity *)userActivity
restorationHandler:(void (^)(NSArray<id<UIUserActivityRestoring>>
*restorableObjects))restorationHandler {
[[SingularAppDelegate shared] continueUserActivity:userActivity
restorationHandler:restorationHandler];
return [super application:application continueUserActivity:userActivity
restorationHandler:restorationHandler ];
}
- (BOOL)application:(UIApplication *)app
openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
[[SingularAppDelegate shared] handleOpenUrl:url options:options];
return [super application:app openURL:url options: options];
}
import singular_flutter_sdk
override func application(_ application: UIApplication,
didFinishLaunchingWithOptions
launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
GeneratedPluginRegistrant.register(with: self) if
let singularAppDelegate = SingularAppDelegate.shared() {
singularAppDelegate.launchOptions = launchOptions
}
return super.application(application, didFinishLaunchingWithOptions:launchOptions)
}
override func application(_ application: UIApplication,
continue userActivity:NSUserActivity,
restorationHandler: @escaping ([UIUserActivityRestoring]?)-> Void) -> Bool {
if let singularAppDelegate = SingularAppDelegate.shared() {
singularAppDelegate.continueUserActivity(userActivity, restorationHandler:nil)
}
return super.application(application, continue:userActivity,
restorationHandler: restorationHandler);
}
override func application(_ app: UIApplication,
open url: URL, options:[UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
if let singularAppDelegate = SingularAppDelegate.shared() {
singularAppDelegate.handleOpen(url, options: options)
}
return super.application(app, open: url, options: options);
}
更新 Android MainActivity
安卓版前提条件
要让Singular SDK处理启动相关数据并在安卓应用中处理深层链接,你需要修改MainActivity 文件,将Intent 对象传递给Singular SDK。Intent 对象由安卓系统提供,其中包含关于应用程序启动方式和原因的信息,Singular 将其用于归因跟踪和深层链接导航。
// Add as part of the imports at the top of the class
import android.content.Intent;
import com.singular.flutter_sdk.SingularBridge;
// Add to the MainActivity class
@Override
public void onNewIntent(Intent intent) {
if(intent.getData() != null) {
setIntent(intent);
super.onNewIntent(intent);
SingularBridge.onNewIntent(intent);
}
}
// Add as part of the imports at the top of the class
import android.content.Intent
import com.singular.flutter_sdk.SingularBridge
// Add to the MainActivity class
override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
if (intent.data != null) {
setIntent(intent)
SingularBridge.onNewIntent(intent)
}
}
更新SingularConfig 对象
-
在 SDK 初始化过程中向 SingularConfig 对象添加singularLinksHandler回调,以处理传入的深度链接和延迟的深度链接数据。
注意:只有通过奇异链接打开应用程序时,才会触发singularLinksHandler。更多信息,请参阅《奇异链接常见问题》。
关于 singularLinksHandler 回调行为的说明:
-
在全新安装时,应用程序启动时没有打开 URL。因此,Singular 必须完成最后一个接触点的归因,并确定跟踪链接是否包含已配置的深度链接或延迟深度链接 (DDL)值。这一过程发生在 Singular SDK 向 Singular 服务器发送第一个会话时。如果适用,深度链接值将返回到 SDK 的singularLinksHandler回调中,并显示在"deeplink "参数中。
要测试这种情况
- 从设备上卸载应用程序(如果当前已安装)。
- 重置Google 广告 ID (GAID)。
- 点击设备上的Singular 跟踪链接。确保 Singular 跟踪链接配置了深度链接值。
- 安装并打开应用程序。
专业提示:在使用不同软件包名称(如com.example.dev 而不是com.example.prod )的开发版本应用程序中测试深度链接或延迟深度链接时,请确保跟踪链接是专门为开发应用程序的软件包名称而不是生产应用程序的软件包名称配置的。此外,在设备上点击测试链接后,将开发构建直接安装到测试设备上(例如,通过 Android Studio 或 APK),而不是从应用商店下载生产应用。
应成功完成归属,并将 DDL 值传递给应用程序。
- 如果跟踪链接中包含passthrough (_p) 参数,singularLinksHandler 回调的直通参数将包含相应的数据。这有助于从应用程序中的点击捕获附加数据。
- 要从跟踪链接 URL 中捕获所有查询参数,请在跟踪链接中附加_forward_params=2 参数。所有查询参数都将包含在singularLinksHandler 回调的deeplink参数中。
- 如果应用程序已安装,点击 Singular 链接将打开应用程序。Singular使用安卓应用链接技术来实现这一点。安卓操作系统将提供一个包含整个 Singular 跟踪链接的开放 URL。在 SDK 初始化过程中,Singular SDK 将解析 AndroidIntent ,提取深层链接和直通值,并通过singularLinksHandler 回调返回。