Skip to main content

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.

You can set up a specific activity to launch when a user interacts with a deep link. To do this:

  1. Assign the unique scheme name to the activity in your AndroidManifest.xml file.
  2. Add the intent-filter section to the activity definition.
  3. Assign an android:scheme property 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 ProductActivity in the app if installed
  • Displays the item name (e.g., "book") in a TextView

Configuration

AndroidManifest.xml
<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 like https://trackier.u9ilnk.me/d* (e.g., /product?item=jeans)
  • Categories DEFAULT and BROWSABLE: Enable the activity to handle web links

In ProductActivity, extract the deep link data, pass it to the AppTrove SDK for tracking, and display the item name.

ProductActivity.java
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");
}
}
}

Testing Steps

  1. Ensure the app is installed on your test device.

  2. Open a browser or messaging app on the device.

  3. Click the test URL (e.g., https://trackier.u9ilnk.me/d/product?item=book).

  4. Verify that:

    • The app opens to ProductActivity.
    • The TextView displays "Item: book".
    • The Trackier Panel logs the deep link click (check Event Logs).
  5. 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).