Bit2Connect SDK for Flutter

A comprehensive Flutter SDK for handling deferred deep linking and dynamic link creation. This SDK enables you to track user attribution and handle deep links even when your app is not installed.

Features

  • Deferred Deep Linking: Track users who click on your links before installing your app
  • Dynamic Link Creation: Programmatically create short links with custom parameters
  • Cross-Platform Support: Works on both iOS and Android
  • Device Fingerprinting: Uses device information for accurate attribution on iOS
  • Install Referrer: Leverages Android's Install Referrer API for attribution
  • Easy Integration: Simple API with comprehensive result handling

Installation

Add this to your package's pubspec.yaml file:

dependencies:
  bit_2_connect_sdk: ^1.0.0

Then run:

flutter pub get

Quick Start

1. Initialize the SDK

import 'package:bit_2_connect_sdk/bit_2_connect_sdk.dart';

void main() {
  // Initialize the SDK
  Bit2ConnectSDK.instance.initialize(
    baseUrl: 'https://api.bit2connect.com',
    apiKey: 'your-api-key',
    debug: true, // Enable debug logging
  );
  
  runApp(MyApp());
}

Call this method when your app starts to check for deferred deep links:

Future<void> handleDeferredDeepLink() async {
  final result = await Bit2ConnectSDK.instance.handleDeferredDeepLink();
  
  result.onSuccess((success) {
    print('Deferred link found: ${success.deepLink}');
    // Navigate to the appropriate screen
    // Handle custom data: success.customData
  });
  
  result.onError((error) {
    print('Error: $error');
  });
  
  result.onNoMatch(() {
    print('No deferred link found');
  });
}
Future<void> createDynamicLink() async {
  final result = await Bit2ConnectSDK.instance.createDynamicLink(
    deepLink: 'https://yourapp.com/campaign/123',
    androidPackage: 'com.yourapp',
    androidFallbackUrl: 'https://play.google.com/store/apps/details?id=com.yourapp',
    iosBundleId: 'com.yourapp',
    iosFallbackUrl: 'https://apps.apple.com/app/yourapp/id123456789',
    iosAppStoreId: '123456789',
    campaignParams: {
      'campaign': 'summer_sale',
      'utm_source': 'mobile_app',
    },
    customData: {
      'user_id': '12345',
      'campaign_id': '67890',
    },
  );
  
  if (result is CreateLinkSuccess) {
    print('Link created: ${result.shortUrl}');
    // Share the link
  }
}

For when the app is already installed:

void handleDirectDeepLink(String? link) {
  final result = Bit2ConnectSDK.instance.handleDirectDeepLink(link);
  
  result.onSuccess((success) {
    print('Direct link: ${success.url}');
    print('Click ID: ${success.clickId}');
    print('Parameters: ${success.parameters}');
  });
}

API Reference

Bit2ConnectSDK

Methods

initialize({required String baseUrl, required String apiKey, Duration timeout, bool debug})

Initialize the SDK with your configuration.

  • baseUrl: Your API server base URL
  • apiKey: Your API key for authentication
  • timeout: Request timeout (default: 30 seconds)
  • debug: Enable debug logging (default: false)

Check for deferred deep links on app first launch.

Returns: Future<DeferredLinkResult>

Create a new dynamic link.

Parameters:

  • deepLink (required): The deep link URL
  • androidPackage: Android package name
  • androidFallbackUrl: Fallback URL for Android
  • iosBundleId: iOS bundle identifier
  • iosFallbackUrl: Fallback URL for iOS
  • iosAppStoreId: iOS App Store ID
  • desktopFallbackUrl: Fallback URL for desktop
  • customCode: Custom short code
  • campaignParams: Campaign parameters
  • customData: Custom data to store
  • social: Social media parameters

Returns: Future<CreateLinkResult>

Parse and handle direct deep links.

Returns: DirectLinkResult

Check if a link is from your dynamic link domain.

Returns: bool

Result Classes

DeferredLinkResult

  • DeferredLinkSuccess: Contains deep link data, click ID, confidence score, and custom data
  • DeferredLinkError: Contains error message
  • DeferredLinkNoMatch: No deferred link found

CreateLinkResult

  • CreateLinkSuccess: Contains short URL, code, and QR code URL
  • CreateLinkError: Contains error message

DirectLinkResult

  • DirectLinkSuccess: Contains URL, click ID, and parameters
  • DirectLinkNoLink: No link provided

Extension Methods

The SDK provides convenient extension methods for handling results:

result.onSuccess((success) {
  // Handle success case
});

result.onError((error) {
  // Handle error case
});

result.onNoMatch(() {
  // Handle no match case
});

Platform-Specific Setup

Android

No additional setup required. The SDK uses the Install Referrer API automatically.

iOS

No additional setup required. The SDK uses device fingerprinting for attribution.

Example App

Check out our example repository for a complete Flutter app demonstrating all SDK features. The example includes:

  • Complete setup and configuration
  • Deferred deep linking implementation
  • Dynamic link creation
  • Direct link handling
  • Error handling and user feedback
  • Cross-platform support for iOS and Android

You can clone and run the example to see the SDK in action:

git clone https://github.com/bit2connect/bit2connect-flutter-example.git
cd bit2connect-flutter-example
flutter pub get
flutter run

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

For support, email support@bit2connect.com or create an issue on GitHub.

Libraries

bit_2_connect_sdk