Deep Linking
Deep linking enables seamless navigation to specific in-app content, enhancing user engagement by directing users to targeted screens within your React Native application. The AppTrove React Native SDK supports two types of deep linking: Normal Deep Linking (for users with the app installed) and Deferred Deep Linking (for users who install the app via a deep link). This section outlines the setup and implementation for both Android and iOS platforms.
Prerequisites
- AppTrove React Native SDK installed and initialized in your project
- A Trackier MMP account with access to the Trackier Panel
- React Native 0.60 or later
- For Android:
- Android API 21 (Android 5.0) or later
- For iOS:
- iOS 10.0 or later
- Xcode 12.0 or later
- Basic knowledge of JavaScript, React Native, and platform-specific configurations (e.g.,
AndroidManifest.xml
, Xcode)
Overview
Deep linking redirects users to specific app content using URLs. The AppTrove SDK handles two scenarios:
- Normal Deep Linking: When the app is already installed, the deep link opens the app and navigates to the specified screen.
- Deferred Deep Linking: When the app is not installed, the deep link directs users to the app store. After installation, the SDK navigates to the specified screen upon first app launch.
Normal Deep Linking
Normal deep linking allows users with the app installed to open specific app screens directly via a deep link URL. Configuration is required for both Android and iOS.
Android Configuration
To handle deep links on Android, configure an activity in the AndroidManifest.xml
file to respond to deep link URLs.
Step 1: Update AndroidManifest.xml
- Open the
android/app/src/main/AndroidManifest.xml
file in your React Native project. - Add an activity with an intent-filter to handle deep links, specifying a unique scheme and host.
Example AndroidManifest.xml
<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 Deep Link URL
https://trackier.u9ilnk.me/product?dlv=FirstProduct&quantity=10&pid=sms
Step 2: Test the Deep Link
- Build your React Native project for Android using
npm run android
. - Install the APK on a device or emulator.
- Open the deep link URL in a browser or via an ad to verify it opens the specified activity.
iOS Configuration
For iOS, configure Universal Links to enable deep linking, allowing the app to open directly from web URLs.
Step 1: Get App Bundle ID and Prefix ID
- Log into your Apple Developer Account.
- Navigate to Certificates, IDs & Profiles > Identifiers > App IDs.
- Select your app and copy the Prefix ID and App Bundle ID.
Step 2: Add IDs in Trackier MMP
- Log in to your Trackier Panel.
- Select your application and click the Action button.
- Navigate to UniLink in the Dashboard.
- Create a template by clicking the Action button in the header.
- Edit the template and add the Prefix ID and App Bundle ID under Link Behaviour (When application is installed).
Step 3: Configure Associated Domains in Xcode
- Build your React Native project for iOS using
npm run ios
or open theios/[YourAppName].xcworkspace
file in Xcode. - In Xcode, select your project and target.
- Go to the Capabilities tab and enable Associated Domains.
- Add the unilink subdomain from the Trackier MMP app settings in the format:
applinks:subdomain.unilink.me
.
Trackier hosts the apple-app-site-association
file to support Universal Links. Ensure the unilink subdomain is correctly configured in both Trackier MMP and Xcode.
Step 4: Test Universal Links
- Build and install the app on an iOS device or simulator.
- Open a Universal Link (e.g.,
https://yourbrand.u9ilnk.me
) in Safari to verify it opens the app.
Deferred Deep Linking
Deferred deep linking directs users to the app store if the app is not installed. After installation, the SDK navigates to the specified screen upon first app launch. This requires setting a callback to handle the deep link URL.
Steps to Implement Deferred Deep Linking
- Capture Deep Link Data in Use effect, capture the deep link url and forward it to TrackierSdk.
- Configure a callback listener on the
TrackierConfig
object usingsetDeferredDeeplinkCallbackListener
. - Initialize the SDK with the configured
TrackierConfig
. - Handle the deep link URL in the callback to navigate to the desired screen.
JavaScript Example
useEffect(() => {
const getUrlAsync = async () => {
// Get the deep link used to open the app
const initialUrl = await Linking.getInitialURL();
// Sent this url to Trackier Sdk
TrackierSDK.parseDeepLink(initialUrl);
// The setTimeout is just for testing purpose
setTimeout(() => {
setUrl(initialUrl);
setProcessing(false);
}, 1000);
};
getUrlAsync();
}, []);
import React from 'react';
import { TrackierConfig, TrackierSDK } from 'react-native-trackier';
import { StyleSheet, Text, View, TouchableHighlight } from 'react-native';
export default function App() {
// Initialize SDK with Deferred Deep Linking
const trackierConfig = new TrackierConfig("abcf2270-xxxxxxx-xxxx-34903c6e1d53", TrackierConfig.EnvironmentDevelopment);
trackierConfig.setDeferredDeeplinkCallbackListener(function(uri) {
console.log("Deferred Deeplink Callback received");
console.log("URL: " + uri);
// Add logic to navigate to the specified screen based on uri
});
TrackierSDK.initialize(trackierConfig);
return (
<View style={styles.container}>
<Text>AppTrove React Native SDK</Text>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
},
});
Expected Outcome
When a user installs the app via a deep link, the setDeferredDeeplinkCallbackListener
callback receives the deep link URL, allowing you to navigate to the specified content after the app launches.
Best Practices
- Test Deep Links Thoroughly: Test both normal and deferred deep links on Android and iOS to ensure correct navigation.
- Use Unique Schemes for Android: Choose a unique
android:scheme
value inAndroidManifest.xml
to avoid conflicts with other apps. - Secure Unilink Subdomain: Verify the unilink subdomain is correctly configured in Trackier MMP and Xcode to prevent Universal Link failures.
- Handle Null URLs: Add fallback logic in the deferred deep link callback to handle cases where
uri
is null or undefined. - Log Deep Link Data: Use
console.log
to verify deep link URLs during development. - Comply with Privacy Regulations: Ensure deep link data handling complies with GDPR, CCPA, and other privacy laws.
Troubleshooting
- Deep Links Not Opening App (Android):
- Verify the
AndroidManifest.xml
intent-filter configuration matches the deep link URL structure. - Ensure
android:exported="true"
is set for the activity. - Test the deep link URL in a browser or via an ad.
- Verify the
- Universal Links Not Working (iOS):
- Confirm the
applinks:subdomain.unilink.me
entry is correct in Xcode's Associated Domains. - Check that the
apple-app-site-association
file is hosted by Trackier and accessible. - Ensure the Prefix ID and App Bundle ID are correctly set in Trackier MMP.
- Confirm the
- Deferred Deep Link Callback Not Triggered:
- Verify the
setDeferredDeeplinkCallbackListener
method is called beforeTrackierSDK.initialize
. - Test the deferred deep link by uninstalling the app, clicking the deep link, and installing via the app store.
- Check console logs for errors in the callback.
- Verify the
- General Issues:
Deep Link Resolver
The AppTrove React Native SDK provides a resolveDeeplinkUrl
method to resolve deferred deep links and get instant access to the deep link URL.
Using the Deep Link Resolver
import { TrackierSDK } from 'react-native-trackier';
// Resolve a deep link URL
TrackierSDK.resolveDeeplinkUrl("https://trackier58.u9ilnk.me/d/NKmWH9E7b1")
.then(result => {
console.log("Resolved URL:", result);
// Handle the resolved deep link
handleResolvedDeepLink(result);
})
.catch(error => {
console.error("Failed to resolve deep link:", error);
});
// Handle the resolved deep link
function handleResolvedDeepLink(resolvedUrl) {
console.log("Resolved Deep Link URL:", resolvedUrl);
// Add your navigation logic here
}
Example Implementation
import React, { useEffect } from 'react';
import { TrackierConfig, TrackierSDK } from 'react-native-trackier';
export default function App() {
useEffect(() => {
// Initialize SDK
const trackierConfig = new TrackierConfig("your-app-token", TrackierConfig.EnvironmentDevelopment);
TrackierSDK.initialize(trackierConfig);
// Example: Resolve a deep link URL
resolveExampleDeepLink();
}, []);
const resolveExampleDeepLink = () => {
const deepLinkUrl = "https://trackier58.u9ilnk.me/d/NKmWH9E7b1";
TrackierSDK.resolveDeeplinkUrl(deepLinkUrl)
.then(result => {
console.log("Successfully resolved deep link:", result);
})
.catch(error => {
console.error("Failed to resolve deep link:", error);
});
};
return (
<View style={styles.container}>
<Text>AppTrove React Native SDK</Text>
</View>
);
}
For further assistance, refer to the Trackier Documentation Portal or contact Trackier support at support@trackier.com.