アプリがインストールされているユーザーがAdjustリンクをクリックすると、ダイレクトディープリンク機能により、アプリ内の特定のコンテンツへ直接遷移させることができます。
Androidでは、ダイレクトディープリンクを受け取るための2つの方法が用意されています。各メソッド内で、次のいずれかのメソッドを使用して、ディープリンクをAdjust SDKにパスします。
設定
ディープリンクの処理と解析(推奨)
processDeeplinkメソッドを使用すると、以下の処理が実行されます。
- ディープリンククリックによるアトリビューションを記録する
- ショートブランドリンクを長いブランドリンクに解決する
- その他のリンクをそのままパスする
その後、アプリは解決済みのリンクを解析し、適切な画面へ遷移させることができます。このメソッドは、全てのディープリンク(Adjustの長いブランドリンク、他のAndroid アプリリンク、アプリスキームディープリンクなど)に使用できます。
public static void processDeeplink(Uri url, Context context, OnDeeplinkResolvedListener callback)ディープリンクの処理(レガシー版)
ショートブランドリンクを使用していない場合、appWillOpenUrlメソッドは、ディープリンククリックによるアトリビューションを記録します。
public static void appWillOpenUrl(Uri url, Context context)processDeeplinkメソッドは、このレガシーメソッドに優先します。
実装
メインアクティビティに以下のコードを追加して、ディープリンクを処理します。
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 /*13 * Send deep link to Adjust's servers for attribution.14 * If short branded link, receive long link.15 * Otherwise, receive original link.16 */17 Adjust.processDeeplink(incomingLink, this) { resolvedLink ->18 if (resolvedLink == null) return@processDeeplink19 /*20 * Possible resolvedLink formats:21 *22 * 1. https://brandname.go.link/?adj_t=def456&23 * adj_link=https%3A%2F%2Fexample.com%2Fsummer-clothes%3Fpromo%3Dbeach24 * -> extract and decode the deep link from adj_link25 *26 * 2. https://brandname.go.link/summer-clothes?promo=beach&adj_t=def45627 * -> extract path from the URL28 *29 * 3. https://brandname.go.link/?adj_t=def456&30 * adj_deep_link=example%3A%2F%2Fsummer-clothes%3Fpromo%3Dbeach31 * -> extract and decode the deep link from adj_deep_link32 * (used when Android app scheme path differs from iOS)33 *34 * 4. example://summer-clothes?promo=beach&adj_t=def45635 * -> extract path from the URL36 *37 * TODO: Handle the deep link and navigate to the appropriate screen.38 */39 }40 // Optional: prevent handling the same deep link multiple times41 intent.data = null42 }43
44 // Receive deep link in an existing Activity instance.45 override fun onNewIntent(intent: Intent) {46 super.onNewIntent(intent)47 setIntent(intent)48
49 // Get deep link from intent50 val incomingLink = intent?.data51 Log.d("IncomingLink", "onNewIntent: url=$incomingLink")52
53 if (incomingLink == null) return54
55 /*56 * Send deep link to Adjust's servers for attribution.57 * If short branded link, receive long link.58 * Otherwise, receive original link.59 */60 Adjust.processDeeplink(incomingLink, this) { resolvedLink ->61 if (resolvedLink == null) return@processDeeplink62 /*63 * Possible resolvedLink formats:64 *65 * 1. https://brandname.go.link/?adj_t=def456&66 * adj_link=https%3A%2F%2Fexample.com%2Fsummer-clothes%3Fpromo%3Dbeach67 * -> extract and decode the deep link from adj_link68 *69 * 2. https://brandname.go.link/summer-clothes?promo=beach&adj_t=def45670 * -> extract path from the URL71 *72 * 3. https://brandname.go.link/?adj_t=def456&73 * adj_deep_link=example%3A%2F%2Fsummer-clothes%3Fpromo%3Dbeach74 * -> extract and decode the deep link from adj_deep_link75 * (used when Android app scheme path differs from iOS)76 *77 * 4. example://summer-clothes?promo=beach&adj_t=def45678 * -> extract path from the URL79 *80 * TODO: Handle the deep link and navigate to the appropriate screen.81 */82 }83 // Optional: prevent handling the same deep link multiple times84 intent.data = null85 }86
87}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 /*17 * Send deep link to Adjust's servers for attribution.18 * If short branded link, receive long link.19 * Otherwise, receive original link.20 */21 Adjust.processDeeplink(incomingLink, this, new OnDeeplinkResolvedListener() {22 @Override23 public void onDeeplinkResolved(String resolvedLink) {24 if (resolvedLink == null) {25 return;26 }27 /*28 * Possible resolvedLink formats:29 *30 * 1. https://brandname.go.link/?adj_t=def456&31 * adj_link=https%3A%2F%2Fexample.com%2Fsummer-clothes%3Fpromo%3Dbeach32 * -> extract and decode the deep link from adj_link33 *34 * 2. https://brandname.go.link/summer-clothes?promo=beach&adj_t=def45635 * -> extract path from the URL36 *37 * 3. https://brandname.go.link/?adj_t=def456&38 * adj_deep_link=example%3A%2F%2Fsummer-clothes%3Fpromo%3Dbeach39 * -> extract and decode the deep link from adj_deep_link40 * (used when Android app scheme path differs from iOS)41 *42 * 4. example://summer-clothes?promo=beach&adj_t=def45643 * -> extract path from the URL44 *45 * TODO: Handle the deep link and navigate to the appropriate screen.46 */47 }48 });49 // Optional: prevent handling the same deep link multiple times50 appIntent.setData(null);51 }52 }53
54 // Receive deep link in an existing Activity instance.55 @Override56 protected void onNewIntent(Intent intent) {57 super.onNewIntent(intent);58 setIntent(intent); // Update the current intent with the new one59
60 Uri incomingLink = null;61 if (intent != null) {62 incomingLink = intent.getData();63 }64 Log.d("IncomingLink", "onNewIntent: url=" + incomingLink);65
66 if (incomingLink != null) {67 /*68 * Send deep link to Adjust's servers for attribution.69 * If short branded link, receive long link.70 * Otherwise, receive original link.71 */72 Adjust.processDeeplink(incomingLink, this, new OnDeeplinkResolvedListener() {73 @Override74 public void onDeeplinkResolved(String resolvedLink) {75 if (resolvedLink == null) {76 return;77 }78 /*79 * Possible resolvedLink formats:80 *81 * 1. https://brandname.go.link/?adj_t=def456&82 * adj_link=https%3A%2F%2Fexample.com%2Fsummer-clothes%3Fpromo%3Dbeach83 * -> extract and decode the deep link from adj_link84 *85 * 2. https://brandname.go.link/summer-clothes?promo=beach&adj_t=def45686 * -> extract path from the URL87 *88 * 3. https://brandname.go.link/?adj_t=def456&89 * adj_deep_link=example%3A%2F%2Fsummer-clothes%3Fpromo%3Dbeach90 * -> extract and decode the deep link from adj_deep_link91 * (used when Android app scheme path differs from iOS)92 *93 * 4. example://summer-clothes?promo=beach&adj_t=def45694 * -> extract path from the URL95 *96 * TODO: Handle the deep link and navigate to the appropriate screen.97 */98 }99 });100 // Optional: prevent handling the same deep link multiple times101 intent.setData(null);102 }103 }104}専用ディープリンクアクティビティ
専用ディープリンクアクティビティ アプローチを使用している場合は、以下のようなファイルも作成する必要があります。
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_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP)20 }21 startActivity(mainActivityIntent)22 finish()23 }24
25}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_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);22
23 startActivity(mainActivityIntent);24 finish();25 }26}