Link to repository

AppsFlyer Unity Steam SDK integration

AppsFlyer empowers gaming marketers to make better decisions by providing powerful tools to perform cross-platform attribution.

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 Steam game.

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


  • Unity Engine.
  • Steamworks SDK integrated within your Unity project.
  • Steam client installed with an active user. Note: It must be running for testing.

AppsflyerSteamModule - Interface

AppsflyerSteamModule.cs, included in the scenes folder, contains the required code and logic to connect to AppsFlyer servers and report events.


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.

Signature metode

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


  • string DEV_KEY: Get from the marketer or AppsFlyer HQ.
  • string STEAM_APP_ID: Found in the SteamDB.
  • 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.
  • bool collectSteamUid: Whether to collect Steam UID or not. True by default.


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


This method sends first open and session requests to AppsFlyer.

Signature metode

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.

Signature metode

void Stop()


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


This method receives an event name and JSON object and sends an in-app event to AppsFlyer.

Signature metode

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


Dapatkan ID perangkat unik AppsFlyer. SDK menghasilkan ID perangkat unik AppsFlyer setelah penginstalan aplikasi. Ketika SDK dimulai, ID ini dicatat sebagai ID dari penginstalan aplikasi pertama.

Signature metode

string GetAppsFlyerUID()


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


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.

Signature metode

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.

Signature metode

public void SetSharingFilterForPartners(List<string> sharingFilter)


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


AppsflyerSteamModule afm = new AppsflyerSteamModule(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)


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"

Signature metode

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

Running the sample app

  1. Open Unity hub and open the project.
  2. Add Steamworks to your Unity project. Follow the Steamworks SDK instructions and add it through your package manager.
  3. Use the sample code in SteamScript.cs and update it with your DEV_KEY and APP_ID.
  4. Tambahkan SteamManager and SteamScript to an empty game object (or use the one in the scenes folder).
  5. Launch the sample app via the Unity editor and check that your debug log shows the following message:
  6. After 24 hours, the dashboard updates and shows organic and non-organic installs and in-app events.

Implementing AppsFlyer in your Steam game

  1. Add Steamworks to your Unity project. Follow the Steamworks SDK instructions and add it through your package manager.
  2. Add SteamManager.cs to a game object.
  3. Add the script from Assets/Scenes/AppsflyerSteamModule.cs to your app.
  4. Use the sample code in Assets/Scenes/SteamScript.cs and update it with your DEV_KEY and APP_ID.
  5. Initialize the SDK.
AppsflyerSteamModule afm = new AppsflyerSteamModule(DEV_KEY, STEAM_APP_ID, this);
  1. Start the AppsFlyer integration.
  2. Report in-app events.

Deleting Steam cloud saves (resetting the attribution)

  1. Disable Steam cloud.
  2. Delete the local files.
  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