ディープリンクのサポート
ディープリンクは、アプリ内の特定のコンテンツにユーザーを誘導するURLです。アプリがすでにインストールされているデバイスでユーザーがディープリンクをタップすると、アプリは目的の製品ページやエクスペリエンスに直接開きます。Singularトラッキングリンクは、ディープリンクとディファードディープリンクの両方をサポートしています。詳しくは、ディープリンクFAQと シンギュラーリンクFAQをご覧ください。
必要条件
-
Singular Links Prerequisitesを完了してください。
実装
iOSのAppDelegateを更新する。
iOSの前提条件
Singular SDKがiOSアプリの起動関連データを処理し、ディープリンクを扱えるようにするには、AppDelegate.m ファイルでlaunchOptions とuserActivity オブジェクトをSingular SDKに渡す必要があります。iOSが提供するこれらのオブジェクトには、アプリの起動方法と起動理由に関する重要な情報が含まれており、Singularはこれをアトリビューショントラッキングとディープリンクナビゲーションに使用します。
// Top of AppDelegate.m
#import "SingularAppDelegate.h"
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[GeneratedPluginRegistrant registerWithRegistry:self];
[SingularAppDelegate shared].launchOptions = launchOptions;
return [super application:application
didFinishLaunchingWithOptions:launchOptions];
}
- (BOOL)application:(UIApplication *)application
continueUserActivity:(NSUserActivity *)userActivity
restorationHandler:(void (^)(NSArray<id<UIUserActivityRestoring>>
*restorableObjects))restorationHandler {
[[SingularAppDelegate shared] continueUserActivity:userActivity
restorationHandler:restorationHandler];
return [super application:application continueUserActivity:userActivity
restorationHandler:restorationHandler ];
}
- (BOOL)application:(UIApplication *)app
openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
[[SingularAppDelegate shared] handleOpenUrl:url options:options];
return [super application:app openURL:url options: options];
}
import singular_flutter_sdk
override func application(_ application: UIApplication,
didFinishLaunchingWithOptions
launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
GeneratedPluginRegistrant.register(with: self) if
let singularAppDelegate = SingularAppDelegate.shared() {
singularAppDelegate.launchOptions = launchOptions
}
return super.application(application, didFinishLaunchingWithOptions:launchOptions)
}
override func application(_ application: UIApplication,
continue userActivity:NSUserActivity,
restorationHandler: @escaping ([UIUserActivityRestoring]?)-> Void) -> Bool {
if let singularAppDelegate = SingularAppDelegate.shared() {
singularAppDelegate.continueUserActivity(userActivity, restorationHandler:nil)
}
return super.application(application, continue:userActivity,
restorationHandler: restorationHandler);
}
override func application(_ app: UIApplication,
open url: URL, options:[UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
if let singularAppDelegate = SingularAppDelegate.shared() {
singularAppDelegate.handleOpen(url, options: options)
}
return super.application(app, open: url, options: options);
}
AndroidのMainActivityを更新する
Androidの前提条件
Singular SDKがAndroidアプリの起動関連データを処理し、ディープリンクを処理できるようにするには、MainActivity ファイルを修正して、Intent オブジェクトをSingular SDKに渡す必要があります。Androidシステムから提供されるIntent オブジェクトには、アプリの起動方法と起動理由に関する情報が含まれており、Singularはこれをアトリビューショントラッキングとディープリンクナビゲーションに使用します。
// Add as part of the imports at the top of the class
import android.content.Intent;
import com.singular.flutter_sdk.SingularBridge;
// Add to the MainActivity class
@Override
public void onNewIntent(Intent intent) {
if(intent.getData() != null) {
setIntent(intent);
super.onNewIntent(intent);
SingularBridge.onNewIntent(intent);
}
}
// Add as part of the imports at the top of the class
import android.content.Intent
import com.singular.flutter_sdk.SingularBridge
// Add to the MainActivity class
override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
if (intent.data != null) {
setIntent(intent)
SingularBridge.onNewIntent(intent)
}
}
SingularConfig オブジェクトを更新します。
-
SDKの初期化中にsingularLinksHandlerコールバックをSingularConfigオブジェクトに追加し、入力されるディープリンクと遅延ディープリンクデータを処理します。
注意: singularLinksHandlerは、アプリがSingularリンクを通じて開かれた場合にのみトリガーされます。詳細については、(Singular Links FAQ を参照してください) を参照してください。
singularLinksHandler コールバックの動作に関する注意事項:
-
新規インストールでは、アプリの起動時にOpen URLがありません。そのため、Singularは最後のタッチポイントへのアトリビューションを完了し、トラッキングリンクに設定されたディープリンクまたはディファードディープリンク(DDL)の値が含まれているかどうかを判断する必要があります。このプロセスは、Singular SDKが最初のセッションをSingularサーバーに送信するときに発生します。該当する場合、ディープリンク値がSDKのsingularLinksHandlerコールバックに返され、「deeplink」パラメータに表示されます。
このシナリオをテストするには
- デバイスからアプリをアンインストールします(現在インストールされている場合)。
- Google Advertising ID (GAID)をリセットします。
- 端末からSingularトラッキングリンクをクリックします。Singularトラッキングリンクにディープリンク値が設定されていることを確認します。
- アプリをインストールして開きます。
プロのヒント異なるパッケージ名(例えば、com.example.prod の代わりにcom.example.dev )を持つアプリの開発バージョンでディープリンクまたは遅延ディープリンクをテストする場合、トラッキングリンクが本番アプリのパッケージ名ではなく、開発アプリのパッケージ名専用に設定されていることを確認してください。さらに、デバイス上でテストリンクをクリックした後、アプリストアから本番アプリをダウンロードするのではなく、開発ビルドをテストデバイスに直接インストールしてください(Android StudioやAPKなど)。
アトリビュートが正常に完了し、DDL値がアプリに渡されるはずです。
- トラッキングリンクにpassthrough (_p) パラメータが含まれている場合、singularLinksHandler コールバックのパススルーパラメータには対応するデータが含まれます。これは、アプリでクリックからの追加データを取得するのに便利です。
- トラッキングリンクのURLからすべてのクエリパラメータを取得するには、_forward_params=2 パラメータをトラッキングリンクに追加します。すべてのクエリパラメータは、singularLinksHandler コールバックのdeeplinkパラメータに含まれます。
- アプリがすでにインストールされている場合、Singularリンクをクリックするとアプリが開きます。SingularはAndroid App Linksテクノロジーを使ってこれを実現します。Android OSはSingularトラッキングリンク全体を含むOpen URLを提供します。SDKの初期化中に、Singular SDKはAndroidIntent を解析し、ディープリンクと パススルーの値を抽出し、singularLinksHandler コールバックを通して返します。