Quick Start¶
This article provides the shortest integration path for the Cocos Creator SDK, helping you complete verifiable reporting of RUM, Log, and Trace data.
Before integration, confirm that the installed npm package and native dependencies meet the SDK Version and Dependency Requirements.
Prerequisites¶
- In Real User Monitoring (RUM), create an Android app and an iOS app separately, and obtain the two App IDs.
-
Prepare a reporting method:
- Local environment deployment: prepare
datakitUrl. - Public DataWay: prepare
datawayUrlandclientToken.
- Local environment deployment: prepare
-
Install
@truewatchtech/cocos-sdkand run the project installer. For detailed steps, see App Access. - Reopen Cocos Creator and generate an Android or iOS native project.
- For iOS projects using CocoaPods, go to the directory containing the
Podfileand runpod install, then open the.xcworkspace. When using SPM, configure it as described in iOS Native Build and compile; there is no need to install Pods for a new project.
The following minimal example uses only the base package. If you need Session Replay, first install the standalone package according to Replay Install Options and run --replay, then initialize with the combined SDK instance.
Minimal Initialization¶
The following example uses Creator 3. For Creator 2, simply change the import entry to @truewatchtech/cocos-sdk/creator2.
import { truewatchSdk } from '@truewatchtech/cocos-sdk/creator3';
export function startObservability(): void {
truewatchSdk.start({
sdk: {
datakitUrl: 'https://your-datakit.example.com',
serviceName: 'cocos-game',
env: 'prod',
debug: true,
},
rum: {
androidAppId: 'android-rum-app-id',
iosAppId: 'ios-rum-app-id',
sampleRate: 1,
},
logger: {
enableCustomLog: true,
enableLinkRumData: true,
sampleRate: 1,
},
trace: {
traceType: 'ddTrace',
enableLinkRumData: true,
sampleRate: 1,
},
autoTrack: {
scenes: true,
actions: true,
errors: true,
network: true,
},
});
}
Call startObservability() before the first scene that requires collection loads, and ensure that it is initialized only once during the entire app lifecycle.
If the app mainly consists of Android/iOS native pages and only one or a few pages use Cocos, do not call truewatchSdk.start() again. In this scenario, the native host should complete the SDK initialization once, and Cocos should integrate through attach(). For details, see Native and Cocos Hybrid Development.
If you use the public DataWay, change sdk to:
sdk: {
datawayUrl: 'https://open.dataway.url',
clientToken: 'client-token',
serviceName: 'cocos-game',
env: 'prod',
debug: true,
},
Use either datakitUrl or datawayUrl; when using datawayUrl, you must also pass clientToken.
Print a Custom Log¶
After initialization, call:
Verify Integration¶
- Run the app with an Android or iOS native build; browser preview does not report data.
- Switch scenes, trigger a touch operation, and initiate a network request.
- Check the Cocos console and native logs for initialization or Bridge errors.
- Go to RUM > Explorer and select the corresponding Android or iOS app.
- Confirm that View, Action, or Resource data exists, and confirm the custom log in the Log Explorer.
- After verification, disable
debugin the production environment.
Next Steps¶
- Basic parameters and user binding: SDK Initialization
- RUM and automatic collection: RUM Configuration
- Logs: Log Configuration
- Distributed Tracing: Trace Configuration
- Session Replay: Cocos Creator Session Replay (Experimental)
- Native apps partially using Cocos: Native and Cocos Hybrid Development
- Manual collection: RUM Manual Instrumentation
- No data or build failures: Troubleshooting