Simple Deep Linking
Deep linking is a technique in which the user is directly redirected to specific pages of an application by clicking on a deeplink URL.
Normal deeplinking: Direct deep linking occurs when a user already has your app installed on their device. When this is the case, the deep link will redirect the user to the screen specified in the link.
If a user already has your app on their device, it will open when they interact with a tracker containing a deep link. You can then parse the deep link information for further use. To do this, you need to choose a desired unique scheme name.
Setting Up Deep Links
You can set up a specific activity to launch when a user interacts with a deep link. To do this:
- Assign the unique scheme name to the activity in your
AndroidManifest.xmlfile. - Add the
intent-filtersection to the activity definition. - Assign an
android:schemeproperty value with your preferred scheme name.
Example Scenario
We'll create a deep link that:
- Has the format:
https://trackier.u9ilnk.me/product?item=book - Opens
ProductActivityin the app if installed - Displays the item name (e.g., "book") in a TextView
Configuration
<activity
android:name=".ProductActivity"
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:scheme="https"
android:host="trackier.u9ilnk.me"
android:pathPrefix="/d" />
</intent-filter>
</activity>
Explanation:
android:exported="true": Allows the activity to receive external intents (required for Android 12+)<data>: Matches URLs likehttps://trackier.u9ilnk.me/d*(e.g.,/product?item=jeans)- Categories
DEFAULTandBROWSABLE: Enable the activity to handle web links
Implement the Activity and Handle the Deep Link
In ProductActivity, extract the deep link data, pass it to the AppTrove SDK for tracking, and display the item name.
- Java
- Kotlin
package com.example.myapp;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import com.trackier.sdk.TrackierSDK;
public class ProductActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_product);
// Initialize TextView
TextView itemTextView = findViewById(R.id.itemTextView);
// Get the deep link intent
Intent intent = getIntent();
Uri data = intent.getData();
if (data != null) {
// Pass the deep link to AppTrove SDK for tracking
TrackierSDK.parseDeepLink(data);
// Extract the 'item' parameter from the URL
String item = data.getQueryParameter("item");
if (item != null && !item.isEmpty()) {
itemTextView.setText("Item: " + item);
} else {
itemTextView.setText("No item specified");
}
} else {
itemTextView.setText("No deep link received");
}
}
}
package com.example.myapp
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import com.trackier.sdk.TrackierSDK
class ProductActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_product)
// Initialize TextView
val itemTextView = findViewById<TextView>(R.id.itemTextView)
// Get the deep link intent
val data: Uri? = intent.data
if (data != null) {
// Pass the deep link to AppTrove SDK for tracking
TrackierSDK.parseDeepLink(data)
// Extract the 'item' parameter from the URL
val item = data.getQueryParameter("item")
itemTextView.text = when {
!item.isNullOrEmpty() -> "Item: $item"
else -> "No item specified"
}
} else {
itemTextView.text = "No deep link received"
}
}
}
Testing Steps
-
Ensure the app is installed on your test device.
-
Open a browser or messaging app on the device.
-
Click the test URL (e.g.,
https://trackier.u9ilnk.me/d/product?item=book). -
Verify that:
- The app opens to
ProductActivity. - The TextView displays "Item: book".
- The Trackier Panel logs the deep link click (check Event Logs).
- The app opens to
-
Test edge cases:
- Invalid URL (e.g.,
https://trackier.u9ilnk.me/product): Should show "No item specified". - No app installed: Should redirect to Play Store (if configured in Trackier).
- Invalid URL (e.g.,