Meta Quest 2 Unity
Link to repository
GitHub
AppsFlyer Meta Quest Unity 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 Meta Quest game.
Điều kiện tiên quyết
- Unity 2021.3.16f1
- The Oculus SDK - follow the Oculus SDK for Unity integration guide.
- Oculus Quest 2 Headset
AppsflyerModule - Interface
AppsflyerModule.cs
, included in the scenes folder, contains the required code and logic to connect to AppsFlyer servers and report events.
AppsflyerModule
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.
Chữ ký phương thức
AppsflyerModule(string devkey, string appid, MonoBehaviour mono, bool isSandbox = false)
Usage:
// for regular init
AppsflyerModule afm = new AppsflyerModule(<< DEV_KEY >>, << QUEST_APP_ID >>, this);
// for init in sandbox mode (reports the events to the sandbox endpoint)
AppsflyerModule afm = new AppsflyerModule(<< DEV_KEY >>, << QUEST_APP_ID >>, this, true);
Arguments:
DEV_KEY
: Get from the marketer or AppsFlyer HQ.QUEST_APP_ID
: Your Quest Store app ID (For Quest 2, it's the number in the store URL - for example: https://www.oculus.com/experiences/quest/XXXXXXXXXXXXXXXX/).
Start
This method sends first open/session requests to AppsFlyer.
Chữ ký phương thức
void Start(bool skipFirst = false)
Usage:
// without the flag
afm.Start();
// with the flag
bool skipFirst = [SOME_CONDITION];
afm.Start(skipFirst);
LogEvent
This method receives an event name and JSON object and sends an in-app event to AppsFlyer.
Chữ ký phương thức
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);
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-01T23:12:34+00:00"
Chữ ký phương thức
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);
GetAppsFlyerUID
Nhận ID thiết bị duy nhất của AppsFlyer. SDK sẽ tạo ra một ID thiết bị duy nhất của AppsFlyer khi cài đặt ứng dụng. Khi SDK khởi động, ID này sẽ được ghi nhận là ID của lượt cài đặt ứng dụng đầu tiên.
Chữ ký phương thức
void GetAppsFlyerUID()
Usage:
AppsflyerModule afm = new AppsflyerModule(<< DEV_KEY >>, << QUEST_APP_ID >>, this);
afm.Start();
string af_uid = afm.GetAppsFlyerUID();
Running the sample app
- Open Unity hub and open the project.
- Use the sample code in AppsflyerScript.cs and update it with your DEV_KEY and QUEST_APP_ID.
- Add the AppsflyerScript 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 AppsFlyer dashboard updates and shows organic and non-organic installs and in-app events.
Implementing AppsFlyer in your Meta Quest game
Setup
- Add the script from
Assets/AppsflyerModule.cs
to your app. - Use the sample code in
Assets/AppsflyerScript.cs
and update it with yourDEV_KEY
andQUEST_APP_ID
. - Initialize the SDK.
AppsflyerModule afm = new AppsflyerModule(<< DEV_KEY >>, << QUEST_APP_ID >>, this);
- Start the AppsFlyer integration.
- Report in-app events.
Resetting the attribution
Delete the PlayerPrefs data the registry/preferences folder, or use PlayerPrefs.DeleteAll() when testing the attribution in the UnityEditor.
Đã cập nhật khoảng 1 tháng trước