Unity Steam
Link to repository
GitHub
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.
Prerequisites
- 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.
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.
Signature de la méthode
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);
Arguments
string DEV_KEY
: Get from the marketer or AppsFlyer HQ.string STEAM_APP_ID
: Found in the 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
This method sends first open and session requests to AppsFlyer.
Signature de la méthode
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.
Signature de la méthode
void Stop()
Usage:
// Starting the SDK
afm.Start();
// ...
// Stopping the SDK, preventing further communication with AppsFlyer
afm.Stop();
LogEvent
This method receives an event name and JSON object and sends in-app events to AppsFlyer.
Signature de la méthode
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
Pour obtenir l'ID d'appareil unique AppsFlyer. Le SDK génère un ID d'appareil unique AppsFlyer lorsque l'application est installée. Lorsque le SDK se lance, cet ID est enregistré comme étant l'ID de la première installation
Signature de la méthode
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()
.
Signature de la méthode
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"
Signature de la méthode
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);
Running the sample app
- Open Unity hub and open the project.
- Add Steamworks to your Unity project. Follow the Steamworks SDK instructions and add it through your package manager.
- Use the sample code in
SteamScript.cs
and update it with yourDEV_KEY
andAPP_ID
. - Ajoutez
SteamManager
andSteamScript
to an empty game object (or use the one in the scenes folder).
- Launch the sample app via the Unity editor and check that your debug log shows the following message:
- After 24 hours, the dashboard updates and shows organic and non-organic installs and in-app events.
Implementing AppsFlyer in your Steam game
- Add Steamworks to your Unity project. Follow the Steamworks SDK instructions and add it through your package manager.
- Add
SteamManager.cs
to a game object. - Add the script from
Assets/Scenes/AppsflyerSteamModule.cs
to your app. - Use the sample code in
Assets/Scenes/SteamScript.cs
and update it with yourDEV_KEY
andAPP_ID
. - Initialize the SDK.
AppsflyerSteamModule afm = new AppsflyerSteamModule(DEV_KEY, STEAM_APP_ID, this);
- Start the AppsFlyer integration.
- Report in-app events.
Deleting Steam cloud saves (resetting the attribution)
- Disable Steam cloud.
- Delete the local files.
- Delete the PlayerPrefs data the registry/preferences folder, or use PlayerPrefs.DeleteAll() when testing the attribution in the UnityEditor.
Mis(e) à jour il y a 16 jours