bit_2_connect_sdk 1.0.1
bit_2_connect_sdk: ^1.0.1 copied to clipboard
A Flutter SDK for handling deferred deep linking and dynamic link creation with cross-platform support for iOS and Android.
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());
}
2. Handle Deferred Deep Links #
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');
});
}
3. Create Dynamic Links #
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
}
}
4. Handle Direct Deep Links #
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 URLapiKey
: Your API key for authenticationtimeout
: Request timeout (default: 30 seconds)debug
: Enable debug logging (default: false)
handleDeferredDeepLink()
Check for deferred deep links on app first launch.
Returns: Future<DeferredLinkResult>
createDynamicLink({...})
Create a new dynamic link.
Parameters:
deepLink
(required): The deep link URLandroidPackage
: Android package nameandroidFallbackUrl
: Fallback URL for AndroidiosBundleId
: iOS bundle identifieriosFallbackUrl
: Fallback URL for iOSiosAppStoreId
: iOS App Store IDdesktopFallbackUrl
: Fallback URL for desktopcustomCode
: Custom short codecampaignParams
: Campaign parameterscustomData
: Custom data to storesocial
: Social media parameters
Returns: Future<CreateLinkResult>
handleDirectDeepLink(String? link)
Parse and handle direct deep links.
Returns: DirectLinkResult
isLaunchedFromDynamicLink(String? link)
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 dataDeferredLinkError
: Contains error messageDeferredLinkNoMatch
: No deferred link found
CreateLinkResult
CreateLinkSuccess
: Contains short URL, code, and QR code URLCreateLinkError
: Contains error message
DirectLinkResult
DirectLinkSuccess
: Contains URL, click ID, and parametersDirectLinkNoLink
: 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 #
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - 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.