adjust-icon

设置直接深度链接

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

工作原理

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

Adjust SDK 方法

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

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

应用将打开 URL (遗留)

Adjust.appWillOpenUrl 方法会记录来自深度链接点击的归因,但不会解析短品牌化链接。

方法签名
static void appWillOpenUrl(String url)

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

实施

使用 app_links 库接收深度链接,并将其发送至 Adjust SDK。

pubspec.yaml
dependencies:
app_links: ^6.0.0 # check pub.dev for latest version
final _appLinks = AppLinks();
Future<void> _initDeepLinks() async {
// Handle link when app is started from a deep link
final initialLink = await _appLinks.getInitialLink();
if (initialLink != null) {
_handleDeepLink(initialLink);
}
// Handle links when app is already running
_appLinks.uriLinkStream.listen(_handleDeepLink);
}
Future<void> _handleDeepLink(Uri incomingLink) async {
// Send deep link to Adjust's servers for attribution.
// If short branded link, receive long link.
// Otherwise, receive original link.
final resolvedLink = await Adjust.processDeeplink(incomingLink.toString());
// 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
*/
}