{"id":21478269,"url":"https://github.com/appsflyersdk/appsflyer-unity-steam-sample-app","last_synced_at":"2025-07-15T11:30:36.343Z","repository":{"id":141149268,"uuid":"604706854","full_name":"AppsFlyerSDK/appsflyer-unity-steam-sample-app","owner":"AppsFlyerSDK","description":null,"archived":false,"fork":false,"pushed_at":"2024-04-16T15:07:19.000Z","size":178,"stargazers_count":1,"open_issues_count":0,"forks_count":3,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-04-23T03:41:08.105Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AppsFlyerSDK.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2023-02-21T16:13:31.000Z","updated_at":"2023-10-25T16:17:12.000Z","dependencies_parsed_at":null,"dependency_job_id":"458a5c42-25ef-4e8b-ad03-8e4c7b274b80","html_url":"https://github.com/AppsFlyerSDK/appsflyer-unity-steam-sample-app","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AppsFlyerSDK%2Fappsflyer-unity-steam-sample-app","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AppsFlyerSDK%2Fappsflyer-unity-steam-sample-app/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AppsFlyerSDK%2Fappsflyer-unity-steam-sample-app/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AppsFlyerSDK%2Fappsflyer-unity-steam-sample-app/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AppsFlyerSDK","download_url":"https://codeload.github.com/AppsFlyerSDK/appsflyer-unity-steam-sample-app/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226033200,"owners_count":17563127,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-23T11:17:28.792Z","updated_at":"2024-11-23T11:17:32.362Z","avatar_url":"https://github.com/AppsFlyerSDK.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\ntitle: Unity Steam\nparentDoc: 64ad63e4b848351d3acc44d0\ncategory: 6446526dddf659006c7ea807\norder: 1\nhidden: false\nslug: unity-steam\n---\n\n\u003e Link to repository  \n\u003e [GitHub](https://github.com/AppsFlyerSDK/appsflyer-unity-steam-sample-app)\n\n## AppsFlyer Unity Steam SDK integration\n\nAppsFlyer empowers gaming marketers to make better decisions by providing powerful tools to perform cross-platform attribution.\n\nGame attribution requires the game to integrate the AppsFlyer SDK that records first opens, consecutive sessions, and in-app events. For example, purchase events.  \nWe recommend you use this sample app as a reference for integrating the AppsFlyer SDK into your Unity Steam game.\n\n**Note**: The sample code that follows is supported in a both Windows \u0026 Mac environment.\n\n\u003chr/\u003e\n\n### Prerequisites\n\n- Unity Engine.\n- [Steamworks SDK](https://steamworks.github.io/) integrated within your Unity project.\n- Steam client installed with an active user. Note: It must be running for testing.\n\n\u003chr/\u003e\n\n## AppsflyerSteamModule - Interface\n\n`AppsflyerSteamModule.cs`, included in the scenes folder, contains the required code and logic to connect to AppsFlyer servers and report events.\n\n### AppsflyerSteamModule\n\nThis 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.\n\n**Method signature**\n\n```c#\nAppsflyerSteamModule(\n   string DEV_KEY,\n   string STEAM_APP_ID,\n   MonoBehaviour mono,\n   bool isSandbox = false,\n   bool collectSteamUid = true\n)\n```\n\n**Arguments**\n\n- `string DEV_KEY`: Get from the marketer or [AppsFlyer HQ](https://support.appsflyer.com/hc/en-us/articles/211719806-App-settings-#general-app-settings).\n- `string STEAM_APP_ID`: Found in the [SteamDB](https://steamdb.info/apps/).\n- `MonoBehaviour mono`: the parent MonoBehaviour.\n- `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.\n- `bool collectSteamUid`: Whether to collect Steam UID or not. True by default.\n\n**Usage**:\n\n```c#\n// for regular init\nAppsflyerSteamModule afm = new AppsflyerSteamModule(DEV_KEY, STEAM_APP_ID, this);\n\n// for init in sandbox mode (reports the events to the sandbox endpoint)\nAppsflyerSteamModule afm = new AppsflyerSteamModule(DEV_KEY, STEAM_APP_ID, this, true);\n\n// for init without reporting steam_uid\nAppsflyerSteamModule afm = new AppsflyerSteamModule(DEV_KEY, STEAM_APP_ID, this, false, false);\n\n```\n\n### Start\n\nThis method sends first open and session requests to AppsFlyer.\n\n**Method signature**\n\n```c#\nvoid Start(bool skipFirst = false)\n```\n\n**Arguments**\n\n- `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](#skipFirstExample)\n\n**Usage**:\n\n```c#\n// without the flag\nafm.Start();\n\n// with the flag\nbool skipFirst = [SOME_CONDITION];\nafm.Start(skipFirst);\n```\n\n### Stop\n\nThis method stops the SDK from functioning and communicating with AppsFlyer servers. It's used when implementing user opt-in/opt-out.\n\n**Method signature**\n\n```c#\nvoid Stop()\n```\n\n**Usage**:\n\n```c#\n// Starting the SDK\nafm.Start();\n// ...\n// Stopping the SDK, preventing further communication with AppsFlyer\nafm.Stop();\n```\n\n### LogEvent\n\nThis method receives an event name and JSON object and sends an in-app event to AppsFlyer.\n\n**Method signature**\n\n```c#\nvoid LogEvent(\n      string event_name,\n      Dictionary\u003cstring, object\u003e event_parameters,\n      Dictionary\u003cstring, object\u003e event_custom_parameters = null\n   )\n```\n\n**Arguments**:\n\n- `string event_name`: the name of the event.\n- `Dictionary\u003cstring, object\u003e event_parameters`: dictionary object which contains the [predefined event parameters](https://dev.appsflyer.com/hc/docs/ctv-log-event-event-parameters).\n- `Dictionary\u003cstring, object\u003e event_custom_parameters`: (non-mandatory): dictionary object which contains the any custom event parameters.\n\n**Usage**:\n\n```c#\n// set event name\nstring event_name = \"af_purchase\";\n// set event values\nDictionary\u003cstring, object\u003e event_parameters = new Dictionary\u003cstring, object\u003e();\nevent_parameters.Add(\"af_currency\", \"USD\");\nevent_parameters.Add(\"af_revenue\", 12.12);\n// send logEvent request\nafm.LogEvent(event_name, event_parameters);\n\n// send logEvent request with custom params\nDictionary\u003cstring, object\u003e event_custom_parameters = new Dictionary\u003cstring, object\u003e();\nevent_custom_parameters.Add(\"goodsName\", \"新人邀约购物日\");\nafm.LogEvent(event_name, event_parameters, event_custom_parameters);\n```\n\n### GetAppsFlyerUID\n\nGet 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.\n\n**Method signature**\n\n```c#\nstring GetAppsFlyerUID()\n```\n\n**Usage**:\n\n```c#\nAppsflyerSteamModule afm = new AppsflyerSteamModule(DEV_KEY, STEAM_APP_ID, this);\nafm.Start();\nstring af_uid = afm.GetAppsFlyerUID();\n```\n\n### SetCustomerUserId\n\nThis 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()`.\nThe customer ID is available in raw data reports and in the postbacks sent via API.\n\n**Method signature**\n\n```c#\nvoid SetCustomerUserId(string cuid)\n```\n\n**Arguments**:\n\n- `string cuid`: Custom user id.\n\n**Usage**:\n\n```c#\nAppsflyerSteamModule afm = new AppsflyerSteamModule(DEV_KEY, STEAM_APP_ID, this);\nafm.SetCustomerUserId(\"15667737-366d-4994-ac8b-653fe6b2be4a\");\nafm.Start();\n```\n\n### SetSharingFilterForPartners\n\nThis 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.\n\n**Method signature**\n\n```c#\npublic void SetSharingFilterForPartners(List\u003cstring\u003e sharingFilter)\n```\n\n**Arguments**:\n\n- `List\u003cstring\u003e sharingFilter`: a list of partners to filter. For example: `new List\u003cstring\u003e() {\"partner1_int\", \"partner2_int\"};`\n\n**Usage**:\n\n```c#\nAppsflyerSteamModule afm = new AppsflyerSteamModule(DEV_KEY, APP_ID, this);\n\n// set the sharing filter\nvar sharingFilter = new List\u003cstring\u003e() {\"partner1_int\", \"partner2_int\"};\nafm.SetSharingFilterForPartners(sharingFilter);\n\n// start the SDK (send firstopen/session request)\nafm.Start();\n```\n\n### IsInstallOlderThanDate\n\nThis 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\"\n\n**Method signature**\n\n```c#\nbool IsInstallOlderThanDate(string datestring)\n```\n\n**Arguments**:\n\n- `string datestring`: Date string in `yyyy-mm-ddThh:mm:ss+hh:mm` format.\n\n**Usage**:\n\n\u003cdiv id=\"skipFirstExample\"\u003e\u003c/div\u003e\n\n```c#\n// the creation date in this example is \"2023-03-23T08:30:00+00:00\"\nbool newerDate = afm.IsInstallOlderThanDate(\"2023-06-13T10:00:00+00:00\");\nbool olderDate = afm.IsInstallOlderThanDate(\"2023-02-11T10:00:00+00:00\");\n\n// will return true\nDebug.Log(\"newerDate:\" + (newerDate ? \"true\" : \"false\"));\n// will return false\nDebug.Log(\"olderDate:\" + (olderDate ? \"true\" : \"false\"));\n\n// example usage with skipFirst -\n// skipping if the install date is NOT older than the given date\nbool IsInstallOlderThanDate = afm.IsInstallOlderThanDate(\"2023-02-11T10:00:00+00:00\");\nafm.Start(!IsInstallOlderThanDate);\n```\n\n## Running the sample app\n\n1. Open Unity hub and open the project.\n2. Add Steamworks to your Unity project. Follow the [Steamworks SDK instructions](https://steamworks.github.io/) and add it through your package manager.\n3. Use the sample code in `SteamScript.cs` and update it with your `DEV_KEY` and `APP_ID`.\n4. Add the `SteamManager` and `SteamScript` to an empty game object (or use the one in the scenes folder).  \n   ![Request-OK](https://files.readme.io/7a002a6-small-SteamGameObject.PNG)\n5. Launch the sample app via the Unity editor and check that your debug log shows the following message:  \n   ![Request-OK](https://files.readme.io/1f7dcf0-small-202OK.PNG)\n6. After 24 hours, the dashboard updates and shows organic and non-organic installs and in-app events.\n\n## Implementing AppsFlyer in your Steam game\n\n1. Add Steamworks to your Unity project. Follow the [Steamworks SDK instructions](https://steamworks.github.io/) and add it through your package manager.\n2. Add `SteamManager.cs` to a game object.\n3. Add the script from `Assets/Scenes/AppsflyerSteamModule.cs` to your app.\n4. Use the sample code in `Assets/Scenes/SteamScript.cs` and update it with your `DEV_KEY` and `APP_ID`.\n5. Initialize the SDK.\n\n```c#\nAppsflyerSteamModule afm = new AppsflyerSteamModule(DEV_KEY, STEAM_APP_ID, this);\n```\n\n6. [Start](#start) the AppsFlyer integration.\n7. Report [in-app events](#logevent).\n\n## Deleting Steam cloud saves (resetting the attribution)\n\n1. [Disable Steam cloud](https://help.steampowered.com/en/faqs/view/68D2-35AB-09A9-7678#enabling).\n2. [Delete the local files](https://help.steampowered.com/en/faqs/view/68D2-35AB-09A9-7678#where).\n3. [Delete the PlayerPrefs data the registry/preferences folder](https://docs.unity3d.com/ScriptReference/PlayerPrefs.html), or use [PlayerPrefs.DeleteAll()](https://docs.unity3d.com/2020.1/Documentation/ScriptReference/PlayerPrefs.DeleteAll.html) when testing the attribution in the UnityEditor.\n   ![AF guid \u0026 counter in the Windows Registry](https://files.readme.io/51b1681-image.png)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fappsflyersdk%2Fappsflyer-unity-steam-sample-app","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fappsflyersdk%2Fappsflyer-unity-steam-sample-app","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fappsflyersdk%2Fappsflyer-unity-steam-sample-app/lists"}