• Please read the data model before use.
  • SDK update log, please refer to the Release Notes.

1. Integrate Sensors Analytics SDK

1.1. Introduce SDK

  • Get the source code of Kuaishou Mini Program SDK from GitHub.
  • Place the kuaishou-mp.min.js file into the Mini Program project.
  • In the app.js file, import and initialize the SDK by import method.
import sensors from './utils/kuaishou-mp.min.js'; // 可通过 setPara() 进行 SDK 初始化参数配置: sensors.setPara({ 	server_url: '您的数据接收地址', 	// 是否允许控制台打印查看埋点数据(建议开启查看) 	show_log: true }); // 初始化 SDK sensors.init(); App({ 	onLaunch: function(){ 	 	}, 	onShow: function(){ 	} });
JS
  • The compressed file size of Kuaishou Mini Program SDK is about 17 KB.
  • Call setPara() and init() before instantiating the App, otherwise some pre-set events may be lost.
  • Before calling the init() interface, the collected data is cached in memory; after calling the init() interface, the cached data will be sent through the network.

2. SDK basic configuration

2.1. Configure the data receiving URL

Get the data receiving URL as shown in the figure below:

2.2. Set event common properties

To add properties that need to be added to all events, call registerApp() to register the properties as common properties before initializing the SDK.

// 在需要使用 SDK 接口的页面逻辑文件中,需要通过 import 将 SDK 引入,再调用相应接口 import sensors from '../../utils/kuaishou-mp.min.js' sensors.registerApp({ 	userLever: 'VIP3', 	userSex: '男' });
JS

2.3. User login

When the user successfully registers or logs in, call the login() method to pass the login ID.

// 在需要使用 SDK 接口的页面逻辑文件中,需要通过 import 将 SDK 引入,再调用相应接口 import sensors from '../../utils/kuaishou-mp.min.js' sensors.login("登录 ID");
JS
  • For automatically logged-in users, you can get the login ID and call the login() method before SDK initialization.

2.4. Code tracking event

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

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

Configuration parameters:

ParameterRequiredDescription
event_nameYesEvent name
propertiesNoAdds custom properties to user behavior events, type: Object.

Example:

// 为 pageview 事件添加自定义属性 title 值为首页。 // 在需要使用 SDK 接口的页面逻辑文件中,需要通过 import 将 SDK 引入,再调用相应接口 import sensors from '../../utils/kuaishou-mp.min.js' Page({ 	onShow: function(){ 		sensors.track('pageview',{ 			title: '首页' 		}); 	} }); 
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 triggering logs

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

3.2. Event sending status

When event data is successfully sent, you can view the request to sa in the Network module of the quickapp 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 and replaced:

// 在需要使用 SDK 接口的页面逻辑文件中,需要通过 import 将 SDK 引入,再调用相应接口 import sensors from '../../utils/kuaishou-mp.min.js' sensors.setProfile({ 	email:'xxx@xx', 	favoriteFruits: ['苹果', '油桃'], 	subscribers: 7277 });
JS
  • The difference between event properties and user properties, please refer to Data Model
  • For naming constraints of user properties, please refer to Data Format
  • Other methods for setting user properties, please refer to User Property Settings