Enlace al repositorio de
GitHub

Integración del SDK de AppsFlyer con Unity Steam

AppsFlyer permite a los marketers de gaming tomar mejores decisiones al proporcionarles potentes herramientas para realizar atribuciones multiplataforma.

La atribución de un juego requiere que este integre el SDK de AppsFlyer, que registra los primeros inicios, las sesiones consecutivas y los eventos in-app. Por ejemplo, los eventos de compra.
Te recomendamos que uses esta aplicación de muestra como referencia para integrar el SDK de AppsFlyer en tu juego de Unity Steam.


Prerequisites

  • Motor Unity.
  • SDK de Steamworks integrado dentro de tu proyecto de Unity.
  • Cliente Steam instalado con un usuario activo. Nota: Debe estar ejecutándose para pruebas.

AppsflyerSteamModule - Interfaz

AppsflyerSteamModule.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.

AppsflyerSteamModule

This method receives your API key, Steam app ID, the parent MonoBehaviour and a sandbox mode flag (optional, false by default) and initializes the AppsFlyer Module.

Firma de método

AppsflyerSteamModule(
   string DEV_KEY,
   string STEAM_APP_ID,
   MonoBehaviour mono,
   bool isSandbox = false,
   bool collectSteamUid = true
)

Usage:

// for regular init
AppsflyerSteamModule afm = new AppsflyerSteamModule(DEV_KEY, STEAM_APP_ID, this);

// for init in sandbox mode (reports the events to the sandbox endpoint)
AppsflyerSteamModule afm = new AppsflyerSteamModule(DEV_KEY, STEAM_APP_ID, this, true);

// for init without reporting steam_uid
AppsflyerSteamModule afm = new AppsflyerSteamModule(DEV_KEY, STEAM_APP_ID, this, false, false);

Argumentos

  • string DEV_KEY: puedes obtenerlo del marketer o en AppsFlyer HQ.
  • string STEAM_APP_ID: se encuentra en SteamDB.
  • MonoBehaviour mono:
  • bool isSandbox: Whether to activate sandbox mode. False by default.
  • bool collectSteamUid: Whether to collect Steam UID or not. True by default.

Start

Este método envía las solicitudes de primeros inicios y 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

Once this method is invoked, our SDK no longer communicates with our servers and stops functioning.
Useful 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 eventos in-app a AppsFlyer.

Firma de método

void LogEvent(string event_name, Dictionary<string, object> 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);

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

string GetAppsFlyerUID()

Usage:

AppsflyerSteamModule afm = new AppsflyerSteamModule(DEV_KEY, STEAM_APP_ID, this);
afm.Start();
string af_uid = afm.GetAppsFlyerUID();

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().

Firma de método

void SetCustomerUserId(string cuid)

Usage:

AppsflyerSteamModule afm = new AppsflyerSteamModule(DEV_KEY, STEAM_APP_ID, this);
afm.SetCustomerUserId("15667737-366d-4994-ac8b-653fe6b2be4a");
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-13T10:00:00+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);

Ejecución de la aplicación de muestra

  1. Abre el hub Unity y abre el proyecto.
  2. Agrega Steamworks a tu proyecto de Unity. Sigue las instrucciones del SDK de Steamworks y agrégalo a través de tu gestor de paquetes.
  3. Utiliza el código de muestra en SteamScript.cs y actualízalo con tu DEV_KEY and APP_ID.
  4. Agrega SteamManager and SteamScript a un objeto de juego vacío (o usa el que está en la carpeta de escenas).
    Request-OK
  5. 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:
    Request-OK
  6. 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.

Implementación de AppsFlyer en tu juego de Steam

  1. Agrega Steamworks a tu proyecto de Unity. Sigue las instrucciones del SDK de Steamworks y agrégalo a través de tu gestor de paquetes.
  2. Add SteamManager.cs a un objeto de juego.
  3. Agrega el script de Assets/Scenes/AppsflyerSteamModule.cs a tu aplicación.
  4. Utiliza el código de muestra en Assets/Scenes/SteamScript.cs y actualízalo con tu DEV_KEY and APP_ID.
  5. Inicializa el SDK.
AppsflyerSteamModule afm = new AppsflyerSteamModule(DEV_KEY, STEAM_APP_ID, this);
  1. Inicia la integración de AppsFlyer.
  2. Reporta los eventos in-app.

Eliminación de Steam Cloud Saves (restablecer la atribución)

  1. Desactiva Steam Cloud.
  2. Elimina los archivos locales.
  3. Delete the PlayerPrefs data the registry/preferences folder, or use PlayerPrefs.DeleteAll() when testing the attribution in the UnityEditor.
    AF guid & counter in the Windows Registry