adjust-icon

设置直接深度链接

当已安装应用的用户点击 Adjust 链接时,直接深度链接可确保将用户直接转到应用内的特定内容。

工作原理

  1. 用户点击 Adjust 链接。
  2. 操作系统打开您的应用,并将深度链接发送至原生代码 (iOS 或 Android)。
  3. Adjust SDK 在原生代码中监听来自操作系统的深度链接,并将其转发至 directDeeplinkCallback
  4. 您的代码会将链接发送至 Adjust SDK 进行归因。SDK 还能解析短品牌化链接。
  5. 您的代码会根据已解析的链接为用户导航。

Adjust SDK 方法

在调用 Adjust.initSdk 之前,在您的 AdjustConfig 对象上设置 directDeeplinkCallback,以便在原生代码中接收 Adjust SDK 截获的深度链接。

属性声明
DirectDeeplinkCallback? directDeeplinkCallback;

使用 Adjust.processAndResolveDeeplink 方法,该方法会执行以下操作:

  • 记录深度链接点击的归因
  • 品牌化短链接解析为其等效的品牌化长链接
  • 按原样透传所有其他链接
方法签名
static Future<String?> processAndResolveDeeplink(AdjustDeeplink deeplink)

如果您使用的不是短品牌化链接,那么 Adjust.processDeeplink 方法就会记录来自深度链接点击的归因。

方法签名
static void processDeeplink(AdjustDeeplink deeplink)

processAndResolveDeeplink 方法会取代该遗留方法。

实施

在调用 Adjust.initSdk 之前,在 AdjustConfig 对象上设置 directDeeplinkCallback。每当 Adjust SDK 从操作系统收到原生代码形式的深度链接时,回传就会触发。

AdjustConfig adjustConfig = new AdjustConfig('{YourAppToken}', AdjustEnvironment.sandbox);
// Set direct deep link callback before initializing SDK
adjustConfig.directDeeplinkCallback = (String? incomingLink) async {
if (incomingLink == null) return;
// Create deep link object
final deeplink = AdjustDeeplink(incomingLink);
// Send deep link to Adjust's servers for attribution.
// If short branded link, receive long link.
// Otherwise, receive original link.
final resolvedLink = await Adjust.processAndResolveDeeplink(deeplink);
// Handle failure if resolvedLink is null
if (resolvedLink == null) return;
/*
* TODO: Handle the deep link by parsing the path
* and navigating to the appropriate screen.
*
* Possible resolvedLink formats:
*
* 1. https://brandname.go.link/?adj_t=abc123&
* adj_link=https%3A%2F%2Fexample.com%2Fsummer-clothes%3Fpromo%3Dbeach
* -> extract and decode the deep link from adj_link
*
* 2. https://brandname.go.link/summer-clothes?promo=beach&adj_t=abc123
* -> extract path from the URL
*
* 3. example://summer-clothes?promo=beach&adj_t=abc123
* -> extract path from the URL
*
* Note (Android only): If your Android app scheme path differs from iOS,
* you may receive:
* https://brandname.go.link/?adj_t=abc123&
* adj_deep_link=example%3A%2F%2Fandroid-specific-path%3Fparam%3Dvalue
* -> extract and decode the deep link from adj_deep_link
*/
};
Adjust.initSdk(adjustConfig);