After you’ve created deep links, you’ll need to enable them in your measurement SDK to use them in your App campaigns.
This article explains how to enable deferred deep linking (DDL) in supported third-party App Attribution Partners (AAPs) or in the latest Google Analytics for Firebase (GA4F) SDK. Learn how to track Mobile app conversion tracking with third-party tools.
Before you begin
To enable DDL in a supported AAP, you must have working deep links that are properly included in their attached feed or submitted as an ad group DDL.
Instructions
How to activate DDL in supported AAPs
Third-party AAPs currently supported by Google for DDL are as follows:
- Adjust
- AppsFlyer
- Branch
- Kochava
- Singular
Follow the steps below to enable DDL in your chosen AAP.
Adjust
AppsFlyer
- In AppsFlyer, click Configuration > Integrated Partners, then select Google Ads (Adwords).
- Under the Integration tab, enable 'Deferred deep linking with Google feeds'.
- Click Save integration.
Branch
Kochava
Singular
Learn more About tracking app conversions with an App Attribution Partner.
How to activate DDL in the GA4F SDK
You can activate DDL in the GA4F SDK using Android version 17.2.0+ or a newer version by following these steps:
Steps to activate DDL in the GA4F SDK
1. Configure your app to use Google Analytics for Firebase
In the app build.gradle, remove all dependencies on firebase-core
. Then, add or update the dependency on firebase-analytics
version 17.2.0+. The example below uses a newer version of the SDK.
dependencies {
...
implementation 'com.google.firebase:firebase-analytics:21.0.0'
...
}
2. Enable the feature in your app
Modify your application manifest by adding the following metadata tag to your application tag.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myawesome.app">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name=".MainActivity">
<!-- Value to be added to enable deferred deep links -->
<meta-data android:name="google_analytics_deferred_deep_link_enabled" android:value="true"/>
<activity
android:name=".MainActivity" >
</activity>
</application>
</manifest>
When enabled, GA4F will fetch the configured deep link, on app start, for the corresponding campaign you configured.
3. Capture the deep link
Set up a SharedPreferences change listener within your main launch activity class. This will be triggered when a DDL is available. If you’re registering the listener later in the app lifecycle, the deep link might have already been retrieved. In that case, the listener won’t be triggered, and you can immediately look up the value of the deep link by reading SharedPreferences.
GA4F stores the deep link in a SharedPreferences file google.analytics.deferred.deeplink.prefs
with the key deeplink
. GA4F also stores, in the same SharedPreferences file, the ad click timestamp with the key timestamp
. Note that the format of the timestamp is microseconds (milliseconds followed by a dot and microseconds) and is stored in SharedPreferences using a Long when the type is Double. Use Double.longBitsToDouble(...) to parse the actual value.
Example:
/**
* The main launch activity of the app.
*/
public class MainActivity extends AppCompatActivity {
private SharedPreferences preferences;
private SharedPreferences.OnSharedPreferenceChangeListener deepLinkListener;
@Override
protected void onStart() {
super.onStart();
preferences.registerOnSharedPreferenceChangeListener(deepLinkListener);
}
@Override
protected void onStop() {
super.onStop();
preferences.unregisterOnSharedPreferenceChangeListener(deepLinkListener);
deepLinkListener = null;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
preferences =
getSharedPreferences('google.analytics.deferred.deeplink.prefs', MODE_PRIVATE);
deepLinkListener = (sharedPreferences, key) -> {
Log.d("DEEPLINK_LISTENER", "Deep link changed");
if ("deeplink".equals(key)) {
String deeplink = sharedPreferences.getString(key, null);
Double cTime = Double.longBitsToDouble(sharedPreferences.getLong("timestamp", 0));
Log.d('DEEPLINK_LISTENER', 'Deep link retrieved: ' + deeplink);
showDeepLinkResult(deeplink);
}
};
}
public void showDeepLinkResult(String result) {
String toastText = result;
if (toastText == null) {
toastText = 'The deep link retrieval failed';
} else if (toastText.isEmpty()) {
toastText = 'Deep link empty';
}
Toast.makeText(MainActivity.this, toastText, Toast.LENGTH_LONG).show();
Log.d("DEEPLINK", toastText);
}
}
4. Prepare data for diagnostic testing
To validate your implementation, get the AdID for the device you wish to test with. You can use the following command to set the DDL that the app will receive.
'googleadservices.com/pagead/conversion/app/deeplink?&rdid=<<your device adid>>&id_type=adid&bundleid=<<your application package>>&deeplink=<<deeplink you want to receive>>&ddl_test=1'
To check if the deep link was set correctly, you can use this request to verify the response.
This test deep link expires after 24 hours. Repeat this step if the test deep link expires.
5. Enable test mode for fetching the test DDL
Enable the DDL test mode to start testing on your devices.
adb shell setprop debug.deferred.deeplink <<your application package>>
Next, enable debug mode on your device. Begin using your app and, in Logcat, check that the log message shows a gmp_version
of at least 18200
. Searching for the keyword deferred
will filter all debug messages from Google Analytics for Firebase relating to that functionality.
Example:
D/FA: Deferred Deep Link feature enabled.
FA-SVC: Uploading data. app, uncompressed size, data: <<your application package>>,
…
gmp_version: 18200