Link para o repositório
GitHub

Integração do AppsFlyer Unity Epic SDK

A AppsFlyer capacita os profissionais de marketing de jogos a tomar melhores decisões, fornecendo ferramentas poderosas para executar a atribuição entre plataformas.

A atribuição do jogo requer que o jogo integre o SDK da AppsFlyer que registra as primeiras aberturas, sessões consecutivas e eventos in-app. Por exemplo, eventos de compra.
Recomendamos que você use este aplicativo de exemplo como referência para integrar o SDK da AppsFlyer ao seu jogo Unity Epic.

Note: The sample code that follows is supported in a both Windows & Mac environment.


AppsflyerEpicModule - Interface

AppsflyerEpicModule.cs, incluído na pasta de cenas, contém o código e a lógica necessários para se conectar aos servidores da AppsFlyer e relatar eventos.

AppsflyerEpicModule

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.

Assinatura do método

AppsflyerEpicModule(string appid, string devkey, MonoBehaviour mono, bool isSandbox = false)

Arguments:

  • DEV_KEY: obtenha do profissional de marketing ou do QG da AppsFlyer.
  • EPIC_APP_ID: encontrado no link da loja Epic
  • 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
AppsflyerEpicModule afm = new AppsflyerEpicModule(<< DEV_KEY >>, << EPIC_APP_ID >>, this);

// for init in sandbox mode (reports the events to the sandbox endpoint)
AppsflyerEpicModule afm = new AppsflyerEpicModule(<< DEV_KEY >>, << EPIC_APP_ID >>, this, true);

Start

Este método envia as primeiras solicitações de abertura/sessão para a AppsFlyer.

Assinatura do método

void Start(bool skipFirst = false)

Argumentos

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

Assinatura do método

void Stop()

Usage:

// Starting the SDK
afm.Start();
// ...
// Stopping the SDK, preventing further communication with AppsFlyer
afm.Stop();

LogEvent

Este método recebe um nome de evento e um objeto JSON e envia um evento in-app para a AppsFlyer.

Assinatura do 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_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);

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"

Assinatura do método

bool IsInstallOlderThanDate(string datestring)

Arguments:

  • string datestring: Date string in yyyy-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

Obter o ID do dispositivo exclusivo da AppsFlyer. O SDK gera um ID de dispositivo exclusivo da AppsFlyer na instalação do aplicativo. Quando o SDK é iniciado, esse ID é registrado como o ID da primeira instalação do aplicativo.

Assinatura do método

void GetAppsFlyerUID()

Usage:

AppsflyerEpicModule afm = new AppsflyerEpicModule(<< DEV_KEY >>, << EPIC_APP_ID >>, this);
afm.Start();
string af_uid = afm.GetAppsFlyerUID();

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.

Assinatura do método

void SetCustomerUserId(string cuid)

Arguments:

  • string cuid: Custom user id.

Usage:

AppsflyerEpicModule afm = new AppsflyerEpicModule(DEV_KEY, STEAM_APP_ID, this);
afm.SetCustomerUserId("15667737-366d-4994-ac8b-653fe6b2be4a");
afm.Start();

SetSharingFilterForPartners

This method lets you configure which partners should the SDK exclude from data-sharing. Partners that are excluded with this method will not receive data through postbacks, APIs, raw data reports, or any other means.

Assinatura do método

public void SetSharingFilterForPartners(List<string> sharingFilter)

Arguments:

  • List<string> sharingFilter: a list of partners to filter. For example: new List<string>() {"partner1_int", "partner2_int"};

Usage:

AppsflyerEpicModule afm = new AppsflyerEpicModule(DEV_KEY, APP_ID, this);

// set the sharing filter
var sharingFilter = new List<string>() {"partner1_int", "partner2_int"};
afm.SetSharingFilterForPartners(sharingFilter);

// start the SDK (send firstopen/session request)
afm.Start();

Executando o aplicativo de exemplo

  1. Abra o hub do Unity e abra o projeto.
  2. Use o código de exemplo em AppsflyerEpicScript.cs and update it with your DEV_KEY and APP_ID (in the gaming object).
    gaming-object
  3. Adicione o AppsflyerEpicScript a um objeto de jogo vazio (ou use o da pasta de cenas):
    Request-OK
  4. Inicie o aplicativo de amostra por meio do editor do Unity e verifique se o log de depuração mostra a seguinte mensagem:
    Request-OK
  5. Após 24 horas, o painel da AppsFlyer é atualizado e mostra instalações orgânicas e não orgânicas e eventos in-app.

Implementando a AppsFlyer em seu jogo Epic

Setup

  1. Adicione EOS ao seu projeto Unity. Siga as instruções do plug-in Epic Online Services Unity e adicione-o por meio do gerenciador de pacotes.
  2. Add EOSManager.cs a um objeto de jogo.
  3. Adicione o script de Assets/Scenes/AppsflyerEpicModule.cs ao seu aplicativo.
  4. Use o código de exemplo em Assets/Scenes/AppsflyerEpicScript.cs e atualize-o com o seu DEV_KEY and APP_ID.
  5. Inicialize o SDK.
AppsflyerEpicModule afm = new AppsflyerEpicModule(<< DEV_KEY >>, << EPIC_APP_ID >>, this);
  1. Inicie a integração da AppsFlyer.
  2. Reporte os eventos in-app.

Resetting the attribution

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