1. Integrated Sensors analytics SDK

1.1. Import SDK

  • From GitHub mp-feishu directory to obtain small program SDK source code;
  • Put index.esm.js file into the small program project;
  • In app.js file use import SDK.
import sensors from '/dist/mp-feishu/index.esm';
JS

1.2. Initialize SDK

Can call init() method to initialize SDK

sensors.init({ 	name: 'sensors', 	server_url: '您的数据接收地址', 	// 全埋点控制开关 	autoTrack: {}, 	// 自定义渠道追踪参数,如source_channel: ["custom_param"] 	source_channel: [], 	// 是否允许控制台打印查看埋点数据(建议开启查看) 	show_log: true });
JS

2. SDK Basic configuration

2.1. The IP address for receiving project data was configured

Sensors Analytics v2.2 can obtain the data receiving address as shown in the following figure, other versions can obtain the data receiving address, you can switch the document version to view:

After obtaining the data receiving address setPara Interface Settings server_urlserver_url The domain name needs to follow the requirements of the Bytedance applet(https://microapp.bytedance.com/docs/zh-CN/mini-app/develop/guide/basic-ability/network)The request legal domain name of the applet was configured.

2.2. Open the full burial point

autoTrack It can be used to configure the type of full burial point to be enabled:

sensors.setPara({ 	autoTrack:{ 		appLaunch: true, // 默认为 true,false 则关闭 $MPLaunch 事件采集 		appShow: true, // 默认为 true,false 则关闭 $MPShow 事件采集 		appHide: true, // 默认为 true,false 则关闭 $MPHide 事件采集 		pageShow: true, // 默认为 true,false 则关闭 $MPViewScreen 事件采集 		mpClick: true // 默认为 true,false 则关闭 $MPClick 事件采集 	} 	/** 	 * 其他配置 	 */ });
JS


2.3. Set the event public properties

Attributes that need to be added for all events can be called before initializing the SDK registerApp() Register the property as a public property:

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

2.4. User Login

When a user successfully registers or logs in, the login() method needs to be called to pass the login ID:

sensors.login("登录 ID");
JS
  • For users who enable automatic login, the login ID can be obtained and the login() method can be called before SDK initialization.

2.5. Code Point Tracking Event

After SDK initialization, user behavior events can be traced using the track() method, and custom properties can be added to the events:

sensors.track(event_name [,properties]);
JS

Configuration parameters:

ParameterRequiredDescription
event_nameYesEvent name
propertiesNoAdd custom properties to the user behavior event, type: Object.

Example:

// 为 click 事件添加自定义属性 name 值为点击。 getApp().sensors.track('click',{ 	name: '点击' }); 
JS

For the format specification of event names and event properties, please refer to Data Format.

3. Debugging and viewing event information

3.1. Event trigger logs

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

3.2. Event Delivery Status

When the event data is successfully sent, you can view the "sa" request in the "Network" module of the ByteDance Developer Tool:

4. Optional SDK Configurations

4.1. Set User Properties

setProfile(properties): can set user properties. When the same key is set multiple times, the value will be overwritten:

sensors.setProfile({ 	email:'xxx@xx', 	favoriteFruits: ['苹果', '油桃'], 	subscribers: 7277 });
JS
  • For the difference between event properties and user properties, please refer to the Data Model.
  • For the naming conventions of user properties, please refer to the Data Formats.
  • For other methods of setting user properties, please refer to Setting User Properties.

4.2. Channel Tracking

  1. When users access the mini-program through paths containing utm parameters, the preset events $MPLaunch and $MPShow will parse the utm parameters in the launch path as their own properties and values. The $latest_utm related properties will be set for all events. This feature is valid throughout the life cycle of the mini-program.
  2. Support Custom Channel Tracking