Menu

Integration Documentation (Egret SDK)

Integrate Sensors Analytics SDK

Introduce SDK

  • Get the SDK source code from GitHub
  • Put the SDK (egret-game.min.js) file into the project directory
  • Open the mini game project with an editor, and import the SDK file in the Main.ts file under the src directory
import sensors from './build/egret-game.min.js'

Configure initialization parameters

  • After importing the SDK, you can configure SDK initialization parameters with the setPara() function
sensors.setPara({ 	server_url: '您的数据接收地址', 	// 是否允许控制台打印查看埋点数据(建议开启查看) 	show_log: true, });

Optional initialization parameters

Configuration Name

Default Value

Meaning

server_urlEmpty stringData receiving URL
show_logfalseWhether to display log information

batch_send.send_timeout

6000Send data every 6000 milliseconds

batch_send.max_length

6Send data when there are 6 stored entries

max_string_length

500Maximum length of string attribute values is 500, exceeding length will be truncated

Initialize SDK

  • Call the init() method to initialize the SDK:
// 引入 SDK import sensors from './build/egret-game.min.js' // 配置 SDK 参数 sensors.setPara({ 	server_url: '您的数据接收地址', 	// 是否允许控制台打印查看埋点数据(建议开启查看) 	show_log: true, }); class Main{ 	constructor(){ 		... 		// 初始化 SDK, 建议将 sensors.init() 调用放在 Main 的构造函数最底部执行,保证 Egret 初始化完成后再初始化神策 Egret SDK 		sensors.init(); 	} 	 }


  • Before calling the init() interface, the collected data is cached in memory; after calling the init() interface, the cached data will be sent over the network.

SDK Basic Configuration

Configure project data receiving URL

For Sensing Analytics v2.2 and above, data receiving URL can be obtained as shown in the following figure. For other versions, switch the document version to view how to obtain data receiving URL:


Set Event Common Properties

For properties that need to be added for all events, you can register them as public properties by calling registerApp() before initializing the SDK:

sensors.registerApp({ 	userLever: 'VIP3', 	userSex: '男' });

User Login

When a user registers or logs in successfully, you need to call the login() method and pass in the login ID:

sensors.login("登录 ID");

For users who are automatically logged in, you can get the login ID and call the login() method before initializing the SDK.

Code tracing events

You can track user behavior events and add custom properties to events using the track() method:

import sensors from './sensorsdata.min.js' sensors.track('click',{ 	name: '点击' }); 

Debugging and viewing event information

Event trigger logs

When configuring initialization parameters with setPara(), open the Log feature by setting show_log: true, and after the SDK completes initialization (i.e., after the init() method is called), the developer tool console will print the collected data information:


Event sending status

When an event data is successfully sent, you can see the sa request in the Network module of the developer tool:

Optional SDK configurations

Set user properties

The setProfile(properties): method can set user properties, and when the same key is set multiple times, the value will be overwritten:

sensors.setProfile({ 	email:'xxx@xx', 	favoriteFruits: ['苹果', '油桃'], 	subscribers: 7277 });
  • For the difference between event properties and user properties, see Data model
  • For naming restrictions on user attributes, see Data format


Previous
Egret SDK
Next
LayaAir SDK
Last modified: 2024-12-27