Overview
This guide provides detailed instructions for implementing deep linking with the AppTrove Flutter SDK. Deep linking enhances user engagement by redirecting users to specific in-app content, supporting both normal and deferred deep linking for Android and iOS platforms.
Prerequisites
- A Flutter application with the AppTrove SDK installed and initialized
- Access to the Trackier Panel for configuring deep link URLs
- Flutter 2.0 or later, Dart 2.12 or later
- Basic knowledge of Dart, Flutter, and native platform configurations (AndroidManifest.xml, Info.plist)
Deep Linking
Deep linking allows users to navigate directly to specific content within your app using URLs (e.g., https://trackier.u9ilnk.me
). The AppTrove SDK supports two types of deep linking:
- Normal Deep Linking: Redirects users to specific app content if the app is already installed.
- Deferred Deep Linking: Redirects users to the app store for installation, then to specific content upon first app open after installation.
Normal Deep Linking
Normal deep linking opens the app directly when a user clicks a deep link, provided the app is installed. Configure your app to handle these links by updating the native platform configurations.
Android Configuration
Add an activity to handle deep links in your android/app/src/main/AndroidManifest.xml
file.
AndroidManifest.xml Example
<activity
android:name=".Activity.FirstProduct"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="trackier.u9ilnk.me"
android:pathPrefix="/product"
android:scheme="https" />
</intent-filter>
</activity>
Example URL: https://trackier.u9ilnk.me/product?dlv=FirstProduct&quantity=10&pid=sms
This configuration ensures that clicking the deep link opens the FirstProduct
activity with the specified parameters.
iOS Configuration
For iOS, configure a URL scheme or universal link in ios/Runner/Info.plist
to handle deep links.
Info.plist Example for URL Scheme
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>trackier</string>
</array>
</dict>
</array>
For universal links, host an apple-app-site-association
file on your domain (e.g., trackier.u9ilnk.me/.well-known/apple-app-site-association
) and enable the Associated Domains capability in Xcode.
Steps for Universal Links
- In Xcode, select your project and target.
- Go to the Capabilities tab.
- Enable Associated Domains.
- Add
applinks:trackier.u9ilnk.me
to the domains list.
Ensure Trackier hosts the apple-app-site-association
file for your domain to support universal links.
Deferred Deep Linking
Deferred deep linking handles cases where the app is not installed. When a user clicks a Trackier URL, they are redirected to the app store (Google Play or App Store) to install the app. After installation and first app open, the SDK processes the deep link to route the user to the specified content.
Configure the SDK to handle deferred deep links by setting a callback during initialization.
void initDeepLinkListener() {
// Listen for incoming links while the app is running
uriLinkStream.listen((Uri? uri) {
if (uri != null) {
Trackierfluttersdk.parseDeeplink(uri.toString());
}
}, onError: (err) {
// Handle error
});
}
class _MyAppState extends State<MyApp> {
String _platformVersion = 'Unknown';
void initState() {
super.initState();
initPlatformState();
}
Future<void> initPlatformState() async {
TrackerSDKConfig trackerSDKConfig = TrackerSDKConfig(
"0455721b-xxxx-xxxx-xxxx-596d818d910a", "development");
// Getting deeplink data from the below method
trackerSDKConfig.deferredDeeplinkCallback = (uri) {
print('The value of deeplinkUrl is: $uri');
};
Trackierfluttersdk.initializeSDK(trackerSDKConfig);
}
}
The deferredDeeplinkCallback
retrieves the deep link URL (e.g., https://trackier.u9ilnk.me/product?dlv=FirstProduct
) after the app is installed and opened, allowing you to route the user to the intended content.
4. Call resolveDeeplinkUrl
to Get Deferred Deep Link
Call Trackierfluttersdk.resolveDeeplinkUrl
in your activity to resolve the dynamic link and print the resulting URL to the log.
Trackierfluttersdk.resolveDeeplinkUrl("https://trackier58.u9ilnk.me/d/NKmWH9E7b1").then((resolvedUrl) {
print("Resolved: $resolvedUrl");
});
Best Practices
- Test Both Types: Validate normal and deferred deep links to ensure seamless navigation across scenarios.
- Use Unique Schemes: Choose unique URL schemes or domains to avoid conflicts with other apps.
- Initialize Early: Set the deferred deep link callback during SDK initialization to capture all deep link events.
- Handle Parameters: Parse deep link parameters (e.g.,
dlv
,quantity
) to customize in-app experiences. - Privacy Compliance: Ensure deep link data handling complies with privacy regulations (e.g., GDPR, CCPA).
Troubleshooting
- Deep Link Not Opening App:
- Verify
AndroidManifest.xml
(Android) orInfo.plist
(iOS) configurations for correct scheme and host. - Ensure the app is installed and the URL matches the configured pattern.
- Verify
- Deferred Deep Link Not Working:
- Confirm the
deferredDeeplinkCallback
is set during SDK initialization. - Test with a fresh install to simulate the app store redirect scenario.
- Confirm the
- Universal Links Failing (iOS):
- Check that the
apple-app-site-association
file is hosted correctly and accessible. - Verify the Associated Domains capability is enabled in Xcode.
- Check that the
- Parameter Issues:
- Ensure the deep link URL includes expected parameters and parse them correctly in the callback.
For further assistance, refer to the Trackier Documentation Portal or contact Trackier support at support@trackier.com.