Meta Quest 2 Unity
Enlace al repositorio de
GitHub
AppsFlyer Meta Quest Unity SDK integration
AppsFlyer permite a los marketers de gaming tomar mejores decisiones al proporcionarles potentes herramientas para realizar atribuciones multiplataforma.
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 Meta Quest game.
Requisitos previos
- Unity 2021.3.16f1
- The Oculus SDK - follow the Oculus SDK for Unity integration guide.
- Oculus Quest 2 Headset
AppsflyerModule - Interface
AppsflyerModule.cs
, incluido en la carpeta de escenas, contiene el código y la lógica necesarios para conectarse a los servidores de AppsFlyer y reportar eventos.
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.
Firma de método
AppsflyerModule(string devkey, string appid, MonoBehaviour mono, bool isSandbox = false)
Arguments:
string DEV_KEY
: puedes obtenerlo del marketer o en AppsFlyer HQ.string QUEST_APP_ID
: Your Quest Store app ID (For Quest 2, it's the number in the store URL - for example: https://www.oculus.com/experiences/quest/XXXXXXXXXXXXXXXX/).MonoBehaviour mono
: the parent MonoBehaviour.bool isSandbox
: Whether to activate sandbox mode. False by default. This option is for debugging. With the sandbox mode, AppsFlyer dashboard does not 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
Este método envía las solicitudes de primeros inicios/sesiones a AppsFlyer.
Firma de método
void Start(bool skipFirst = false)
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.
Firma de método
void Stop()
Usage:
// Starting the SDK
afm.Start();
// ...
// Stopping the SDK, preventing further communication with AppsFlyer
afm.Stop();
LogEvent
Este método recibe un nombre de evento y un objeto json y envía un evento in-app a AppsFlyer.
Firma de método
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 which contains the predefined event parameters.Dictionary<string, object> event_custom_parameters
: (non-mandatory): 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_price", 6.66);
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.
Firma de método
void SetCustomerUserId(string cuid)
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"
Firma de método
bool IsInstallOlderThanDate(string datestring)
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
Obtén el ID de dispositivo único de AppsFlyer. El SDK genera un ID de dispositivo único de AppsFlyer tras la instalación de la aplicación. Cuando se inicia el SDK, este ID se registra como el ID de la primera instalación de la aplicación.
Firma de método
void GetAppsFlyerUID()
Usage:
AppsflyerModule afm = new AppsflyerModule(<< DEV_KEY >>, << QUEST_APP_ID >>, this);
afm.Start();
string af_uid = afm.GetAppsFlyerUID();
Ejecución de la aplicación de muestra
- Abre el hub Unity y abre el proyecto.
- Use the sample code in 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):
- Inicia la aplicación de muestra a través del editor de Unity y verifica que tu registro de depuración muestre el siguiente mensaje:
- Después de 24 horas, el panel de control se actualiza y muestra las instalaciones orgánicas y no orgánicas y los eventos in-app.
Implementing AppsFlyer in your Meta Quest game
Setup
- Agrega el script de
Assets/AppsflyerModule.cs
a tu aplicación. - Utiliza el código de muestra en
Assets/AppsflyerScript.cs
y actualízalo con tuDEV_KEY
andQUEST_APP_ID
. - Inicializa el SDK.
AppsflyerModule afm = new AppsflyerModule(<< DEV_KEY >>, << QUEST_APP_ID >>, this);
- Inicia la integración de AppsFlyer.
- Reporta los eventos in-app.
Resetting the attribution
Delete the PlayerPrefs data the registry/preferences folder, or use PlayerPrefs.DeleteAll() when testing the attribution in the UnityEditor.
Actualizado hace 15 días