QQ Mini Program SDK
|
Collect
- Before using, please read the Data model
- Refer to the SDK changelog for updates, please see the Release Notes.
- Currently does not support the development of uni-app mini-programuni-appframework.
The sa-sdk-mini repository has added full tracking of page leave behavior, and the deprecated sa.getPresetProperties and sa.getAnonymousID APIs have been removed.
sa-sdk-qqmini 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. Add SDK
- From GitHub mp-qq get the source code for QQ Mini Program SDK.
- Place the index.esm.js file into the mini program project;
- In the app.js file, import the SDK using the require() function.
import sensors from './dist/mp-qq/index.esm';
1.2. Initialize the SDK
Call theinit() method to initialize the SDK.
sensors.init({ name: 'sensors', server_url: '您的数据接收地址', // 全埋点控制开关 autoTrack: {}, // 自定义渠道追踪参数,如source_channel: ["custom_param"] source_channel: [], // 是否允许控制台打印查看埋点数据(建议开启查看) show_log: true });
2. SDK basic configuration
2.1. Configure the project data receiving URL
Obtain the data receiving URL as shown in the figure below:
After obtaining the Data Receiving URL, set the server_url in the setPara interface. The domain name of server_url should be configured according to the requirements of QQ Mini Program (https://q.qq.com/wiki/develop/game/API/MGOBE/SDK.html#%E8%AE%BE%E7%BD%AE%E8%AF%B7%E6%B1%82%E5%9F%9F%E5%90%8D) to configure the Mini Program server domain name.
2.2. Enable full point burial
In the init() function, in the autoTrack method, configure the types of full point burial 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 // 默认为 false,true 则开启 $MPClick 事件采集 } /** * 其他配置 */ });
- The timing of full point burial collection can refer to the full point burial collection logic
- iOS version of QQ, $MPHide event data sending may result in data loss.
2.3. Set event common attributes
In order to add attributes to all events, you can call registerApp() before initializing the SDK to register attributes as common attributes:
sensors.registerApp({ userLever: 'VIP3', userSex: '男' });
2.4. User login
When the 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 automatically log in, you can obtain the login ID and call the login() method before initializing the SDK.
2.5. Code Point Tracking
After initializing the SDK, you can use the track() method to track user behavior events and add custom attributes to the events:
sensors.track(event_name [,properties]);
Configure parameters:
Parameter | Required | Description |
---|---|---|
event_name | True | Event name |
properties | false | Add custom properties to user behavior events, type: Object. |
Example:
// 为 click 事件添加自定义属性 name 值为点击。 sensors.track('click',{ name: '点击' });
Event Name and Event Property format standards, please refer toData format。
3. Debugging and viewing event information
3.1. Logs of triggered events
setPara() When configuring initialization parameters, you can open the Log function by setting show_log: true and after the SDK initialization is complete (i.e., after the init() method is called), the WeChat developer tool console will print the collected data information.
3.2. Sending status of events
When event data is sent successfully, you can see the request for sa in the Network module of the WeChat developer tool:
4. Optional SDK configurations
4.1. Setting user properties
setProfile( properties ): You 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 });
- 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 to用户属性设置
4.2. Channel tracking
When a user accesses the Mini Program through a path that includes related utm parameters, the preset events $MPLaunch, $MPShow, $MPViewScreen will parse the utm-related parameters in the launch path as their own attributes and attribute values, and will set the related $latest_utm properties to all events. This feature is valid throughout the lifecycle of the Mini Program.
Note: The content of this document is a technical document that provides details on how to use the Sensors product and does not include sales terms; the specific content of enterprise procurement products and technical services shall be subject to the commercial procurement contract.