Unity App Integration¶
Collect metric data from Unity apps to analyze app performance visually.
Reading Path¶
- First-time integration: first choose an access method; for manual integration, see Quick Start
- Complete integration: continue reading this document
- Parameter details: see SDK Initialization, RUM Configuration, Log Configuration, and Trace Configuration
- Custom capabilities: see Custom Tag Usage, RUM Manual Tracking, and Data Collection Masking
- Advanced scenarios: see Native and Unity Hybrid Development
- Troubleshooting: see Troubleshooting
Prerequisites¶
Note
If the RUM Headless service is enabled, the prerequisites are configured automatically, and you can integrate the app directly.
When using a local environment deployment, complete the following data receiver configuration. When using the public DataWay, you do not need to deploy DataKit yourself.
- Install DataKit
- Configure the RUM collector
- Configure DataKit to be publicly accessible and install the IP geolocation database
App Integration¶
- Go to RUM > Create App > Android/iOS
- Create two apps, one for Unity Android and one for Unity iOS, so that RUM data from the Android and iOS platforms is received separately
- For the app for each platform, enter the corresponding app name and app ID
- In "Choose an Access Method", select Agent Auto Integration or Manual Integration, and then complete "Integration Configuration".
Choose an Access Method¶
On the app configuration page, select "Agent Auto Integration" or "Manual Integration", and then complete "Integration Configuration". For an existing app, you can go directly to the configuration page to continue the integration.
| Access Method | Use Cases | Entry Point |
|---|---|---|
| Agent Auto Integration | Want a coding assistant to analyze the project and complete SDK integration | Copy the prompt generated in the console and give it to the coding assistant in the app code repository for execution |
| Manual Integration | Want to install the SDK and configure parameters yourself | Confirm the data reporting method, then complete configuration according to this document and the Quick Start |
Agent Auto Integration¶
- On the current app's configuration page, select "Agent Auto Integration".
- Copy the complete prompt from "Integration Configuration", and make sure it uses the current app's integration information.
- Open the coding assistant in the app code repository, paste the prompt, and let the Agent analyze the project and complete the SDK configuration according to the integration guide.
- Build and run the app, trigger operations such as page views, and verify in the current app's Explorer that data is received.
When using a cross-platform framework, tell the Agent the framework and target platforms, and provide the app information for each platform separately.
If the page indicates that your personal API Key or temporary authorization code is not ready, complete it as prompted, and then copy the prompt again.
Manual Integration¶
On the app configuration page, select "Manual Integration" and confirm the data reporting method:
- Public DataWay: Receives RUM data directly; no need to install the DataKit collector
- Local environment deployment: Receives RUM data after the prerequisites are met
Complete SDK installation, initialization, and verification according to Installation and Quick Start below. If an SDK configuration already exists, check and reuse it first to avoid duplicate initialization.
Installation¶
Source Code: https://github.com/GuanceCloud/datakit-unity
Demo: https://github.com/GuanceCloud/datakit-unity/blob/dev/Assets/Scenes
- Download the latest ft-sdk-unity.unitypackage
- Import
ft-sdk-unity.unitypackageviaAssets->Import Package->Custom Package... - Add the third-party JSON parsing library
"com.unity.nuget.newtonsoft-json"; you can do this inPackage Manager->Add Package by name ... - Drag
FTSDK.prefabto the first scene page, and initialize the SDK in the_InitSDKmethod inFTSDK.cs - Drag
FTViewObserver.prefabto other scene pages to monitor the pageViewlifecycle and app sleep and wake-up - Use
Application.logMessageReceivedto listen for and convert Unity crash data and regular log data. For examples, see Quick Start and RUM Manual Tracking
Assets/Plugins
├── Android
│ ├── FTUnityBridge.java // Android bridge
│ ├── InnerClassProxy.java // Android Inner Setting Proxy
│ ├── ft-sdk-release.aar // Android SDK
│ ├── gson-2.8.5.jar // Android SDK third-party dependency
├── iOS
│ ├── FTMobileSDK.xcframework // iOS SDK
│ ├── FTUnityBridge.mm // iOS bridge
├── FTSDK.cs // FTSDK.prefab binding script
├── FTSDK.prefab // SDK initialization prefab
├── FTUnityBridge.cs // Unity bridge for methods on iOS, Android, and other platforms
├── FTViewObserver.cs // FTViewObserver.prefab binding script
├── FTViewObserver.prefab // View page monitoring prefab
├── UnityMainThreadDispatcher.cs // UnityMainThreadDispatcher.prefab binding script
├── UnityMainThreadDispatcher.prefab // Main-thread consumption queue prefab
- If the native Android and iOS projects have already integrated the native SDK, comment out the
_InitSDKmethod to avoid duplicate setup. For specific scenarios, see Native and Unity Hybrid Development - iOS Plugin Inspector Settings:
FTMobileSDK.xcframeworkis a dynamic library, so you need to selectAdd to Embedded Binaries. After you select this option, Unity sets the Xcode project options so that the plugin files are copied to the final app bundle.
If the native SDK has already been integrated,
gson-2.8.5.jarandft-sdk-release.aarfor Android, andFTMobileSDK.frameworkfor iOS, can be removed from the Unity project.
The OkHttp request and startup time features on Android need to be used withft-plugin. For detailed configuration, see Android SDK.
Initialization¶
For a minimal initialization example, see Quick Start.
For complete SDKConfig parameter descriptions, see SDK Initialization.
Detailed Configuration¶
Advanced Scenarios¶
FAQ¶
Add Global Variables to Avoid Field Conflicts¶
To avoid conflicts between custom fields and SDK data, we recommend prefixing tag names with the project abbreviation, for example, custom_tag_name. You can check the source code for the key values used in the project. If an SDK global variable has the same name as a RUM or Log variable, RUM or Log overrides the SDK global variable.
