The Alipay Mini Program SDK is compatible with DingTalk Mini Programs starting from version v1.1.8.
The sa-sdk-alipaymini repository has been upgraded to the sa-sdk-mini repository for unified code iteration and management.
- The sa-sdk-mini repository supports ID3 universal user association, and sa.appLaunch, sa.appShow, sa.appHide, sa.pageShow, sa.pageLoad API have been taken offline.
- sa-sdk-alipaymini repositoryNo longer updated or maintained, if you need to use the old version SDK, pleaseGo to the old version SDK。
1. Integrate Sensors Analytics SDK
1.1. Introduce SDK
- FromGitHub get the source code for Alipay Mini Program SDK.
- Place the index.esm.js file into the Mini Program project;
- In the app.js file, import the SDK using import.
// 此处 index.esm.js 文件路径需要根据项目实际情况设置 import sensors from 'index.min.js' sensors.setPara({ name: 'sensors', server_url: '数据接收地址', }) sensors.init();
JS
1.2. Set initialization parameters and enable full tracking
// 此处 index.esm.js 文件路径需要根据项目实际情况设置 import sensors from 'index.esm.js' sensors.setPara({ name: 'sensors', server_url: '数据接收地址', // 预置事件采集配置开关,默认为 true autoTrack:{ appLaunch: true, //是否采集 $MPLaunch 事件,true 代表采集,false 不采集。 appShow: true, //是否采集 $MPShow 事件,true 代表采集,false 不采集。 appHide: true, //是否采集 $MPHide 事件,true 代表采集,false 不采集。 pageShow: true, //是否采集 $MPViewScreen 事件,true 代表采集,false 不采集。 mpClick: true //是否采集 $MPClick 事件,true 代表采集,false 不采集。 } })
JS
If you are developing a Mini Program using the Taro framework, you need to configure the framework parameter in sensors.setPara: sensors.setPara({ framework: {taro: Taro} })
1.3. Initialize the SDK
// 此处 index.esm.js 文件路径需要根据项目实际情况设置 import sensors from 'index.esm.js' sensors.setPara({ name: 'sensors', server_url: '数据接收地址', // 预置事件采集配置开关,默认为 true autoTrack:{ appLaunch: true, //是否采集 $MPLaunch 事件,true 代表采集,false 不采集。 appShow: true, //是否采集 $MPShow 事件,true 代表采集,false 不采集。 appHide: true, //是否采集 $MPHide 事件,true 代表采集,false 不采集。 pageShow: true, //是否采集 $MPViewScreen 事件,true 代表采集,false 不采集。 mpClick: true //是否采集 $MPClick 事件,true 代表采集,false 不采集。 } }) sensors.init();
JS
- Detailed initialization configuration parameters can be referred toMini Program SDK API Documentation
- It is recommended to immediately call setPara() to configure the initialization parameters after importing the SDK to prevent delayed configuration from causing the element click event handling function to not be delegated and the pre-set element click event from being collected;
- 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.
2. SDK Basic Configuration
Get the data receiving address as shown in the following figure:
![](/sa/files/latest/en/1573896/150667720/1/1698830780000/%E6%95%B0%E6%8D%AE%E6%8E%A5%E5%85%A5.png)
2.2. Set event common attributes
For attributes that need to be added to all events, you can call registerApp() to register the attributes as common attributes
sensors.registerApp({ userLever: 'VIP3', userSex: '男' });
JS
You need to call registerApp() method before App instantiation to complete the registration of common attributes, otherwise, some collected data will not have registered common attributes
2.3. User association
User association is to uniquely identify users and improve the accuracy of user behavior analysis. Currently, Sensors Analytics provides simple user association and global user association to support different business scenarios.
2.4. Tracking events with code-based tracking
After SDK initialization, you can track user behavior events through the track() method and add custom properties to the events:
sensors.track(event_name [,properties]);
JS
Configuration parameters:
Parameter | Required | Description |
---|
event_name | True | Event name |
properties | false | Add custom properties to user behavior events, type: Object. |
For example:
// 为 click 事件添加自定义属性 name 值为点击。 sensors.track('click',{ name: '点击' });
JS
Event Name and Event Property format standards, please refer to the "Metric" and "Attribute"Data format.
3.1. Event Trigger Logs
setPara() When configuring the initial parameters, use the "Configure" function.show_log: true Open Log Function (enabled by default) and SDK initialization completed (i.e.init() After the API call, the Mini Program Developer Tool. console Prints the collected data information:
![](/sa/files/latest/en/1573896/95978120/1/1590398043000/image2020-5-25_17-14-2.png)
3.2. Event sending status
When event data is successfully sent, you can see the sa request in the module of the mini program developer tool.
![](/sa/files/latest/en/1573896/95978121/1/1590398452000/image2020-5-25_17-20-51.png)
4. SDK optional configuration
4.1. User attributes can be set.
setProfile( properties ): When the same key is set multiple times, the value will be overwritten and replaced.
sensors.setProfile({ email:'xxx@xx', favoriteFruits: ['苹果', '油桃'], subscribers: 7277 });
JS
- Regarding the difference between event properties and user properties, please refer toData model
- User attribute naming constraints, please refer toData format
- User Attribute Other Setting Methods, please refer toUser Attribute Set
4.2. Channel Track
- When users access mini-programs through paths containing UTM parameters, the preset events will $MPLaunch、$MPShow parse the relevant parameters in the launch path utm as their own attributes and attribute values, and set the corresponding attributes$latest_utm for all events. This feature is effective throughout the lifecycle of the mini-program.
- The Alipay mini-program SDK supports parsing custom parameters, custom parameters outside ofutm_*
5. SDK API
For more mini-program APIs, please refer to theSDK API (mini-program)