Native PC Unity

리포지토리에 연결

AppsFlyer Native PC Unity SDK integration

는 앱스플라이어크로스 플랫폼 어트리뷰션을 수행할 수 있는 강력한 도구를 제공하여 게임 마케터가 더 나은 결정을 내릴 수 있도록 지원합니다.

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.

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

AppsflyerModule - Interface

AppsflyerModule.cs는 scenes 폴더에 들어 있으며 앱스플라이어 서버에 연결하고 이벤트를 리포트하는 데 필요한 코드와 로직이 포함되어 있습니다.


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.

Method signature

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


  • DEV_KEY: 마케터 또는 앱스플라이어 본사에서 얻을 수 있습니다.
  • APP_ID: The app id on Appsflyer HQ (excluding the nativepc- 제외).
  • 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.


// 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);


이 메서드는 앱스플라이어에 first open/session 요청을 보냅니다.

Method signature

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


// without the flag

// with the flag
bool skipFirst = [SOME_CONDITION];


This method stops the SDK from functioning and communicating with AppsFlyer servers. It's used when implementing user opt-in/opt-out.

Method signature

void Stop()


// Starting the SDK
// ...
// Stopping the SDK, preventing further communication with AppsFlyer


이 메서드는 이벤트 이름과 JSON 객체를 수신하고 앱스플라이어에 인앱이벤트를 보냅니다.

Method signature

void LogEvent(
      string event_name,
      Dictionary<string, object> event_parameters,
      Dictionary<string, object> event_custom_parameters = null


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


// 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);


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"

Method signature

bool IsInstallOlderThanDate(string datestring)


  • string datestring: Date string in yyyy-mm-ddThh:mm:ss+hh:mm format.


// 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");


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.

Method signature

void SetCustomerUserId(string cuid)


  • string cuid: Custom user id.


AppsflyerSteamModule afm = new AppsflyerSteamModule(DEV_KEY, STEAM_APP_ID, this);


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.

Method signature

public void SetSharingFilterForPartners(List<string> sharingFilter)


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


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

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

// start the SDK (send firstopen/session request)


앱스플라이어의 고유 기기 ID를 가져옵니다. SDK는 앱 설치 시 앱스플라이어의 고유 기기 ID를 생성합니다. SDK가 시작되면 이 ID가 첫 번째 앱 인스톨의 ID로 기록됩니다.

Method signature

void GetAppsFlyerUID()


AppsflyerModule afm = new AppsflyerModule(<< DEV_KEY >>, << APP_ID >>, this);
string af_uid = afm.GetAppsFlyerUID();

샘플 앱 실행

  1. Unity 허브를 열고 프로젝트를 엽니다.
  2. Use the sample code in AppsflyerScript.cs and update it with your DEV_KEY and APP_ID.
  3. Add the AppsflyerScript to an empty game object (or use the one in the scenes folder):
  4. Unity 편집기를 통해 샘플 앱을 실행하고 디버그 로그에 다음 메시지가 표시되는지 확인합니다.
  5. 24시간 후 앱스플라이어 대시보드가 업데이트되고 오가닉 및 논오가닉 인스톨과 인앱이벤트가 표시됩니다.

Implementing AppsFlyer in your Native PC game


  1. 스크립트를 Assets/AppsflyerModule.cs 에서 앱으로 추가합니다.
  2. Assets/AppsflyerScript.cs 의 샘플 코드를 사용하여 다음을 업데이트 합니다: DEV_KEY and APP_ID.
  3. SDK 초기화.
AppsflyerModule afm = new AppsflyerModule(<< DEV_KEY >>, << APP_ID >>, this);
  1. 앱스플라이어 연동을시작합니다.
  2. 인앱 이벤트를 리포트합니다.

Resetting the attribution

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