Skip to main content

Set up standard deep linking

If a user already has your app installed and opens an Adtrace tracker URL that includes a deep_link parameter, Android can launch your app and deliver that deep link to your activity.

Setup steps

  1. Choose a unique URL scheme.
  2. Register that scheme on an activity in AndroidManifest.xml.
  3. Put the same scheme in the tracker's deep_link parameter (URL-encoded).
  4. Read the deep link from the activity Intent.
  5. For re-engagement campaigns, also call AdTrace.appWillOpenUrl().

1. Choose a unique scheme name

Pick a unique scheme for your app (for example adtraceExample). Use the same scheme in both the manifest and the tracker URL.

2. Add an intent filter in AndroidManifest.xml

Assign the scheme to the activity you want to open after the user selects the tracker URL. Add an intent-filter and set android:scheme to your scheme name:

<activity
android:name=".MainActivity"
android:configChanges="orientation|keyboardHidden"
android:label="@string/app_name"
android:screenOrientation="portrait">

<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

<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="adtraceExample" />
</intent-filter>
</activity>

Use the same scheme in the tracker URL's deep_link parameter. A tracker URL with no extra deep link path can look like this:

https://app.adtrace.io/adt1ex?deep_link=adtraceExample%3A%2F%2F

That encoded value is adtraceExample://.

Important

You must URL-encode the deep_link parameter value in the tracker URL. In your app, the value you receive is not encoded.

When the user selects the tracker URL, Android launches your app and the configured activity (for example MainActivity). The deep link is delivered in the activity Intent.

android:launchMode in AndroidManifest.xml controls whether the content arrives in onCreate, onNewIntent, or both. See Android activity launch modes for details.

onCreate

Use this when the activity is created for the deep link:

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Uri data = getIntent().getData();
// data.toString() -> deep_link parameter value
}

onNewIntent

Use this when the activity already exists and receives a new deep link Intent:

@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
setIntent(intent);

Uri data = intent.getData();
// data.toString() -> deep_link parameter value
}

Use the URI value for your app logic (for example open a specific screen).

5. Re-engagement attribution (optional)

If the deep link is part of a re-engagement campaign, call AdTrace.appWillOpenUrl() when you receive the link so Adtrace can reattribute the user. See Reattribute from deep links.