Current Unity SDK Version: v4.18.0
Compatible with Android SDK v4.8.18 and iOS SDK v4.8.10
1. 概要
AppsFlyerのSDKは、Android、iOS、Windows Phone、その他多くのモバイル開発プラットフォーム向けにモバイルアプリのインストールやイベントトラッキング機能を提供します。
インストール、アップデート、セッションを計測できます。また、追加でインストール後イベント(アプリ内購入、ゲームレベル等)を計測し、ROIとユーザーエンゲージメントレベルも評価できます。
Unityプラットフォームで開発されるモバイルアプリは、AppsFlyerのSDKと連携し、AndroidとiOSの両方で生成されるアプリを計測することができます。以下のガイドでは、iOSとAndroidのアプリに関して、AppsFlyerのSDKをUnityのコードと連携させる方法について詳しく説明します。
注
AppsFlyerは、Unityバージョン5以上との連携をサポートしています。
重要!
Google Play Install Referrer APIは、Unityプラグインv.4.16.0からサポートが開始されました。新しいReferrer APIを使用するには、プラグインをバージョン4.16.0以降に更新してください。
ヒント
- Chapters 2 and 3 are MANDATORY to implement BASIC SDK integration, i.e. install attribution only
- Tracking in-app events chapter is HIGHLY RECOMMENDED to implement
- The rest of the described features are OPTIONAL to implement, although some of them may be necessary for you, depending on your app's business logic. For example, tracking revenue or getting the conversion data on first launch may be vital for your app's flow
2. クイックスタート
2.1 AppsFlyerのUnityプラグインのダウンロード
プラグインはGithubのこちらをご覧ください:https://github.com/AppsFlyerSDK/Unity
以下はAppsFlyerのUnityプラグイン使用に関する連携手順の説明です。
2.2 プラグインのインストール
以下はAppsFlyerのプラグインに関する連携手順の説明です。
- AppsFlyerUnityPlugin.unitypackageをUnityプロジェクトにインポートします。
- 「アセット(Assets)」>>「パッケージのインポート(Import Package)」>>「カスタムパッケージ(Custom Package)」に移動します。
- ファイル「AppsFlyerUnityPlugin.unitypackage」を選択します。
2.3 AndroidとiOSの必須セットアップ
Androidのセットアップ
AFレシーバーとパーミッションのAndroidManifest.xmlへの設定
<!-- receiver should be inside the <application> tag -->
<receiver android:name="com.appsflyer.MultipleInstallBroadcastReceiver" android:exported="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
<!-- Mandatory permission: -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
必須パーミッションの設定
AndroidManifest.xmlには、次のパーミッションが含まれます。
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<!-- Optional : -->
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
AndroidManifest.xmlのBroadcastReceiverの設定
インストールリファラーブロードキャストレシーバーの実装には、次の2つのオプションがあります。
AndroidManifest.xmlのINSTALL_REFERRER
をリッスンするレシーバーがない場合、次のレシーバーをapplicationタグ内に追加します。
<receiver android:name="com.appsflyer.SingleInstallBroadcastReceiver" android:exported="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
<receiver android:name="com.appsflyer.MultipleInstallBroadcastReceiver" android:exported="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
iOSのセットアップ
Linked Frameworks and Libraries
xCode向けにUnityでプロジェクトを構築後、フレームワークを以前追加しなかった場合は、Security.FrameworkをxCodeのLinked Frameworks and Librariesに追加する必要があります。
iOS Apple Search Ads
以下を追加します。
- AdSupport.framework
- AppsFlyerは、このフレームワークが含まれている場合に限りIDFAを収集します。このフレームワークを追加しない場合、Facebook、Twitter、その他の大半の広告ネットワークを計測できないことになります。
- iAd.framework
-
Apple Search Adsの計測に必須であるため、このフレームワークをアプリのプロジェクトに追加することを強くお勧めします。
3. SDKの初期化
Start / Initメソッド内で、iTunesやGoogle Playで使用するAppsFlyer Dev Key と一意のアプリIDをセットします。 ここでのiOSアプリIDは、"id"接頭辞を付けずに数字のみで設定する必要があります。
次のコードを追加します。
void Start () {
/* Mandatory - set your AppsFlyer’s Developer key. */
AppsFlyer.setAppsFlyerKey ("YOUR_APPSFLYER_DEV_KEY");
/* For detailed logging */
/* AppsFlyer.setIsDebug (true); */
#if UNITY_IOS
/* Mandatory - set your apple app ID
NOTE: You should enter the number only and not the "ID" prefix */
AppsFlyer.setAppID ("YOUR_APP_ID_HERE");
AppsFlyer.trackAppLaunch ();
#elif UNITY_ANDROID
/* Mandatory - set your Android package name */
AppsFlyer.setAppID ("YOUR_ANDROID_PACKAGE_NAME_HERE");
/* For getting the conversion data in Android, you need to add the "AppsFlyerTrackerCallbacks" listener.*/
AppsFlyer.init ("YOUR_APPSFLYER_DEV_KEY","AppsFlyerTrackerCallbacks");
#endif
}
void Start () {
/* Mandatory - set your AppsFlyer’s Developer key. */
AppsFlyer.setAppsFlyerKey ("YOUR_APPSFLYER_DEV_KEY");
/* For detailed logging */
/* AppsFlyer.setIsDebug (true); */
#if UNITY_IOS
/* Mandatory - set your apple app ID
NOTE: You should enter the number only and not the "ID" prefix */
AppsFlyer.setAppID ("YOUR_APP_ID_HERE");
AppsFlyer.trackAppLaunch ();
#elif UNITY_ANDROID
/* Mandatory - set your Android package name */
AppsFlyer.setAppID ("YOUR_ANDROID_PACKAGE_NAME_HERE");
AppsFlyer.init ("YOUR_APPSFLYER_DEV_KEY");
#endif
}
重要!
- Androidでは、AppsFlyer.initでtrackAppLaunchを呼び出します。そのため、UnityプラグインのAndroidビルドでは、trackAppLaunchを呼び出さないでください。
- iOSでは、コンバージョンデータの応答は、AppsFlyerTrackerCallbacks.csクラスでトリガーされます。
4. アプリ内イベントのトラッキング
アプリ内イベントにより、アプリ内の動作に関するインサイトを得ることができます。ROI(投資収益率)やLTV(顧客生涯価値)を計測するために、時間を取って計測するイベントを定義することをお勧めします。
Tracking in-app events is performed by calling trackRichEvent
with event name and value parameters. See In-App Events documentation for more details.
注
アプリ内イベント名は45文字以下である必要があります。イベント名が45文字を超える場合は管理画面に表示されず、ローデータ、Pull API、Push APIにのみ表示されます。
イベントトラッキングの例:
System.Collections.Generic.Dictionary<string, string> purchaseEvent = new
System.Collections.Generic.Dictionary<string, string> ();
purchaseEvent.Add ("af_currency", "USD");
purchaseEvent.Add ("af_revenue", "0.99");
purchaseEvent.Add ("af_quantity", "1");
AppsFlyer.trackRichEvent ("af_purchase", purchaseEvent);
注
AppsFlyerでは、Unity SDKバージョン4.15.1以降で、アプリ内イベント、他のSDK APIで、英語以外の文字をサポートしています。
5. ディープリンクの計測
For deep linking, follow the instructions according to your operating system.
<activity android:name="com.appsflyer.GetDeepLinkingActivity" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="your_scheme" />
</intent-filter>
</activity>
Follow the native iOS Integration Guide.
注:
Unityプラグインは、AppControllerをIMPL_APP_CONTROLLER_SUBCLASSフラグと使用します。プロジェクトにこのフラグを使用する追加のプラグインが含まれている場合、すべてのコードを1つのAppControllerに統合する必要があります。
6. 収益の計測
AFInAppEvents.REVENUE
イベントパラメータを使用し、収益をアプリ内イベントの一部としてカウントします。正負を問わず、あらゆる数値を入力できます。
注
AFInAppEvents.REVENUE
(af_revenue
の使用と同等)は、AppsFlyerのローデータと管理画面で真の収益としてカウントされる唯一のイベントパラメータです。詳細については、こちらをクリックしてください。
例
課金イベントAppsFlyer.trackRichEvent(AFInAppEvents.LEVEL_ACHIEVED, new Dictionary<string, string>(){
{AFInAppEvents.CONTENT_ID, "1234567"},
{AFInAppEvents.CONTENT_TYPE, "category_a"},
{AFInAppEvents.REVENUE, "1.99"},
{AFInAppEvents.CURRENCY, "USD"}
});
重要!
Do NOT format the revenue value in any way. It should not contain comma separators, currency sign, or text. A revenue event should be similar to 1234.56, for example.
7. コンバージョンデータの取得
AppsFlyerでは、直接SDKレベルでユーザーのコンバージョンデータにリアルタイムでアクセスできます。これによって、ユーザーが新しくアプリをインストールした後、初めてアプリを開くと表示されるランディングページをカスタマイズすることができます。
AppsFlyerのコンバージョンデータをサーバーからロードするには:
- 空の
GameObject
を追加します。 - プロジェクトに含まれるAppsFlyerTrackerCallbacks.csに添付します(このgameobjectをAppsFlyerTrackerCallbacksと名付ける必要があります)。
/*For getting the conversion data in Android, you need to add this listener. to the init() method*/
AppsFlyer.init ("YOUR_DEV_KEY","AppsFlyerTrackerCallbacks");
Androidでは、メソッドをAppsFlyerTrackerCallbacks.csから別のクラスに移動し、そのクラスをリスナーで呼び出すことができます。
AppsFlyerTrackerCallbacks
に表示されるものとまったく同じメソッドのnamespaceを使用する必要があります。
/*For getting the conversion data in Android, you need to add this listener.*/
AppsFlyer.loadConversionData("AppsFlyerTrackerCallbacks");
Androidでは、メソッドをAppsFlyerTrackerCallbacks.csから別のクラスに移動し、そのクラスをリスナーで呼び出すことができます。
AppsFlyerTrackerCallbacks
に表示されるものとまったく同じメソッドのnamespaceを使用する必要があります。
/* For getting the conversion data. This is triggered on AppsFlyerTrackerCallbacks.cs file */
AppsFlyer.getConversionData ();
AppsFlyerTrackerCallbacks.csクラスからの例(ロジックをこのメソッドで実装)-
public void didReceiveConversionData(string conversionData) {
print ("AppsFlyerTrackerCallbacks:: got conversion data = " + conversionData);
}
8. ユーザー識別子
AppsFlyerデバイスIDの取得
AppsFlyerの一意のデバイスIDは、アプリが新しくインストールされるたびに作成されます。AppsFlyerの一意のIDを取得するには、次のAPIを使用します。
public String getAppsFlyerId();
使用例:
string AppsFlyerUID = AppsFlyer.getAppsFlyerId();
顧客ユーザーIDの設定
アプリで使用される通りにユーザーIDを設定します。
ユーザーIDを設定するには、次のメソッドを呼び出します。
AppsFlyer.setCustomerUserID("someId");
注
customerUserID
は、trackAppLaunch/initの前に設定する必要があります。この設定後に報告されるイベントにのみ関連付けられるため、顧客ユーザーIDはできる限り早く設定することをお勧めします。また、顧客ユーザーIDは、MixpanelやSwrveなどのアナリティクスプラットフォームとの連携を完了させるためにも利用できます。
顧客ユーザーIDの詳細については、こちらをクリックしてくだい。
ユーザーメールの設定
Google Advertising ID
SDKバージョン4.8.0以降、AppsFlyerはgoogle_advertising_id
を自動的に収集します。Google Advertising IDを収集する要件は、バージョン4.7.X以前のSDKにのみ関連します。
IMEIとAndroid ID
デフォルトでは、OSバージョンがKitKat(4.4)より新しく、デバイスにGoogle Play Servicesが含まれている場合( Unity SDK バージョン 4.16.4以前でGoogle Play Servicesが必要な特定のアプリ)、IMEIとAndroid IDはSDKによって収集されません。
これらのIDをAppsFlyerに明示的に送信するには、開発者は以下のAPIを使用することができます。
AppsFlyer.setAndroidIdData(string)
AppsFlyer.setImeiData(string)
アプリにGoogle Play Servicesが含まれていない場合、IMEIとAndroid IDは、SDKによって収集されます。ただし、 Google Play Servicesを使用したアプリの場合、IMEIの収集がGoogle Playのポリシーに違反するため、収集を行わないようにしてください。
開発者は、これらのAPIを使用することで、IMEIとAndroid IDの収集をオプトアウトすることができます。
AppsFlyer.setCollectAndroidID(bool)
AppsFlyer.setCollectIMEI(bool)
警告
適切なアトリビューションには、少なくとも一つのデバイス識別子、GAID、Android IDまたはIMEIを収集する必要があります。
IDFAとIDFV
アプリにAdSupport.frameworkが含まれる場合、AppsFlyerではIDFA(広告主用のID)とIDFV(ベンダー用のID)を自動的に収集します。
9. オプション機能
アンインストールの計測
アンインストールするには、オペレーティングシステムごとの手順に沿って操作します。
2. FirebaseMessaging.unitypackageをプロジェクトにインポートします。
3. (Firebaseコンソールで取得した)プロジェクトにgoogle-services.jsonをインポートします
注
マニフェストレシーバーは、Unity Firebase SDKによって自動的に追加されます。
4. AppsFlyerコードを処理するUnityクラスで以下を追加します。
using Firebase.Messaging;
using Firebase.Unity;
5. Start()メソッドに追加します。
Firebase.Messaging.FirebaseMessaging.TokenReceived += OnTokenReceived;
6. 次のメソッドを追加します。
public void OnTokenReceived
(object sender, Firebase.Messaging.TokenReceivedEventArgs token) {
AppsFlyer.updateServerUninstallToken (token.Token);
}
警告
Unity Firebase SDKを実装するユーザーは、次のenableUninsatallTracking(“SenderID”) へのメソッド呼び出しを追加しないでください。これは、Firebase SDKにより、以前追加したgoogle-services.jsonファイルから送信元IDが取得されるためです。このメソッドを追加すると、Androidのデバッグ警告が表示される場合があります。
重要!
Firebase Cloud Messaging(FCM)はGCMの新バージョンであり、信頼性と拡張性の高いGCMインフラストラクチャを継承しながら、新機能が追加されています。新しいアプリにメッセージング機能を追加するには、まずFCMを使用してください。GCMユーザーは、現在のFCMの新機能だけでなく、将来追加される機能も利用できるように、FCMにアップグレードすることが強く推奨されます。
次の行をマニフェストに追加します。
パーミッション:
<uses-permission android:name="android.permission.WAKE_LOCK" />
<permission android:name="android.appsflyer.sampleapp.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="android.appsflyer.sampleapp.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
注
android.appsflyer.sampleapp
は、アプリケーションのバンドル識別子に置き換える必要があります。
レシーバー:
<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
android:exported="true">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</receiver>
このメソッドを呼び出します。
AppsFlyer.setGCMProjectNumber("Your_GCM_Project_Number");
GCMプロジェクト番号は、Google Developer Consoleから取得します。
詳細については、「Androidアンインストールガイド」を参照してください。
AppsFlyer.registerUninstall("device_push_notification_token");
デバイストークンはUnityEngine.iOS.NotificationServices.deviceToken
から取得できます。
例:
void Start () {
// register to push notifications
UnityEngine.iOS.NotificationServices.RegisterForNotifications(UnityEngine.iOS.NotificationType.Alert | UnityEngine.iOS.NotificationType.Badge | UnityEngine.iOS.NotificationType.Sound);
Screen.orientation = ScreenOrientation.Portrait;
} void Update () {
if (!tokenSent) { // tokenSent needs to be defined somewhere (bool tokenSent = false)
byte[] token = UnityEngine.iOS.NotificationServices.deviceToken;
if (token != null) {
AppsFlyer.registerUninstall (token);
tokenSent = true;
}
}
}
詳細については、「iOSアンインストールガイド」を参照してください。
Tracking Push Notifications
AppsFlyerでは、プッシュ通知をリターゲティングキャンペーンの一部として計測することが可能です。
handlePushNotification(Dictionary<string, string> payload)
データペイロードには、関連するキー/値ストリングと共にオブジェクト:af
が含まれている必要があります。
例:
{
"data":{
"score":"5x1",
"time":"15:10",
"af":{
"c":"test_campaign",
"is_retargeting":"true",
"pid":"push_provider_int"
}
}
}
// with deep-linking
{
"data":{
"score":"5x1",
"time":"15:10",
"click_action":"com.example.someAction",
"af":{
"c":"test_campaign",
"is_retargeting":"true",
"pid":"push_provider_int"
}
}
}
注
プッシュ通知のに関する詳細については、こちらをお読みください。
Cross Promotion Tracking
AppsFlyer allows you to track and attribute installs originating from a cross promotion of one of your apps from within the current app the user has. Cross promoting apps can be a major growth factor in driving additional installs for your apps.
For details, see the Cross Promotion Tracking article, here.
ユーザー招待の計測
AppsFlyer allows you to track and attribute installs originating from user invites within your app. Allowing your existing users to invite their friends and contacts as new users to your app can be a key growth factor for your app.
For details, see the User Invite Tracking article, here.
Set Currency Code
AFInAppEvents.CURRENCY
がアプリ内イベントの一部として送信されない場合に使用されます。
USD(米国ドル)がデフォルト値です。使用可能なISO通貨コードは、こちらで確認することができます。
通貨コードを設定するには、以下のAPIを使用します。
public void setCurrencyCode(String currencyCode);
使用例:
setCurrencyCode(string currencyCode)
アプリ内購入検証
アプリ内購入のレシート検証を行うには、オペレーティングシステムごとの手順に沿って操作します。
//コールバックを取得する
//AppsFlyer.createValidateInAppListener("AppsFlyerTrackerCallbacks",
"onInAppBillingSuccess", "onInAppBillingFailure");
AppsFlyer.validateReceipt(stringpublicKey, string purchaseData,
string signature, string price, string currency, Dictionary additionalParametes);
AppsFlyer.createValidateInAppListener("AppsFlyerTrackerCallbacks", "onInAppBillingSuccess", "onInAppBillingFailure");
(purchaseData variable should hold the original JSON from the purchase).
テストの目的上、次のようにAppleのサンドボックスサーバー呼び出しに対してテストするようにしてください。
AppsFlyer.setIsSandbox(true);
AppsFlyer.validateReceipt(stringproductIdentifier, string price, string currency,
string transactionId, Dictionary additionalParametes);
購入検証の応答は、AppsFlyerTrackerCallbacks.csクラスでトリガーされます
ユーザーデータの匿名化
ユーザーのインストール、イベント、セッションのトラッキングを明示的に匿名化するには、SDKの初期化中にこのAPIを使用します。
public void setDeviceTrackingDisabled(boolean isDisabled);
使用例:
AppsFlyer.setDeviceTrackingDisabled(true);
トラッキングを再開するには、deviceTrackingDisabled
(falseに設定されている)を再度呼び出します。
警告
ユーザーをオプトアウトすることにより、アトリビューション情報に大きな悪影響があります。ユーザーの情報を収集することが法的に禁じられている地域でのみ、このオプションを使用してください。
カスタムのセッション間隔
However, you can use the following API to set your custom value for the minimum required time between sessions:
setMinTimeBetweenSessions(int seconds)
使用例:
AppsFlyer.setMinTimeBetweenSessions(10);
Note that setting a high value to the custom time between launches may badly impact APIs relying on sessions data, such as deep linking.
ユーティリティ系アプリ向けバックグラウンドセッション
現在、Unityでは使用できません。
Track Out-of-Store Apps
注
Google Playがデフォルトのストアです。Google Playのみでアプリを公開する場合、このセクションはスキップしてください。
Google Play以外からのインストールを計測するには、各APKに固有のチャネルやストア名を使用して、アプリのAndroidManifest.xmlでチャネルまたはストアを設定します。CHANNEL値では大文字と小文字を区別します。
例:
<meta-data android:name="CHANNEL" android:value="Amazon" />
<meta-data android:name="CHANNEL" android:value="Standalone"/>
<meta-data android:name="CHANNEL" android:value="Verizon" />
注
アプリのセットアップ時にAppsFlyerの管理画面でCHANNEL値を設定する必要があります。
</application>タグの前にmeta-dataタグを配置します。
ストア外アプリのインストールを計測する方法の詳細については、こちらを参照してください。
Opt-Out
In some extreme cases you might want to shut down all SDK tracking due to legal and privacy compliance. This can be achieved with the isStopTracking API. Once this API is invoked, our SDK no longer communicates with our servers and stops functioning.
AppsFlyer.stopTracking(true);
In any event, the SDK can be reactivated by calling the same API, by passing false.
There are several different scenarios for user opt-out. We highly recommend following the exact instructions for the scenario, that is relevant for your app.
警告
このユーザーをすべてのトラッキングで完全に無視する場合にのみ、このAPIを使用します。このAPIを使用することにより、レポートとアトリビューションに大きな影響があります。
カスタムデータの追加設定
setAdditionalData APIを使用するには、Segment、Adobe、Urban Airshipなど、複数の外部パートナーのプラットフォームとSDKレベルで連携する必要があります。このAPIは、プラットフォームの連携の記事に、 setAdditionalData APIが必要であると記載されている場合にのみ使用してください。
次に、UnityでsetAdditionalDataを実装するコードの例を示します。
Dictionary<string, string> CustomDataMap = new Dictionary<string, string>();
CustomDataMap.Add("custom_param_1", "value_of_param_1");
AppsFlyer.setAdditionalData(CustomDataMap);
プリインストール済みアプリのアトリビューション
Android Only
You can programatically set a pre-installed media source, from Unity, using the following API:
setPreinstallAttribution(string MediaSource, string Campaign, string Site_Id);
For details on native implementations, click here.
重要!
AppsFlyer Unity SDKを使用する場合は、次を避けてください。
PlayerPrebs.DeleteAll()
10. SDK実装テスト
連携をテストするためのオペレーティングシステムごとの手順については、「Android SDK実装テスト」または「iOS SDK実装テスト」を参照してください。
Now you can start tracking the media sources you work with.
11. 既知の問題
ProGuard
If you are using ProGuard for Android and you encounter a warning regarding our AFKeystoreWrapper
class, then add the following code to your ProGuard rules file:
-keep class com.appsflyer.** { *; }
IL2CPP
To exclude our SDK from the Managed bytecode stripping with IL2CPP, add the following to the link.xml:
<linker>
<assembly fullname="mscorlib">
<type fullname="AppsFlyer.*" preserve="all"/>
</assembly>
…
</linker>
12. Unity Sample Project
Unityサンプルプロジェクトを表示するには、こちらをクリックしてください。
コメント
ログインしてコメントを残してください。