adjust-icon

Send push tokens

Push notifications enable you to deliver personalized content to your users. You can use deep links to direct users to specific pages in your app, and measure reattributions.

How it works

Each device generates a unique push token that's used to target it. The push token is sent to Adjust when the following information is passed to the MobileCore.trackAction API:

  1. AdjustAdobeExtension.ADOBE_ADJUST_ACTION_SET_PUSH_TOKEN: a string constant that maps to the setPushToken method.
  2. contextData: a HashMap of values used to configure your push token.

When you call MobileCore.trackAction with these arguments, the Adjust extension the token to the setPushToken method and sends the information to Adjust.

Reference

The contextData HashMap holds information about an action. To configure your push token, add the following key-value pair to your HashMap.

AdjustAdobeExtension.ADOBE_ADJUST_PUSH_TOKEN

The device's push token.

Example: Send a push token

To send a push token to Adjust, you need to add a function to your main activity. In this tutorial, you'll build on MainActivity.java from the integration guide and add a new function called sendPushTokenToAdjust which will send an updated push token to Adjust. The final result looks like this:

MainActivity.java
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import androidx.appcompat.app.AppCompatActivity;
import com.adjust.sdk.Adjust;
import com.adjust.sdk.AdjustDeeplink;
import com.adobe.marketing.mobile.MobileCore;
import java.util.HashMap;
import java.util.Map;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent intent = getIntent();
Uri data = intent.getData();
AdjustDeeplink adjustDeeplink = new AdjustDeeplink(data);
Adjust.processDeeplink(adjustDeeplink, getApplicationContext());
}
public void sendPushTokenToAdjust(View view) {
String action = AdjustAdobeExtension.ADOBE_ADJUST_ACTION_TRACK_EVENT;
Map<String, String> contextData = new HashMap<String, String>();
contextData.put(AdjustAdobeExtension.ADOBE_ADJUST_PUSH_TOKEN, "de18dbf8-f38a-4962-8f1e-44abcf43055d");
MobileCore.trackAction(action, contextData);
}
}

Here's what you need to do:

  1. First, import the following classes:

    • com.adobe.marketing.mobile.MobileCore: this class is used to send information to Adobe and Adjust.
    • java.util.HashMap: this class is used to generate the contextData HashMap.
    • java.util.Map: this class is used to type the contextData HashMap.
    MainActivity.java
    import android.content.Intent;
    import android.net.Uri;
    import android.os.Bundle;
    import android.view.View;
    import androidx.appcompat.app.AppCompatActivity;
    import com.adjust.sdk.Adjust;
    import com.adjust.sdk.AdjustDeeplink;
    import com.adobe.marketing.mobile.MobileCore;
    import java.util.HashMap;
    import java.util.Map;
  2. Next, create a new function inside the MainActivity class called sendPushTokenToAdjust. This function takes a View as an argument and returns void.

    MainActivity.java
    public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Intent intent = getIntent();
    Uri data = intent.getData();
    AdjustDeeplink adjustDeeplink = new AdjustDeeplink(data);
    Adjust.processDeeplink(adjustDeeplink, getApplicationContext());
    }
    public void sendPushTokenToAdjust(View view) {}
    }
  3. Inside the sendPushTokenToAdjust function, declare a new String variable called action and assign it the value AdjustAdobeExtension.ADOBE_ADJUST_ACTION_SET_PUSH_TOKEN. This is used to tell MobileCore.trackAction which action to handle.

    MainActivity.java
    public void sendPushTokenToAdjust(View view) {
    String action = AdjustAdobeExtension.ADOBE_ADJUST_ACTION_SET_PUSH_TOKEN;
    }
  4. Create a new HashMap variable called contextData. This is used to hold the properties of the action.

    MainActivity.java
    public void sendPushTokenToAdjust(View view) {
    String action = AdjustAdobeExtension.ADOBE_ADJUST_ACTION_SET_PUSH_TOKEN;
    Map<String, String> contextData = new HashMap<String, String>();
    }
  5. Add your push token to the HashMap using the AdjustAdobeExtension.ADOBE_ADJUST_PUSH_TOKEN key. This example sets the push token to "de18dbf8-f38a-4962-8f1e-44abcf43055d".

    MainActivity.java
    public void sendPushTokenToAdjust(View view) {
    String action = AdjustAdobeExtension.ADOBE_ADJUST_ACTION_TRACK_EVENT;
    Map<String, String> contextData = new HashMap<String, String>();
    contextData.put(AdjustAdobeExtension.ADOBE_ADJUST_PUSH_TOKEN, "de18dbf8-f38a-4962-8f1e-44abcf43055d");
    }
  6. Finally, call MobileCore.trackAction with your action and contextData variables to send the push token to Adjust.

    MainActivity.java
    public void sendPushTokenToAdjust(View view) {
    String action = AdjustAdobeExtension.ADOBE_ADJUST_ACTION_TRACK_EVENT;
    Map<String, String> contextData = new HashMap<String, String>();
    contextData.put(AdjustAdobeExtension.ADOBE_ADJUST_PUSH_TOKEN, "de18dbf8-f38a-4962-8f1e-44abcf43055d");
    MobileCore.trackAction(action, contextData);
    }

That's it! When the user performs an action that maps to the sendPushTokenToAdjust function, your push token is sent to Adjust.