Meta Quest 2 Unity
Ссылка на репозиторий
GitHub
AppsFlyer Meta Quest Unity SDK integration
Integrate your Meta Quest Unity app or game with AppsFlyer to measure the performance of campaigns marketing these apps.
Game attribution and user measurement require the game to integrate an AppsFlyer SDK that records first opens, sessions, and in-app events. For example, purchase events.
Необходимые условия
- Unity 2021.3.16f1
- The Oculus SDK: Follow the Oculus SDK for Unity integration guide.
- Oculus Quest 2/3 Headset
AppsflyerModule - Interface
AppsflyerModule.cs
в папке сцен содержит необходимый код и логику для подключения к серверам AppsFlyer и передачи отчетов по событиям.
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)
Arguments:
string DEV_KEY
: получите у маркетолога или AppsFlyer HQ.string QUEST_APP_ID
: Your Quest Store app ID. For Quest 2/3, this is the number in the store URL. For example: https://www.oculus.com/experiences/quest/XXXXXXXXXXXXXXXX/.MonoBehaviour mono
: The parent MonoBehaviour.bool isSandbox
: Flag that determines whether to activate sandbox mode. False by default. This option is for debugging. With the sandbox mode, AppsFlyer dashboard doesn't show the data.
Usage:
// for regular init
AppsflyerModule afm = new AppsflyerModule(<< DEV_KEY >>, << QUEST_APP_ID >>, this);
// for init in sandbox mode (reports the events to the sandbox endpoint)
AppsflyerModule afm = new AppsflyerModule(<< DEV_KEY >>, << QUEST_APP_ID >>, this, true);
Start
Данный метод передает запросы «first open/session» в AppsFlyer.
Сигнатура метода
void Start(bool skipFirst = false)
Аргументы
bool skipFirst
: Determines whether or not to skip first open events and send session events. The value is false by default. If true , first open events are skipped and session events are sent. See example
Usage:
// without the flag
afm.Start();
// with the flag
bool skipFirst = [SOME_CONDITION];
afm.Start(skipFirst);
Stop
This method stops the SDK from functioning and communicating with AppsFlyer servers. It's used when implementing user opt-in/opt-out.
Сигнатура метода
void Stop()
Usage:
// 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,
Dictionary<string, object> event_custom_parameters = null
)
Arguments:
string event_name
: The name of the event.Dictionary<string, object> event_parameters
: Dictionary object that contains the predefined event parameters.Dictionary<string, object> event_custom_parameters
: [Optional] Dictionary object which contains the any custom event parameters.
Usage:
// 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_revenue", 12.12);
// send logEvent request
afm.LogEvent(event_name, event_parameters);
// send logEvent request with custom params
Dictionary<string, object> event_custom_parameters = new Dictionary<string, object>();
event_custom_parameters.Add("goodsName", "新人邀约购物日");
afm.LogEvent(event_name, event_parameters, event_custom_parameters);
SetCustomerUserId
This method sets a customer ID that enables you to cross-reference your unique ID with the AppsFlyer unique ID and other device IDs. Note: You can only use this method before calling Start()
.
The customer ID is available in raw data reports and in the postbacks sent via API.
Сигнатура метода
void SetCustomerUserId(string cuid)
Arguments:
string cuid
: Custom user id.
Usage:
AppsflyerModule afm = new AppsflyerModule(<< DEV_KEY >>, << QUEST_APP_ID >>, this);
afm.SetCustomerUserId("TestCUID");
afm.Start();
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)
Arguments:
string datestring
: Date string inyyyy-mm-ddThh:mm:ss+hh:mm
format.
Usage:
// 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);
GetAppsFlyerUID
Get the AppsFlyer unique device ID. The SDK generates an AppsFlyer unique device ID upon app installation. When the SDK is started, this ID is recorded as the ID of the first app install.
Сигнатура метода
void GetAppsFlyerUID()
Usage:
AppsflyerModule afm = new AppsflyerModule(<< DEV_KEY >>, << QUEST_APP_ID >>, this);
afm.Start();
string af_uid = afm.GetAppsFlyerUID();
Запуск примера приложения
- Откройте хаб Unity и откройте проект.
- Используйте пример кода в
AppsflyerScript.cs
and update it with your DEV_KEY and QUEST_APP_ID. - Add the AppsflyerScript to an empty game object (or use the one in the scenes folder).
- Launch the sample app via the Unity editor and check that your debug log shows the following messages:
- Через 24 часа дэшборд AppsFlyer обновляется и отображает органические и неорганические установки и внутренние события приложения.
Implementing AppsFlyer in your Meta Quest game
Setup
- Добавьте скрипт из
Assets/AppsflyerModule.cs
в ваше приложение. - Используйте пример кода в
Assets/AppsflyerScript.cs
и обновите его данными своихDEV_KEY
andQUEST_APP_ID
. - Инициализируйте SDK.
AppsflyerModule afm = new AppsflyerModule(<< DEV_KEY >>, << QUEST_APP_ID >>, this);
- Начните интеграцию AppsFlyer.
- Подайте отчет о внутренних событиях приложения.
Resetting the attribution
Delete the PlayerPrefs data in the registry/preferences folder, or use the PlayerPrefs.DeleteAll() function when testing the attribution in the UnityEditor.
Изменения сохранены 10 месяцев назад