Skip to main content

anylink_flutter 0.0.2 copy "anylink_flutter: ^0.0.2" to clipboard
anylink_flutter: ^0.0.2 copied to clipboard

A Flutter plugin for integrating AnyLink deep-linking, deferred deep-linking, and session management.

AnyLink Flutter Plugin #

A generic, reusable Flutter plugin for integrating the AnyLink deep-linking and deferred deep-linking platform into Flutter applications.


1. Add Dependency to Host App #

Add anylink to your host application's pubspec.yaml using your repository URL:

dependencies:
  flutter:
    sdk: flutter
  anylink_flutter: ^0.0.1

Then run:

flutter pub get

2. Platform Setup #

URL Model #

Link hosts are driven by LINK_ROOT_DOMAIN (default anylink.in). Public links use a per-app subdomain or active custom domain:

  • Primary public share URL: https://{appIdentifier}.{LINK_ROOT_DOMAIN}/{slug} (e.g. https://dcart.anylink.in/AbC123)
  • Alternate public share URL: https://{appIdentifier}-alt.{LINK_ROOT_DOMAIN}/{slug}
  • Custom domain: https://{customDomain}/{slug}
  1. Ensure your domain hosts an assetlinks.json file at: https://{appIdentifier}.anylink.in/.well-known/assetlinks.json (per-app subdomain host).
  2. Configure intent filters in your Android host app's android/app/src/main/AndroidManifest.xml:
<intent-filter android:autoVerify="true">
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />

    <data
        android:scheme="https"
        android:host="dcart.anylink.in"
        android:pathPrefix="/" />
</intent-filter>

Note: Replace dcart.anylink.in with your app's subdomain or custom domain.

  1. Ensure your domain hosts an apple-app-site-association file at: https://{appIdentifier}.anylink.in/.well-known/apple-app-site-association
  2. Enable Associated Domains in Xcode under your project target capabilities:
applinks:dcart.anylink.in
  1. If your Flutter project targets iOS 13+ and uses UISceneDelegate (SceneDelegate.swift), forward continue userActivity to UIApplicationDelegate so AnyLink catches links in both cold and background states:
class SceneDelegate: FlutterSceneDelegate {
  override func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {
    super.scene(scene, continue: userActivity)
    if let appDelegate = UIApplication.shared.delegate as? FlutterAppDelegate {
      _ = appDelegate.application(UIApplication.shared, continue: userActivity, restorationHandler: { _ in })
    }
  }
}

3. How to Use in Flutter Code #

Initialize the SDK and subscribe to incoming deep links early in your application lifecycle:

Production Base URL: https://api.anylink.in (SDK default)
Host applications must provide their assigned appId and devKey.

import 'package:flutter/material.dart';
import 'package:anylink_flutter/anylink_flutter.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  // 1. Initialize AnyLink SDK with appId and devKey
  await AnyLinkSdk.initialize(
    appId: 'YOUR_APP_UUID',
    devKey: 'ak_your_dev_key',
    enableLogging: false, // Set to true to view sanitized debug logs during development
  );

  // 2. Listen to resolved deep links via Stream (or AnyLinkSdk.onDeepLink)
  // Automatically handles direct links and deferred install links on startup
  AnyLinkSdk.deepLinks.listen((AnyLinkDeepLink deepLink) {
    print('Resolved Link ID: ${deepLink.linkId}');
    print('Canonical URL: ${deepLink.url}');
    
    // Access dynamic response fields directly using [] operator:
    final id = deepLink['id'];
    final view = deepLink['view'];
    print('Dynamic response: view=$view, id=$id');

    // Or via rawData:
    // final raw = deepLink.rawData;
  });

  // Optional: Manually check or resolve deferred link if app was not installed
  // AnyLinkSdk automatically checks on initialize, but you can also call manually:
  // (Android):
  final deferredLink = await AnyLinkSdk.checkDeferredDeepLink();
  if (deferredLink != null) {
    print('Deferred link found: ${deferredLink.url}');
  }

  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('AnyLink Host App')),
        body: const Center(child: Text('AnyLink SDK Integrated')),
      ),
    );
  }
}

Deferred Deep Linking & Matching #

When a user clicks a link while the app is not installed:

  • Android: User is routed to Google Play with a deferredToken in the Play Install Referrer. The SDK automatically resolves this token on first launch via POST /v1/sdk/deferred-link.
  • iOS: User installs the app via the App Store. On first launch, the SDK automatically checks POST /v1/sdk/match with optional device hints to match the user's pre-install click signal.

The SDK also provides explicit manual APIs if needed:

// Android: Check Google Play Install Referrer or resolve token manually
AnyLinkDeepLink? deepLink = await AnyLinkSdk.checkDeferredDeepLink();
AnyLinkDeepLink? deepLinkManual = await AnyLinkSdk.resolveDeferredLink('YOUR_DEFERRED_TOKEN_UUID');

// iOS: Match pre-install click signal with optional device hints
AnyLinkDeepLink? matchedLink = await AnyLinkSdk.matchIos(
  osVersion: '17.0',
  language: 'en-US',
  timezone: 'Asia/Kolkata',
  screen: '390x844',
);

Follow these step-by-step instructions to test both Direct Deep Linking and Deferred Deep Linking.

Prerequisites #

  • An active AnyLink appId and devKey.
  • A Public Share URL configured for your app (e.g. https://dcart.anylink.in/AbC123).

Step 1: Launch your app on an Android Emulator or Device

Connect an Android device or start an emulator with your app installed.

Step 2: Test via ADB Command Line (Cold or Warm Start)

Run the following adb command in your terminal while replacing the URL with your Public Share URL:

adb shell am start -W -a android.intent.action.VIEW \
  -d "https://dcart.anylink.in/AbC123" \
  com.yourcompany.yourapp

Step 3: Verify SDK Logs & Callback

Observe your app's logs (flutter logs or debug console):

  • The native plugin intercepts https://dcart.anylink.in/AbC123.
  • The SDK sends a request to POST /v1/sdk/resolve-link with short_url.
  • The SDK emits AnyLinkDeepLink containing { linkId, url, ...parameters } to AnyLinkSdk.deepLinks.
  • An event DEEP_LINK_OPEN with linkId is sent asynchronously to /v1/sdk/events.

Step 1: Build and Run on iOS Simulator or Device

Ensure your applinks:dcart.anylink.in Associated Domain is active.

Step 2: Trigger URL via Xcode / xcrun Tool

Run the following command in your macOS terminal:

xcrun simctl openurl booted "https://dcart.anylink.in/AbC123"

Or paste https://dcart.anylink.in/AbC123 into Safari / Notes app inside the simulator and tap the link.

Step 3: Verify Callback

Confirm that your Flutter listener receives the resolved parameters and canonical URL.


C. Testing Android Deferred Deep Linking (Install Referrer) #

Deferred deep linking resolves link parameters when a user clicks a link, installs the app from Google Play, and launches it for the first time. The referrer key passed by AnyLink is deferredToken.

Step 1: Simulate Google Play Install Referrer via ADB

Before opening your freshly installed app, simulate an Install Referrer broadcast containing your deferredToken:

adb shell am broadcast -a com.android.vending.INSTALL_REFERRER \
  -n com.yourcompany.yourapp/com.anylink.anylink.AnyLinkInstallReferrer \
  --es "referrer" "deferredToken=YOUR_DEFERRED_TOKEN_UUID"

Step 2: Open the Application

Launch the app. During AnyLinkSdk.initialize(...):

  • The SDK checks Google Play Install Referrer for deferredToken.
  • It calls POST /v1/sdk/deferred-link with deferredToken.
  • The click-time snapshot { linkId, url, ...parameters } is returned and emitted to AnyLinkSdk.deepLinks.
  • An event DEFERRED_DEEP_LINK_RESOLVED is posted asynchronously with linkId and canonical url.

D. Testing iOS Pre-Install Matching #

When an iOS user clicks a public link before installation, a click signal is created on the server:

  • On first launch after install, the SDK calls POST /v1/sdk/match.
  • If matched, the click-time snapshot is returned and emitted to AnyLinkSdk.deepLinks.
  • An event DEFERRED_DEEP_LINK_RESOLVED is posted with linkId and canonical url.

5. Architecture & Key Features #

  • Production API URL: https://api.anylink.in default endpoint.
  • Subdomain Routing & Allowed Hosts: Validates incoming URLs against allowedHosts received from initialize (e.g. dcart.anylink.in, dcart-alt.anylink.in, custom domains).
  • Session Security: Session tokens are automatically refreshed and sent as Authorization: Bearer <sessionToken>.
  • Header Standard: All requests send X-AnyLink-Platform (ANDROID or IOS).
  • Strict Payload Contracts:
    • POST /v1/sdk/resolve-link: { "short_url": "..." }
    • POST /v1/sdk/deferred-link: { "deferredToken": "..." }
    • POST /v1/sdk/match: { "osVersion": "...", "language": "...", ... }
    • POST /v1/sdk/events: { "event": "DEEP_LINK_OPEN", "linkId": "..." } (no url) or { "event": "DEFERRED_DEEP_LINK_RESOLVED", "linkId": "...", "url": "..." }
  • Duplicate Protection & Intent Consumption: Consumes incoming Android intents (intent.data = null) and resets iOS userActivity.webpageURL immediately after resolving to prevent duplicate triggers or automatic navigation on phone/app restarts.
  • Debounced Emits: Stream emissions are safeguarded within a deduplication window to protect against repeated lifecycle triggers.
  • Fail-Safe & Non-Blocking: Event reporting and background network requests fail safely without interrupting app execution or host navigation.

6. Cleaning Up #

To release resources when unmounting your root app widget:

@override
void dispose() {
  AnyLinkSdk.dispose();
  super.dispose();
}
1
likes
150
points
125
downloads

Documentation

API reference

Publisher

verified publisheranylink.in

Weekly Downloads

A Flutter plugin for integrating AnyLink deep-linking, deferred deep-linking, and session management.

Homepage
Repository (GitHub)

License

MIT (license)

Dependencies

flutter, flutter_web_plugins, http, plugin_platform_interface, web

More

Packages that depend on anylink_flutter

Packages that implement anylink_flutter