lex-wxl пре 5 дана
родитељ
комит
5d056e6d00

+ 19 - 0
miniprogram/api/new.ts

@@ -117,3 +117,22 @@ export const api_schoolAreaDetail = (params: any) => {
     method: "get"
   } as any);
 };
+
+/** 埋点信息 */
+export const api_trackPointLog = (params: any) => {
+  return request({
+    url: '/edu-app/open/miniProgramClickLog/save',
+    method: 'post',
+    data: params
+  })
+}
+
+/** 获取openId */
+export const api_getOpenId = (params: any) => {
+  return request({
+    url: '/edu-app/open/paramConfig/miniProgramOpenId',
+    method: 'post',
+    data: params
+  })
+
+}

+ 21 - 1
miniprogram/app.ts

@@ -1,5 +1,6 @@
 // app.ts
 import { api_login, api_queryUserInfo } from "./api/login";
+import { api_getOpenId } from "./api/new";
 const config = require("./config");
 
 App<IAppOption>({
@@ -10,7 +11,7 @@ App<IAppOption>({
     appId: "",
     deviceNum: "", // 设备信息
     isLogin: false, // 是否登录
-    userInfo: {} as any,
+    userInfo: {} as any
   },
   onLaunch() {
     // 展示本地存储能力
@@ -26,6 +27,25 @@ App<IAppOption>({
         this.onLogin(res.code);
       },
     });
+
+    wx.setStorageSync("traceId", this.getRandomKey())
+
+    // 获取openId
+    wx.login({
+      success: async (res) => {
+        await api_getOpenId({
+          code: res.code,
+          appId: this.globalData.appId
+        }).then((res: any) => {
+          // 存储openId
+          wx.setStorageSync("openId", res.data.data);
+        })
+      }
+    })
+  },
+  getRandomKey() {
+    let key = "" + new Date().getTime() + Math.floor(Math.random() * 1000000);
+    return key;
   },
   setAppId() {
     //获取当前小程序appId

+ 33 - 2
miniprogram/pages/buyerInformation/index.ts

@@ -1,5 +1,5 @@
-import { api_schoolAreaDetail, api_schoolAreaList, api_sysAreaQueryAllProvince, api_userBeneficiarySave, api_userBeneficiaryUpdate } from "../../api/new";
-import { debounce, GRADE_ENUM } from "../../utils/util";
+import { api_schoolAreaDetail, api_schoolAreaList, api_sysAreaQueryAllProvince, api_trackPointLog, api_userBeneficiarySave, api_userBeneficiaryUpdate } from "../../api/new";
+import { debounce, formatTime, GRADE_ENUM } from "../../utils/util";
 
 
 const classList: any = [];
@@ -622,6 +622,20 @@ Page({
       return ''
     }
   },
+  // 进行埋点
+  onTrackPoint(options: { openId: string, elementName: string, extParams?: string }) {
+    const traceId = wx.getStorageSync("traceId");
+    const deviceInfo = wx.getDeviceInfo();
+    api_trackPointLog({
+      traceId,
+      openId: options.openId,
+      elementName: options.elementName,
+      deviceInfo: deviceInfo.brand + '_' + deviceInfo.model + '_' + deviceInfo.system + '_' + deviceInfo.platform,
+      appName: "音乐数字AI",
+      extParams: options.extParams || '',
+      clickTime: formatTime(new Date(), '-') // 点击时间
+    })
+  },
   /** 最终提交 */
   async onSubmit() {
     try {
@@ -666,6 +680,23 @@ Page({
         return
       }
 
+      // 埋点
+      const openId = wx.getStorageSync("openId")
+      this.onTrackPoint({
+        openId,
+        elementName: '添加购买人',
+        extParams: JSON.stringify({
+          id: params.userBeneficiaryId || '',
+          phone: params.phone,
+          name: params.name,
+          gender: params.gender,
+          currentGradeNum: params.currentGradeNum,
+          currentClass: params.currentClass,
+          schoolAreaId: params.schoolAreaId,
+          defaultStatus: false
+        })
+      })
+
       const pages = getCurrentPages();
       const prevPage = pages[pages.length - 2]; // 获取上一个页面实例
       if (params.userBeneficiaryId) {

+ 54 - 1
miniprogram/pages/index/index.ts

@@ -1,7 +1,8 @@
 // index.ts
 
 import { api_shopInstruments, api_shopProduct } from "../../api/login";
-import { debounce, formatPrice } from "../../utils/util";
+import { api_getOpenId, api_trackPointLog } from "../../api/new";
+import { debounce, formatPrice, formatTime } from "../../utils/util";
 // 获取应用实例
 const app = getApp<IAppOption>();
 // pages/orders/orders.ts
@@ -88,6 +89,37 @@ Page({
     this.setData({
       videoHeight: (wxWindowInfo.windowWidth / 16) * 9 + "px",
     });
+
+    // 首页进入页面埋点
+    this.onHomePageTrackPoint()
+  },
+  onHomePageTrackPoint() {
+    // openId
+    const openId = wx.getStorageSync("openId")
+    if(openId) {
+      this.onTrackPoint({
+        openId,
+        elementName: '首页'
+      })
+    } else {
+      wx.login({
+        success: async (res) => {
+          await api_getOpenId({
+            code: res.code,
+            appId: app.globalData.appId
+          }).then((res: any) => {
+            // 存储openId
+            const openId = res.data.data
+            wx.setStorageSync("openId", openId);
+
+            this.onTrackPoint({ 
+              openId,
+              elementName: '首页'
+            })
+          })
+        }
+      })
+    }
   },
   onReady() {
     const that = this;
@@ -387,6 +419,20 @@ Page({
       // showSelectedProduct: true,
     });
   },
+  // 进行埋点
+  onTrackPoint(options: { openId: string, elementName: string }) {
+    const traceId = wx.getStorageSync("traceId");
+    const deviceInfo = wx.getDeviceInfo();
+    api_trackPointLog({
+      traceId,
+      openId: options.openId,
+      elementName: options.elementName,
+      deviceInfo: deviceInfo.brand + '_' + deviceInfo.model + '_' + deviceInfo.system + '_' + deviceInfo.platform,
+      appName: "音乐数字AI",
+      // extParams: '',
+      clickTime: formatTime(new Date(), '-') // 点击时间
+    })
+  },
   onClose() {
     this.setData({
       popupShow: false,
@@ -425,6 +471,13 @@ Page({
         })
       }
 
+      // openId
+      const openId = wx.getStorageSync("openId")
+      that.onTrackPoint({
+        openId,
+        elementName: "去结算"
+      })
+
       let info = JSON.stringify({
         ...params
       });

+ 23 - 2
miniprogram/pages/orders/order-detail.ts

@@ -1,7 +1,7 @@
 // pages/orders/order-detail.ts
 import { api_executeOrder, api_executePayment, api_queryByParamName, api_userPaymentOrderDetail, api_userPaymentOrderUnpaid } from "../../api/login";
-import { api_sysAreaQueryAllProvince, api_userReceiveAddressPage, api_userReceiveAddressRemove, api_userReceiveAddressSave, api_userReceiveAddressUpdate } from "../../api/new";
-import { formatPrice, GRADE_ENUM } from "../../utils/util";
+import { api_sysAreaQueryAllProvince, api_trackPointLog, api_userReceiveAddressPage, api_userReceiveAddressRemove, api_userReceiveAddressSave, api_userReceiveAddressUpdate } from "../../api/new";
+import { formatPrice, formatTime, GRADE_ENUM } from "../../utils/util";
 
 // 获取应用实例
 const app = getApp<IAppOption>()
@@ -143,6 +143,20 @@ Page({
       serviceShow: false
     })
   },
+  // 进行埋点
+  onTrackPoint(options: { openId: string, elementName: string, extParams?: string }) {
+    const traceId = wx.getStorageSync("traceId");
+    const deviceInfo = wx.getDeviceInfo();
+    api_trackPointLog({
+      traceId,
+      openId: options.openId,
+      elementName: options.elementName,
+      deviceInfo: deviceInfo.brand + '_' + deviceInfo.model + '_' + deviceInfo.system + '_' + deviceInfo.platform,
+      appName: "音乐数字AI",
+      // extParams: options.extParams || '',
+      clickTime: formatTime(new Date(), '-') // 点击时间
+    })
+  },
   /** 获取订单详情 */
   async getOrderDetail() {
     try {
@@ -341,6 +355,13 @@ Page({
           "paymentCouponAmount": 0
         })
       })
+
+      // 埋点
+      const openId = wx.getStorageSync("openId")
+      this.onTrackPoint({
+        openId,
+        elementName: '去支付'
+      })
       if (orderNo) {
         const { data } = await api_userPaymentOrderUnpaid({
           orderNo: orderNo,

+ 2 - 2
miniprogram/utils/util.ts

@@ -1,4 +1,4 @@
-export const formatTime = (date: Date) => {
+export const formatTime = (date: Date, unit = '/') => {
   const year = date.getFullYear()
   const month = date.getMonth() + 1
   const day = date.getDate()
@@ -7,7 +7,7 @@ export const formatTime = (date: Date) => {
   const second = date.getSeconds()
 
   return (
-    [year, month, day].map(formatNumber).join('/') +
+    [year, month, day].map(formatNumber).join(unit) +
     ' ' +
     [hour, minute, second].map(formatNumber).join(':')
   )

+ 1 - 0
typings/index.d.ts

@@ -11,6 +11,7 @@ interface IAppOption {
   }
   userInfoReadyCallback?: WechatMiniprogram.GetUserInfoSuccessCallback,
   setAppId(): void,
+  getRandomKey(): void,
   onSerivceLocationChange?(): void,
   onLogin(code: string): void
 }