Native PC Unity
AppsFlyer Native PC Unity SDK integration
AppsFlyerは、クロスプラットフォームアトリビューションを実行するための強力なツールを提供することで、ゲームマーケティング担当者がより良い意思決定を行えるよう支援します。
Game attribution requires the game to integrate the AppsFlyer SDK that records first opens, consecutive sessions, and in-app events. For example, purchase events.
We recommend you use this sample app as a reference for integrating the AppsFlyer SDK into your Unity Native PC game.
AppsflyerModule - Interface
AppsflyerModule.cs
, included in the scenes folder, contains the required code and logic to connect to AppsFlyer servers and report events.
AppsflyerModule
This method receives your API key, App ID, the parent MonoBehaviour and a sandbox mode flag (optional, false by default) and initializes the AppsFlyer Module.
メソッドのシグネチャ
AppsflyerModule(string devkey, string appid, MonoBehaviour mono, bool isSandbox = false)
例:
// for regular init
AppsflyerModule afm = new AppsflyerModule(<< DEV_KEY >>, << APP_ID >>, this);
// for init in sandbox mode (reports the events to the sandbox endpoint)
AppsflyerModule afm = new AppsflyerModule(<< DEV_KEY >>, << APP_ID >>, this, true);
Arguments:
DEV_KEY
: Get from the marketer or AppsFlyer HQ.APP_ID
: The app id on Appsflyer HQMonoBehaviour mono
:bool isSandbox
: Whether to activate sandbox mode. False by default.
Start
このメソッドは、first open / session(初回起動 / セッション)リクエストをAppsFlyerに送信します。
メソッドのシグネチャ
void Start(bool skipFirst = false)
例:
// without the flag
afm.Start();
// with the flag
bool skipFirst = [SOME_CONDITION];
afm.Start(skipFirst);
Stop
Once this method is invoked, our SDK no longer communicates with our servers and stops functioning.
Useful when implementing user opt-in/opt-out.
メソッドのシグネチャ
void Stop()
例:
// Starting the SDK
afm.Start();
// ...
// Stopping the SDK, preventing further communication with AppsFlyer
afm.Stop();
LogEvent
このメソッドは、イベント名とJSONオブジェクトを受け取り、アプリ内イベントをAppsFlyerに送信します。
メソッドのシグネチャ
void LogEvent(string event_name, Dictionary<string, object> event_parameters)
例:
// set event name
string event_name = "af_purchase";
// set event values
Dictionary<string, object> event_parameters = new Dictionary<string, object>();
event_parameters.Add("af_currency", "USD");
event_parameters.Add("af_price", 6.66);
event_parameters.Add("af_revenue", 12.12);
// send logEvent request
afm.LogEvent(event_name, event_parameters);
IsInstallOlderThanDate
This method receives a date string and returns true if the game folder creation date is older than the date string. The date string format is: "2023-03-01T23:12:34+00:00"
メソッドのシグネチャ
bool IsInstallOlderThanDate(string datestring)
例:
// the creation date in this example is "2023-03-23T08:30:00+00:00"
bool newerDate = afm.IsInstallOlderThanDate("2023-06-13T10:00:00+00:00");
bool olderDate = afm.IsInstallOlderThanDate("2023-02-11T10:00:00+00:00");
// will return true
Debug.Log("newerDate:" + (newerDate ? "true" : "false"));
// will return false
Debug.Log("olderDate:" + (olderDate ? "true" : "false"));
// example usage with skipFirst -
// skipping if the install date is NOT older than the given date
bool IsInstallOlderThanDate = afm.IsInstallOlderThanDate("2023-02-11T10:00:00+00:00");
afm.Start(!IsInstallOlderThanDate);
SetCustomerUserId
Setting your own customer ID enables you to cross-reference your own unique ID with AppsFlyer’s unique ID and other devices’ IDs.
This ID is available in raw-data reports and in the Postback APIs for cross-referencing with your internal IDs.
Can be used only before calling Start()
.
メソッドのシグネチャ
void SetCustomerUserId(string cuid)
例:
AppsflyerSteamModule afm = new AppsflyerSteamModule(DEV_KEY, STEAM_APP_ID, this);
afm.SetCustomerUserId("15667737-366d-4994-ac8b-653fe6b2be4a");
afm.Start();
GetAppsFlyerUID
AppsFlyerのユニークデバイスIDを取得します。SDKはアプリのインストール時にAppsFlyerのユニークなデバイスIDを生成します。SDKを起動すると、このIDが最初のアプリインストール時のIDとして記録されます。
メソッドのシグネチャ
void GetAppsFlyerUID()
例:
AppsflyerModule afm = new AppsflyerModule(<< DEV_KEY >>, << APP_ID >>, this);
afm.Start();
string af_uid = afm.GetAppsFlyerUID();
サンプルアプリの実行
- Unity hubを開き、プロジェクトを開きます。
- Use the sample code in AppsflyerScript.cs and update it with your DEV_KEY and APP_ID.
- Add the AppsflyerScript to an empty game object (or use the one in the scenes folder):
- Unityエディターでサンプルアプリを起動し、デバッグログに以下のメッセージが表示されることを確認します:
- 24時間後にダッシュボードが更新され、オーガニックとノンオーガニックのインストールとアプリ内イベントが表示されます。
Implementing AppsFlyer in your Native PC game
Setup
- スクリプトの追加元
Assets/AppsflyerModule.cs
をアプリに追加します。 - Use the sample code in
Assets/AppsflyerScript.cs
and update it with yourDEV_KEY
andAPP_ID
. - SDKの初期化
AppsflyerModule afm = new AppsflyerModule(<< DEV_KEY >>, << APP_ID >>, this);
- AppsFlyerの実装を開始しましょう。
- Report in-app events.
Resetting the attribution
Delete the PlayerPrefs data the registry/preferences folder, or use PlayerPrefs.DeleteAll() when testing the attribution in the UnityEditor.
更新済 23日前