The sa-sdk-mini-game repository layaair-game.min.js is now suspended.

1. Platform Support

PlatformWeChat Mini GameQQ Mini GameByteDance Mini GameH5iOSAndroid
Support

(滴答)

(滴答)

(滴答)

(滴答)

(滴答)

(滴答)

2. Integrate Sensors Analytics SDK

Get the GitHub dist directory of LayaAir SDK from

If your project is a TypeScript project, follow these steps:

  • Modify the tsconfig.json file and add "allowJs": true to allow compilation of js files.
"compilerOptions": { "module": "es6", "target": "es6", "baseUrl": "../libs", "outDir": "../build/src", "allowJs": true, //指定允许编译JS文件 }
CODE
  • Laya 3.0 puts the SDK files into the assets directory,Referenced in source code.
  • Laya 2.0 places the SDK files in the src directory,Referenced in source code.
//3.0 引入方式 import sensorsData from "../assets/js/sensors-laya.min.esm.js"; //2.0 引入方式 import sensorsData from "./sensors-laya.min.esm.js";
CODE

If your project is a JavaScript project, follow these steps:

  • Directly place the sensors-laya.min.esm.js file into your project and reference it in the source code:
import sensorsData from "./sensors-laya.min.esm.js";
CODE


3. Initialization

After importing the SDK, use the sensorsData call the init() method to initialize the SDK:

//配置对象 var config = { server_url: '数据上报 URL', // 数据上报 URL,必需 show_log: true, super_properties: { superKey: 'value' }, mini: { app_show: false, //默认 false, 小游戏从后台进入前台。 app_hide: false //默认 false, 小游戏从前台进入后台。 }, app: { app_start: true, //默认 false 启动 app_end: true //默认false 关闭 } 	} //初始化 sensorsData.init(config); // 上报一个事件,事件名为 test sensorsData.track( 	'test', // 事件名称 	{ demo:1 }// 事件属性 );
JS

3.1.1. The parameter is described as follows:

ParameterTypeRequiredDefaultMeaningRemarks
server_urlStringYesData Receiving URLData Receiving URL
super_propertiesObjectNoNoneSet Public Static Property


show_logBooleanNofalseWhether to print log
  • Setting it to true will print log in the emulator console, showing the data being sent. Setting it to false means no display. It is recommended to enable it.
miniObjectNo

No

Enable Automatic Collection
  • Indicates whether to enable automatic collection of mini-games. All are turned off by default.
  • 2 attribute parameters (app_showandapp_hide) are used to collect $MPShow and $MPHide events, respectively.

Note: H5 platform does not support full-page tracking.

appObjectNoNoEnable Automatic Collection
  • Indicates whether to enable automatic collection of Native. All are turned off by default.
  • 2 attribute parameters (app_startandapp_end) are used to collect $AppStart and $AppEnd events, respectively.

When publishing as WeChat/QQ/ByteDance mini-games, you need to configure the domain of the data receiving address on the corresponding developer platform.

4. SDK Basic Configuration

4.1. Configure Project Data Receiving Address

For Sensible Analytics v2.2 or above, you can obtain the data receiving address as shown in the following figure. For obtaining data receiving address in other versions, switch the document version for viewing:

5. Debugging Displays event information

5.1. Event triggering logs

When configuring initialization parameters, use  show_log: true to enable the Log function and after the SDK is initialized (i.e.,  init() method is called), the developer console  will print the collected data information.

5.2. Event sending situation

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