Unity Steam

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.


  • 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 and the parent MonoBehaviour and initializes the AppsFlyer Module.

Method signature

AppsflyerSteamModule(string devkey, string appid, MonoBehaviour mono)


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



This method sends first open and session requests to AppsFlyer.

Method signature

void Start(bool skipFirst = false)


// without the flag

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


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

Method signature

void LogEvent(string event_name, Dictionary<string, object> 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_price", 6.66);
event_parameters.Add("af_revenue", 12.12);
// send logEvent request
afm.LogEvent(event_name, event_parameters);


Get AppsFlyer's unique device ID. The SDK generates an AppsFlyer unique device ID upon app installation. When the SDK is started, this ID is recorded as the ID of the first app install.

Method signature

string GetAppsFlyerUID()


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


Method signature

bool IsInstallOlderThanDate(string datestring)

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-January-01T23:12:34+00:00"

// the creation date in this example is "2023-January-23T08:30:00+00:00"

// will return false
bool dateBefore = AppsflyerSteamModule()->IsInstallOlderThanDate("2023-January-01T23:12:34+00:00");

// will return true
bool dateAfter = AppsflyerSteamModule()->IsInstallOlderThanDate("2023-April-10T23:12:34+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. Add the 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");
  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.