huangzhichao 1 год назад
Родитель
Сommit
2b932de637

+ 3 - 2
src/http/api/index.ts

@@ -3,7 +3,8 @@ import { BASE_DOMAIN, INVITE_API_DOMAIN, BASE_COMMON_DOMAIN } from './base'
 
 function env(BASE_DOMAIN) {
   const envApi = Taro.getStorageSync('env')
-  return BASE_DOMAIN[envApi || 'production']
+  return BASE_DOMAIN[envApi || 'development']
 }
 
-export const adSelfPredict =  `${env(INVITE_API_DOMAIN)}/ad/self/predict`
+export const adSelfPredict =  `${env(INVITE_API_DOMAIN)}/ad/alliance/self/predict`
+export const logUploadReport =  `${env(INVITE_API_DOMAIN)}/log-center/log/logUpload`

+ 3 - 37
src/http/index.ts

@@ -41,7 +41,6 @@ class Http {
         },
         method: 'POST'
       }
-
       Taro.request({
         url,
         data,
@@ -52,41 +51,8 @@ class Http {
             reject(data)
             return
           }
-          const mockData = {
-            "code": 0,
-            "msg": "success",
-            "data": {
-              "ownPlatformAlliance": {
-                "adType": "ownPlatformAlliance",
-                "platformCreativeInfo": {
-                  "id": 3403,
-                  "creativeCode": "CREATIVE_17096086444271430",
-                  "adId": 1136,
-                  "adCode": "AD_17095512471071489",
-                  "campaignId": 172,
-                  "campaignCode": "CAMPAIGN_17024525411821220",
-                  "advertiserId": 332,
-                  "advertiserCode": "ADA_17024523941341815",
-                  "creativePattern": 3,
-                  "creativeTitle": "联盟广告测试",
-                  "copywriting": "111",
-                  "materialType": "VIDEO",
-                  "materialAddress": "http://rescdn.yishihui.com/ad/transcode/prod/video/material_CREATIVE_17096086444271430_1709608644427.mp4",
-                  "creativeLogoAddress": "http://rescdn.yishihui.com/ad/prod/image/logo_1709608644242.png",
-                  "clickButtonText": "按钮啊啊",
-                  "clickButtonColor": "#00C25D",
-                  "clickButtonEffects": 0,
-                  "landingPageType": 2,
-                  "landingPageAddress": "https://nbtga.whjiaoy.com/putin/linkTovnn7Pb?ewpCode=10008&channel=786&subChannel=415&lxqAdid=pqAdOpDrKrMMm8",
-                  "positionId": 13,
-                  "adpId":"xxxxxx",
-                  "trafficCode":"ATP182138123"
-                }
-              }
-            },
-            "success": true
-          }
-          resolve(mockData || data)
+
+          resolve(data)
         },
         fail(res) {
           reject(res)
@@ -122,7 +88,7 @@ export function wrapData(params) {
 }
 
 export function createBaseInfoToFetchData(data) {
-  const baseKey = ['token', 'loginUid', 'appType', 'machineCode', 'platform', 'machineInfo', 'networkType', 'pageSource', 'rootPageSource', 'clientTimestamp', 'sessionId', 'subSessionId', 'requestId', 'pageCategoryId', 'rootPageCategoryId', 'openType', 'shareDepth', 'eventId', 'videoReportMeta', 'rootPageTimestamp', 'returnId', 'system']
+  const baseKey = ['appType', 'machineCode', 'platform', 'machineInfo', 'network', 'clientTimestamp', 'requestId', 'eventId', 'system']
 
   return Object.keys(data).reduce((calc, key) => {
     if (baseKey.includes(key)) {

+ 71 - 0
src/logCenter/index.ts

@@ -0,0 +1,71 @@
+import Taro from '@tarojs/taro'
+import { createBaseInfoToFetchData } from '@/http/index'
+import { logUploadReport } from '@/http/api/index'
+const logTypeEnums = {
+  //ab测试上报类型
+  ABTEST : 10,
+  //漏斗模型上报类型
+  funnel : 20,
+  //独立事件上报类型
+  simpleEvent : 30,
+  //前端调试上报类型
+  debug : 40,
+  //播放动作上报类型
+  playAction : 50,
+  //用户活跃上报类型
+  userActive : 60,
+  // h5 自营广告新库
+  adActionNewLog : 170
+}
+
+interface adAction {
+  (params: any[]): Promise<any>
+}
+
+export const adActionLog: adAction = params => {
+  const { baseInfo } = createBaseInfoToFetchData(params[0] || {})
+
+  const detail = params.map(item => ({
+    logUploadType: 'OWN_AD_UPLOAD',
+    params: {
+      logType: logTypeEnums.adActionNewLog,
+      ...item
+    }
+  }))
+
+  return request(logUploadReport, {
+    baseInfo,
+    detail
+  }, { 'content-type': 'application/json;' })
+}
+
+function request(url, data, header) {
+  return new Promise((resolve, reject) => {
+    const expParams: ConfigType = {
+      header: {
+        'content-type': 'application/x-www-form-urlencoded',
+        ...header
+      },
+      method: 'POST'
+    }
+
+    Taro.request({
+      url,
+      data,
+      success(res) {
+        const { data, statusCode } = res
+
+        if (statusCode !== 200) {
+          reject(data)
+          return
+        }
+
+        resolve(data)
+      },
+      fail(res) {
+        reject(res)
+      },
+      ...expParams
+    })
+  })
+}

+ 36 - 3
src/plugin/components/custom/index.tsx

@@ -2,10 +2,12 @@ import Taro, { useLoad, useReady, useUnload } from '@tarojs/taro'
 import { PropsWithChildren, useState } from 'react'
 import { View, Video, Image } from '@tarojs/components'
 import useGetCustomClient from '@/hooks/useGetCustomClient'
-import { wrapProps } from '@/plugin/share'
+import { wrapProps, generateUUID } from '@/plugin/share'
 import './index.less'
 import http from '@/http/index'
 import { adSelfPredict } from '@/http/api/index'
+import { adActionLog } from '@/logCenter/index'
+import { reportBusinessType } from '@/plugin/share/const'
 
 // 在一些场景下 loadedMetaFiredInOnce 被触发了很多次
 let loadedMetaFiredInOnce = 0
@@ -35,10 +37,12 @@ function PqCustom(props: PropsWithChildren<CustomPropsType>) {
 
   useReady(() => {
     getAdConfig()
+
+    adActionReport(reportBusinessType.buttonView, 'adView')
   })
 
   function getAdConfig() {
-    http.post(adSelfPredict, {
+    http.post(`${adSelfPredict}?adpId=uh2321awe1`, {
       baseInfo: {},
       positionId: 1,
       phoneModel : '',
@@ -47,7 +51,7 @@ function PqCustom(props: PropsWithChildren<CustomPropsType>) {
     }, {
       header: { 'content-type': 'application/json;' }
     }).then((res: RequestType) => {
-      const { code, message, data } = res
+      const { code, data } = res
       // TODO: onError、logUpload
       if(code !== 0) {
         onError()
@@ -63,6 +67,8 @@ function PqCustom(props: PropsWithChildren<CustomPropsType>) {
       })
 
       console.log(data)
+    }).catch(err => {
+      console.log(err)
     })
   }
 
@@ -100,6 +106,33 @@ function PqCustom(props: PropsWithChildren<CustomPropsType>) {
     closeCustom()
   }
 
+  function adActionReport(eventId, businessType) {
+    const {
+      adCode,
+      adPosition,
+      advertiserId,
+      ownAdDetailId,
+      ownAdPositionId,
+      ownAdSystemType,
+      planId,
+    } = adData
+
+    adActionLog([{
+      adCode,
+      adPosition,
+      advertiserId,
+      businessType,
+      eventId,
+      ownAdDetailId,
+      ownAdPositionId,
+      ownAdSystemType,
+      pageSource: 'plugin',
+      planId,
+      pqtId: generateUUID(),
+      videoId: '000'
+    }])
+  }
+
   return (
     <>
       {show && <View className='pq-custom' onClick={clickMask}>

+ 7 - 0
src/plugin/share/const.ts

@@ -0,0 +1,7 @@
+export const reportBusinessType = {
+  buttonClick: 'buttonClick',
+  buttonView: 'buttonView',
+  windowView: 'windowView',
+  autoJump: 'autoJump',
+  pageView: 'pageView'
+}

+ 10 - 0
src/plugin/share/index.ts

@@ -45,4 +45,14 @@ export function wrapProps(props: PropsWithChildren<CustomPropsType>) {
     onClick,
     onClose
   }
+}
+
+export function generateUUID () {
+  let d = new Date().getTime();
+  let uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
+      let r = (d + Math.random() * 16) % 16 | 0;
+      d = Math.floor(d / 16);
+      return (c === 'x' ? r : (r & 0x7) | 0x8).toString(16);
+  });
+  return uuid;
 }