Quick Start¶
This article provides the shortest integration path for the Cocos Creator SDK, helping you complete verifiable RUM, Log, and Trace data reporting.
The examples on this page use the current SDK version combination.
Prerequisites¶
- Create an Android and an iOS app in Real User Monitoring (RUM) respectively, and obtain the two App IDs.
-
Prepare one data reporting method:
-
Local environment deployment: prepare
datakitUrl. -
Public DataWay: prepare
datawayUrlandclientToken. -
Install
@cloudcare/cocos-sdkand run the project installer. For detailed steps, see App Access. - Reopen Cocos Creator and generate the Android or iOS native project.
- For an iOS project using CocoaPods, enter the directory where the
Podfileis located and runpod install, then open the.xcworkspace.When using SPM, configure as described in iOS Native Build and compile; there is no need to install Pods for a brand-new project.
The following minimal example uses only the base package. If Session Replay is needed, first install the standalone package with the Replay installation 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 @cloudcare/cocos-sdk/creator2.
import { guanceSdk } from '@cloudcare/cocos-sdk/creator3';
export function startObservability(): void {
guanceSdk.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 data collection is loaded, and make sure it is initialized only once throughout the entire application lifecycle.
If the main body of the app is Android/iOS native pages and only one or a few pages use Cocos, do not call guanceSdk.start() again. In this scenario, the native host should complete 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,
},
Choose either datakitUrl or datawayUrl; when using datawayUrl, you must also pass clientToken.
Print a Custom Log¶
Call the following after initialization:
Verify Integration¶
- Run the app with an Android or iOS native build. Browser preview does not report data.
- Switch scenes, trigger a touch action, and make 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)
- Using Cocos in part of a native App: Native and Cocos Hybrid Development
- Manual instrumentation: RUM Manual Instrumentation
- No data or build failures: Troubleshooting