Push notifications
Overview
The following guide covers the configuration of the Android SDK for processing incoming push notifications and sending extracted attribution data to AppsFlyer.
There are 2 methods of implementing the integration:
- By utilizing OneLink in the push payload (recommended method).
- By using plain JSON in the push payload (legacy method).
Choose the right method for you based on how the marketer structures the push notification.
Prerequisites
Before you continue, make sure you have:
- An Android app with the AppsFlyer SDK integrated.
- If implementing the recommended OneLink-based solution, you need the name of the key inside the push notification payload that contains the OneLink (provided by the app marketer).
Integrating AppsFlyer with Android push notifications using OneLink
Recommended
This is the recommended method for implementing push notification measurement in the Android SDK.
To integrate AppsFlyer with Android push notifications:
In your Application
, call addPushNotificationDeepLinkPath
before calling start
:
AppsFlyerLib.getInstance().addPushNotificationDeepLinkPath("af_push_link");
In this example, the SDK is configured to look for the af_push_link
key in the first level of the push notification payload.
When calling addPushNotificationDeepLinkPath
the SDK verifies that:
- The required key exists in the payload.
- The key contains a valid OneLink URL.
Note
addPushNotificationDeepLinkPath
accepts an array of strings too, to allow you to extract the relevant key from nested JSON structures. For more information, seeaddPushNotificationDeepLinkPath
.
Integrating AppsFlyer with Android push notifications using JSON (legacy)
This is the legacy method for implementing push notification measurement in the Android SDK.
To integrate AppsFlyer with Android push notifications using the legacy solution:
In your deep-linked activity's onCreate
, call sendPushNotificationData
:
public class MainActivity extends AppCompatActivity {
// ...
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// ...
if (getIntent().getExtras() != null) {
AppsFlyerLib.getInstance().sendPushNotificationData(this);
}
// ...
}
}
The SDK expects to get the af
key in the Intent's extras
Bundle. If an af
key is found, the SDK sends the value to AppsFlyer.
Updated 10 months ago