How does the applet integrate statistics from Youmeng?

WeChat applet SDK integration

Scope of application

This document is applicable to Youmeng + WeChat Mini Program Statistics SDK 2.3.2 and above.

1. Register Umeng + account

Login + Friends of the Union's official website ( www.umeng.com ), according to Friends of the Union registered guide + account
! [AB35B58C-AAE7-4968-BFAB- D69A33CBE887.png] (https://imgconvert.csdnimg.cn/aHR0cHM6Ly9pbnRyYW5ldHByb3h5LmFsaXBheS5jb20vc2t5bGFyay9sYXJrLzAvMjAyMC9wbmcvMjk2NjU4LzE1OTEwNjgwNTM2MDEtN2M2ZDE2YTktN2E4MS00MTVjLWE0MWMtMjFlN2UyNTgwOGEyLnBuZw?x-oss -process=image/format,png#align=left&display=inline&height=365&margin=[object Object]&name=AB35B58C-AAE7-4968-BFAB-D69A33CBE887.png&originHeight=444&originWidth=587&size=14440&status=done&style=none&width=482)
Special reminder: We recommend that developers use corporate email when registering an account, and avoid using personal email to register to prevent problems caused by personal resignation. The recommended account form: umeng@企业域、apps@企业域、dev@企业域

2. Install SDK

npm install umtrack-wx  --save

Note: Please refer to https://developers.weixin.qq.com/miniprogram/dev/devtools/npm.html to use npm in the WeChat Mini Program

3. Integrate SDK

In the app.js file, add the following code to perform basic indicator statistics:**

import 'umtrack-wx';
App({
  umengConfig: {
    appKey: 'YOUR_UMENG_APPKEY', //由友盟分配的APP_KEY
    useOpenid: false, // 是否使用openid进行统计,此项为false时将使用友盟+随机ID进行用户统计。使用openid来统计微信小程序的用户,会使统计的指标更为准确,对系统准确性要求高的应用推荐使用OpenID。
    autoGetOpenid: false, // 是否需要通过友盟后台获取openid,如若需要,请到友盟后台设置appId及secret
    debug: true, //是否打开调试模式
    uploadUserInfo: true // 自动上传用户信息,设为false取消上传,默认为false
  }
});

Note: Remember to set umengConfig correctly, don’t misspell

* Use OpenID (optional)

When useOpenid: true
**Method 1:** Developers need to add additional code to upload openid, otherwise the data will not be reported

// 开启后必须额外添加代码上传OpenID,否则数据不会上报
wx.uma.setOpenid(openid)

parameter:

  • id(string): the user openid obtained by the developer

return value:

  • no

**Method 2: **Enable autoGetOpenid: true and set valid appId and secret information in the Umeng background

App({
  umengConfig: {
    appKey: 'YOUR_UMENG_APPKEY', //由友盟分配的APP_KEY
    useOpenid: true,
    // 授权友盟+通过后台自动获取openid,可防止数据统计过程中因未采集到OpenID而造成
    // 数据丢失的情况。开启后请到友盟+小程序应用设置中添加appId及secret信息
    autoGetOpenid: true
  }

4. Add the whitelist of Umeng + data service domain names

Add the request legal domain name in the WeChat developer background: umini.shujupie.com
Steps: Log in to the WeChat public platform, enter the Mini Program Settings -> Development -> Development Settings -> Server Domain Name, and add umini.shujupie.com to the request legal domain name , As shown in the figure:

![](https://imgconvert.csdnimg.cn/aHR0cHM6Ly95dXF1ZS5hbnRmaW4uY29tL2F0dGFjaG1lbnRzL2xhcmsvMC8yMDIwL3BuZy8yOTY2NTgvMTU5MTI1NDcwMDg2Ni05Y2M3MmNkNS0xZTYxLTQ2MzgtYWZiNS1kOWYwZGM1YTA1YjcucG5n?x-oss-process=image/format,png#align=left&display=inline&height=567&margin=[object Object]&originHeight=567&originWidth=1044&size=0&status=done&style=none&width=1044)

5. Apply for Appkey

After the service provider obtains the applet APPID, order number, and authorization code, the service provider can apply for Umeng + APPkey through OpenAPI and return it to the SDK.

API test tool, please click to download: UMiniOpenApi-1.0.10-java.zip

		UmengUminiCreateMiniAppParam param = new UmengUminiCreateMiniAppParam();
        param.setName("应用名称");
        param.setType("mini");
        param.setPlatform("平台");
        param.setLanguage("CN");
        param.setFirstLevel("一级分类");
        param.setSecondLevel("二级分类");
        param.setDescription("描述……");
        param.setMiniAppId("");
        param.setMiniAppSecret("");
        param.setMiniPublicKey("");
        param.setMiniPrivateKey("");

        try {
            UmengUminiCreateMiniAppResult result = apiExecutor.execute(param);
            System.out.println("1、" + JSONObject.toJSONString(result));
        } catch (OceanException e) {
            System.out.println("1、errorCode=" + e.getErrorCode() + ", errorMessage=" + e.getErrorMessage());
        }

Special Note:

  1. For details on OpenAPI, please refer to:

    https://developer.umeng.com/open-api/docs/com.umeng.umini/umeng.umini.createMiniApp/1

  2. For industry classification, please refer to: https://developer.umeng.com/docs/147615/detail/169442

  3. If the number of applications created exceeds 300, please contact online customer service

  4. The specific integration method can refer to the demo: https://github.com/umeng/mp-demos

Advanced Features

To use other APIs, you need to add the following code:

import uma from 'umtrack-wx';

App({
  umengConfig: {
    appKey: 'test5d886faf4ca357bfc900',
    useOpenid: true,
    autoGetOpenid: false,
    debug: true
  },
  globalData: {
    uma // 请将uma模块绑定在gloabalData下,以便后续使用
  }
});

1. setUnions

The developer sets the user's unionid by himself

setUnionid(id)

parameter:

  • id(string): user unionid obtained by the developer

return value:

  • no

2. Custom Event

trackEvent(eventId, params)

parameter:

  • id(string): The event ID needs to be applied on the official website, and the length is within 128 characters
  • params(object|string):
    • object cannot be an array
    • When params is object type, the length of each key cannot exceed 256 characters
    • When params is of object type, the number of keys it carries cannot exceed 100
    • When the rule is illegal, discard the entire event

return value:

  • no

2.1 When only counting events and no attributes, use the following methods:

wx.uma.trackEvent('事件ID');

2.2 When counting events with attributes, use the following methods:

wx.uma.trackEvent('事件ID', { '属性1':'属性值1','属性2':'属性值2' });

// 字符型属性值
wx.uma.trackEvent('ViewProductDetails', { 'Category':'家电','ItemName':'西门子冰箱' });

// 数值型属性值
wx.uma.trackEvent('Pay', { 'PayAmount':6999 });

note:

  1. When params is object type, the attribute value only supports two types: string and numeric value;
  2. Please call the event after App.onLaunch.

2.3 Custom event adding process

  1. Go to the "Custom Event" page in the U-MiniProgram background and click "Event Management";
  2. Click "Add Event" and enter the event ID and name of the applet;
  3. Return to the custom event page of the applet to view the event data.

3. Set application user ID

When the user registration on your applet, your application server will be added to the user database record and assign a user ID, through setUseridthe interface provided to the user ID, so that subsequent to do data open or do the calculation based on the application user ID When used.

setUserid(userId, provider)

parameter:

  • userId(string): The unique ID generated by your application for the user
  • provider(string): ID provider, compatible with the old interface, this parameter should be ignored if there is no special need Return value: None Example:
wx.uma.setUserid('custom_userid');

4. Upload user information

Developers can add the configuration uploadUserInfo: trueto the Friends of the Union the option to automatically report the user information. The uploadUserInfosetting falseis canceled reporting user information. The uploaded user information is the basic user information publicly available on the Mini Program platform, such as nickname, avatar, gender, region, language, etc. This information will be used in the statistics of user-related functions in the U-MiniProgram product. Example:

import 'umtrack-wx';
App({
  umengConfig: {
    appKey: 'YOUR_UMENG_APPKEY', //由友盟分配的APP_KEY
    useOpenid: false, // 是否使用openid进行统计,此项为false时将使用友盟+随机ID进行用户统计。使用openid来统计微信小程序的用户,会使统计的指标更为准确,对系统准确性要求高的应用推荐使用OpenID。
    autoGetOpenid: false, // 是否需要通过友盟后台获取openid,如若需要,请到友盟后台设置appId及secret
    debug: true, //是否打开调试模式

    uploadUserInfo: true // 自动上传用户信息,设为false取消上传,默认为false
  }
});

SDK successful access verification method

This solution only provides a method to verify whether the integration is successful. Since there may be incomplete data in the development environment, please verify the correctness of the data after you officially release the applet.

  1. Introduce SDK according to the method described above;
  2. Enter the IDE and open the Console option in the debugging tool. If you see [umeng]-SDK integration prompt, it means that the SDK integration is successful.

Explanation

  1. Call and wx.clearStorage() and wx.clearStorageSync() interfaces carefully! The SDK caches user-related operation data in the client data storage module, and initiates the sending strategy at a specific time. If this interface is called, it may cause inaccurate data statistics;
  2. If the user forcibly closes WeChat while using the Mini Program, statistical data may be lost.

Third-party framework support

Currently, the Mini Program SDK supports the following third-party frameworks, please refer to the demo for specific usage: https://github.com/umeng/mp-demos

  • uniapp
  • taro
  • chameleon
  • mpvue
  • wepy2
  • WeChat games

Currently only SDK 2.2.0 and above can support the above third-party frameworks

Video guide

Video tutorial

FAQ:

  • Q: When registering an application, it prompts that the application name already exists
  • A: [Youmeng+] The application name in the background has nothing to do with the actual application name and package name. It is recommended to name it as the application name + platform, for example: Youmeng + Mini Program (WeChat), Youmeng + Mini Program (Alipay)
  • Q: I forgot my Appkey, where can I find it
  • A: Enter the Mini Program Statistics-Application Settings page, you can see the Appkey of the current Mini Program

https://developers.weixin.qq.com/miniprogram/dev/devtools/npm.html

Guess you like

Origin blog.csdn.net/weixin_39706415/article/details/106804449