一般社団法人 全国個人事業主支援協会

COLUMN コラム

  • モバイルアプリのディープリンク設計:Universal Links・App Linksの実装

ディープリンクとは

ディープリンクとは、モバイルアプリの特定の画面やコンテンツに直接遷移するための仕組みです。従来のURLスキーム(myapp://product/123)に加え、現在ではiOSのUniversal LinksとAndroidのApp Linksが標準的な実装方式となっています。これらはHTTPSの通常のURLを使用するため、アプリがインストールされていない場合はWebサイトにフォールバックできるのが大きなメリットです。

ECサイト、SNS、メディアアプリなど、Webとアプリを横断するサービスにとって、ディープリンクはユーザー体験の要となる機能です。メールやSNSで共有したリンクからアプリの該当ページに直接遷移できれば、コンバージョン率の向上が期待できます。

iOS Universal Linksの実装

Universal Linksでは、自社ドメインとアプリの紐付けをApple App Site Association(AASA)ファイルで行います。

// https://example.com/.well-known/apple-app-site-association
{
"applinks": {
"apps": [],
"details": [
{
"appIDs": ["TEAM_ID.com.example.myapp"],
"components": [
{
"/": "/products/*",
"comment": "商品詳細ページ"
},
{
"/": "/users/*/profile",
"comment": "ユーザープロフィール"
},
{
"/": "/cart",
"comment": "カートページ"
}
]
}
]
}
}

AASAファイルはドメインの.well-knownディレクトリに配置し、Content-Typeはapplication/jsonで返す必要があります。CDN経由で配信する場合は、キャッシュ設定に注意してください。

アプリ側では、SwiftUIのonOpenURLモディファイアまたはSceneDelegateでURLを受け取り、適切な画面にルーティングします。

// SwiftUI での処理
@main
struct MyApp: App {
var body: some Scene {
WindowGroup {
ContentView()
.onOpenURL { url in
DeepLinkRouter.shared.handle(url)
}
}
}
}

class DeepLinkRouter {
static let shared = DeepLinkRouter()

func handle(_ url: URL) {
guard let components = URLComponents(url: url, resolvingAgainstBaseURL: true) else { return }
let path = components.path

if path.hasPrefix("/products/") {
let productId = path.replacingOccurrences(of: "/products/", with: "")
navigateToProduct(id: productId)
} else if path.hasSuffix("/profile") {
let userId = extractUserId(from: path)
navigateToProfile(userId: userId)
}
}
}

Android App Linksの実装

Android App Linksでは、Digital Asset Links JSONファイルをドメインに配置し、AndroidManifest.xmlでintent-filterを設定します。

<!-- AndroidManifest.xml -->
<activity android:name=".MainActivity">
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https"
android:host="example.com"
android:pathPrefix="/products" />
</intent-filter>
</activity>

android:autoVerify=”true”を設定することで、インストール時にドメインの検証が自動で行われ、リンクタップ時にアプリ選択ダイアログを表示せず直接アプリが開きます。

ディープリンク設計のベストプラクティス

URLパス設計はWebサイトとアプリで統一し、一貫性のあるユーザー体験を提供しましょう。認証が必要なページへのディープリンクでは、未ログイン時にログイン画面を経由して元のリンク先に遷移する「Deferred Deep Link」パターンの実装が重要です。また、パラメータのバリデーションを徹底し、不正なURLによるクラッシュを防止することも忘れないでください。

この記事をシェアする

  • Twitterでシェア
  • Facebookでシェア
  • LINEでシェア