アプリがインストールされているユーザーがAdjustリンクをクリックすると、ダイレクトディープリンク機能により、アプリ内の特定のコンテンツへ直接遷移させることができます。
Androidでは、ダイレクトディープリンクを受け取るための2つの方法が用意されています。各メソッド内で、次のいずれかのメソッドを使用して、ディープリンクをAdjust SDKにパスします。
設定
ディープリンクの処理と解析(推奨)
processAndResolveDeeplinkメソッドを使用すると、以下の処理が実行されます。
- ディープリンククリックによるアトリビューションを記録する
- ショートブランドリンクを長いブランドリンクに解決する
- その他のリンクをそのままパスする
その後、アプリは解決済みのリンクを解析し、適切な画面へ遷移させることができます。このメソッドは、全てのディープリンク(Adjustの長いブランドリンク、他のAndroid アプリリンク、アプリスキームディープリンクなど)に使用できます。
public static void processAndResolveDeeplink(AdjustDeeplink adjustDeeplink, Context context, OnDeeplinkResolvedListener callback)ディープリンクの処理(レガシー版)
ショートブランドリンクを使用していない場合、processDeeplinkメソッドは、ディープリンククリックによるアトリビューションを記録します。
public static void processDeeplink(AdjustDeeplink adjustDeeplink, Context context)processAndResolveDeeplinkメソッドは、このレガシーメソッドに優先します。
実装
メインアクティビティに以下のコードを追加して、ディープリンクを処理します。
1class MainActivity : AppCompatActivity() {2 // Receive deep link when the Activity launches.3 override fun onCreate(savedInstanceState: Bundle?) {4 super.onCreate(savedInstanceState)5
6 // Get deep link from intent7 val incomingLink = intent?.data8 Log.d("IncomingLink", "onCreate: url=$incomingLink")9
10 if (incomingLink == null) return11
12 // Create deep link object13 val deeplink = AdjustDeeplink(incomingLink)14
15 /*16 * Send deep link to Adjust's servers for attribution.17 * If short branded link, receive long link.18 * Otherwise, receive original link.19 */20 Adjust.processAndResolveDeeplink(deeplink, this) { resolvedLink ->21 if (resolvedLink == null) return@processAndResolveDeeplink22 /*23 * TODO: Handle the deep link and navigate to the appropriate screen.24 *25 * Possible resolvedLink formats:26 *27 * 1. https://brandname.go.link/?adj_t=def456&28 * adj_link=https%3A%2F%2Fexample.com%2Fsummer-clothes%3Fpromo%3Dbeach29 * -> extract and decode the deep link from adj_link30 *31 * 2. https://brandname.go.link/summer-clothes?promo=beach&adj_t=def45632 * -> extract path from the URL33 *34 * 3. https://brandname.go.link/?adj_t=def456&35 * adj_deep_link=example%3A%2F%2Fsummer-clothes%3Fpromo%3Dbeach36 * -> extract and decode the deep link from adj_deep_link37 * (used when Android app scheme path differs from iOS)38 *39 * 4. example://summer-clothes?promo=beach&adj_t=def45640 * -> extract path from the URL41 */42 }43 // Optional: prevent handling the same deep link multiple times44 intent.data = null45 }46
47 // Receive deep link in an existing Activity instance.48 override fun onNewIntent(intent: Intent) {49 super.onNewIntent(intent)50 setIntent(intent)51
52 // Get deep link from intent53 val incomingLink = intent?.data54 Log.d("IncomingLink", "onNewIntent: url=$incomingLink")55
56 if (incomingLink == null) return57
58 // Create deep link object59 val deeplink = AdjustDeeplink(incomingLink)60
61 /*62 * Send deep link to Adjust's servers for attribution.63 * If short branded link, receive long link.64 * Otherwise, receive original link.65 */66 Adjust.processAndResolveDeeplink(deeplink, this) { resolvedLink ->67 if (resolvedLink == null) return@processAndResolveDeeplink68 /*69 * TODO: Handle the deep link and navigate to the appropriate screen.70 *71 * Possible resolvedLink formats:72 *73 * 1. https://brandname.go.link/?adj_t=def456&74 * adj_link=https%3A%2F%2Fexample.com%2Fsummer-clothes%3Fpromo%3Dbeach75 * -> extract and decode the deep link from adj_link76 *77 * 2. https://brandname.go.link/summer-clothes?promo=beach&adj_t=def45678 * -> extract path from the URL79 *80 * 3. https://brandname.go.link/?adj_t=def456&81 * adj_deep_link=example%3A%2F%2Fsummer-clothes%3Fpromo%3Dbeach82 * -> extract and decode the deep link from adj_deep_link83 * (used when Android app scheme path differs from iOS)84 *85 * 4. example://summer-clothes?promo=beach&adj_t=def45686 * -> extract path from the URL87 */88 }89 // Optional: prevent handling the same deep link multiple times90 intent.data = null91 }92}1public class MainActivity extends AppCompatActivity {2 // Receive deep link when the Activity launches.3 @Override4 protected void onCreate(Bundle savedInstanceState) {5 super.onCreate(savedInstanceState);6
7 // Get deep link from intent8 Intent appIntent = getIntent();9 Uri incomingLink = null;10 if (appIntent != null) {11 incomingLink = appIntent.getData();12 }13 Log.d("IncomingLink", "onCreate: url=" + incomingLink);14
15 if (incomingLink != null) {16 // Create deep link object17 AdjustDeeplink deeplink = new AdjustDeeplink(incomingLink);18
19 /*20 * Send deep link to Adjust's servers for attribution.21 * If short branded link, receive long link.22 * Otherwise, receive original link.23 */24 Adjust.processAndResolveDeeplink(deeplink, this, new OnDeeplinkResolvedListener() {25 @Override26 public void onDeeplinkResolved(String resolvedLink) {27 if (resolvedLink == null) {28 return;29 }30 /*31 * TODO: Handle the deep link and navigate to the appropriate screen.32 *33 * Possible resolvedLink formats:34 *35 * 1. https://brandname.go.link/?adj_t=def456&36 * adj_link=https%3A%2F%2Fexample.com%2Fsummer-clothes%3Fpromo%3Dbeach37 * -> extract and decode the deep link from adj_link38 *39 * 2. https://brandname.go.link/summer-clothes?promo=beach&adj_t=def45640 * -> extract path from the URL41 *42 * 3. https://brandname.go.link/?adj_t=def456&43 * adj_deep_link=example%3A%2F%2Fsummer-clothes%3Fpromo%3Dbeach44 * -> extract and decode the deep link from adj_deep_link45 * (used when Android app scheme path differs from iOS)46 *47 * 4. example://summer-clothes?promo=beach&adj_t=def45648 * -> extract path from the URL49 */50 }51 });52 // Optional: prevent handling the same deep link multiple times53 appIntent.setData(null);54 }55 }56
57 // Receive deep link in an existing Activity instance.58 @Override59 protected void onNewIntent(Intent intent) {60 super.onNewIntent(intent);61 setIntent(intent); // Update the current intent with the new one62
63 Uri incomingLink = null;64 if (intent != null) {65 incomingLink = intent.getData();66 }67 Log.d("IncomingLink", "onNewIntent: url=" + incomingLink);68
69 if (incomingLink != null) {70 // Create deep link object71 AdjustDeeplink deeplink = new AdjustDeeplink(incomingLink);72
73 /*74 * Send deep link to Adjust's servers for attribution.75 * If short branded link, receive long link.76 * Otherwise, receive original link.77 */78 Adjust.processAndResolveDeeplink(deeplink, this, new OnDeeplinkResolvedListener() {79 @Override80 public void onDeeplinkResolved(String resolvedLink) {81 if (resolvedLink == null) {82 return;83 }84 /*85 * TODO: Handle the deep link and navigate to the appropriate screen.86 *87 * Possible resolvedLink formats:88 *89 * 1. https://brandname.go.link/?adj_t=def456&90 * adj_link=https%3A%2F%2Fexample.com%2Fsummer-clothes%3Fpromo%3Dbeach91 * -> extract and decode the deep link from adj_link92 *93 * 2. https://brandname.go.link/summer-clothes?promo=beach&adj_t=def45694 * -> extract path from the URL95 *96 * 3. https://brandname.go.link/?adj_t=def456&97 * adj_deep_link=example%3A%2F%2Fsummer-clothes%3Fpromo%3Dbeach98 * -> extract and decode the deep link from adj_deep_link99 * (used when Android app scheme path differs from iOS)100 *101 * 4. example://summer-clothes?promo=beach&adj_t=def456102 * -> extract path from the URL103 */104 }105 });106 // Optional: prevent handling the same deep link multiple times107 intent.setData(null);108 }109 }110}専用ディープリンクアクティビティ
専用ディープリンクアクティビティ アプローチを使用している場合は、以下のようなファイルも作成する必要があります。
1class DedicatedDeepLinkActivity : AppCompatActivity() {2 override fun onCreate(savedInstanceState: Bundle?) {3 super.onCreate(savedInstanceState)4 handleIntent(intent)5 }6
7 override fun onNewIntent(intent: Intent) {8 super.onNewIntent(intent)9 handleIntent(intent)10 }11
12 private fun handleIntent(intent: Intent) {13 Log.d("IncomingLink", "DedicatedDeepLinkActivity: url=${intent.data}")14
15 // Create intent to forward to MainActivity16 val mainActivityIntent = Intent(this, MainActivity::class.java).apply {17 data = intent.data18 putExtras(intent)19 addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP)20 }21 startActivity(mainActivityIntent)22 finish()23 }24}1public class DedicatedDeepLinkActivity extends AppCompatActivity {2 @Override3 protected void onCreate(Bundle savedInstanceState) {4 super.onCreate(savedInstanceState);5 handleIntent(getIntent());6 }7
8 @Override9 protected void onNewIntent(Intent intent) {10 super.onNewIntent(intent);11 handleIntent(intent);12 }13
14 private void handleIntent(Intent intent) {15 Log.d("IncomingLink", "DedicatedDeepLinkActivity: url=" + intent.getData());16
17 // Create intent to forward to MainActivity18 Intent mainActivityIntent = new Intent(this, MainActivity.class);19 mainActivityIntent.setData(intent.getData());20 mainActivityIntent.putExtras(intent);21 mainActivityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);22
23 startActivity(mainActivityIntent);24 finish();25 }26}