li.shaoyi 5 ヶ月 前
コミット
d73890306e

+ 1 - 1
oem/tss/config/appconfig.json

@@ -13,5 +13,5 @@
     "holdvolume"
   ],
   "riskType": 1,
-  "metaPixelId": "1216740937129492"
+  "metaPixelId": "3835518800009765"
 }

+ 29 - 22
src/hooks/meta-pixel/index.ts

@@ -11,45 +11,52 @@ declare global {
 
 export function useMetaPixel() {
     const { getSystemInfo } = useGlobalStore()
+    const pixelId = getSystemInfo('metaPixelId')
 
     // 初始化 MetaPixel
     const initPixel = () => {
-        if (window.fbq) return
+        if (pixelId) {
+            if (window.fbq) return
 
-        const fbq: any = <T>(...args: T[]) => {
-            fbq.callMethod
-                ? fbq.callMethod(...args)
-                : fbq.queue.push(args)
-        }
+            const fbq: any = <T>(...args: T[]) => {
+                fbq.callMethod
+                    ? fbq.callMethod(...args)
+                    : fbq.queue.push(args)
+            }
 
-        if (!window._fbq) {
-            window._fbq = fbq
-        }
+            if (!window._fbq) {
+                window._fbq = fbq
+            }
 
-        fbq.push = fbq
-        fbq.loaded = true
-        fbq.version = '2.0'
-        fbq.queue = []
+            fbq.push = fbq
+            fbq.loaded = true
+            fbq.version = '2.0'
+            fbq.queue = []
 
-        const el = document.createElement('script')
-        el.async = true
-        el.src = 'https://connect.facebook.net/en_US/fbevents.js'
+            const el = document.createElement('script')
+            el.async = true
+            el.src = 'https://connect.facebook.net/en_US/fbevents.js'
 
-        const tag = document.getElementsByTagName('script')[0]
-        tag.parentNode?.insertBefore(el, tag)
+            const tag = document.getElementsByTagName('script')[0]
+            tag.parentNode?.insertBefore(el, tag)
 
-        window.fbq = fbq
-        window.fbq('init', getSystemInfo('metaPixelId'))
+            window.fbq = fbq
+            window.fbq('init', pixelId)
+        }
     }
 
     // 跟踪页面视图
     const trackPageView = () => {
-        window.fbq('track', 'PageView')
+        if (pixelId) {
+            window.fbq('track', 'PageView')
+        }
     }
 
     // 跟踪自定义事件
     const trackEvent = (eventName: 'Lead' | 'Purchase', parameters?: Record<string, any>) => {
-        window.fbq('track', eventName, parameters)
+        if (pixelId) {
+            window.fbq('track', eventName, parameters)
+        }
     }
 
     // 在组件挂载时初始化

+ 8 - 2
src/packages/mobile/views/user/register/Index.vue

@@ -78,11 +78,13 @@
 </template>
 
 <script lang="ts" setup>
-import { reactive, shallowRef, ref, computed, onMounted, useAttrs, toRaw } from 'vue'
+import { reactive, shallowRef, ref, computed, onMounted, useAttrs } from 'vue'
 import { CellGroup, Cell, Button, Field, Form, FormInstance, Checkbox, showFailToast, showToast, FieldRule, Popup, Picker, PickerConfirmEventParams, showSuccessToast } from 'vant'
 import { useCountDown } from '@vant/use'
 import { fullloading, dialog } from '@/utils/vant'
+import { tmMatchAccountID } from '@/filters'
 import { validateRules } from '@/constants/regex'
+import { useMetaPixel } from '@/hooks/meta-pixel'
 import { useNavigation } from '@mobile/router/navigation'
 import { userRegister, sendRegisterVerifyCode, queryMyRegisterMoney } from '@/services/api/common'
 import { i18n, useGlobalStore, useUserStore, useErrorInfoStore } from '@/stores'
@@ -109,6 +111,7 @@ defineProps({
 
 const emit = defineEmits<{ (event: string, ...args: unknown[]): void }>()
 
+const { trackEvent } = useMetaPixel()
 const attrs = useAttrs()
 
 // 是否弹出选择器
@@ -241,7 +244,10 @@ const formRules: { [key: string]: FieldRule[] } = {
 
 // 路由跳转
 const routerAction = () => {
-  emit('trackLead', toRaw(formData))
+  // 追踪注册结果
+  trackEvent('Lead', {
+    content_name: tmMatchAccountID(formData.mobilephone)
+  })
 
   if (attrs.onRouterAction) {
     emit('routerAction')

+ 5 - 1
src/packages/tss/router/index.ts

@@ -113,9 +113,13 @@ const routes: Array<RouteRecordRaw> = [
       {
         path: 'register',
         name: 'user-register',
-        component: () => import('../views/user/register/index.vue'),
+        component: () => import('@mobile/views/user/register/Index.vue'),
         meta: {
           ignoreAuth: true,
+        },
+        props: {
+          showYhkhfxgzs: false,
+          insetStyle: false
         }
       },
       {

+ 0 - 17
src/packages/tss/views/user/register/index.vue

@@ -1,17 +0,0 @@
-<template>
-    <register-view :show-yhkhfxgzs="false" :inset-style="false" @track-lead="trackLead" />
-</template>
-
-<script lang="ts" setup>
-import { useMetaPixel } from '@/hooks/meta-pixel'
-import RegisterView from '@mobile/views/user/register/Index.vue'
-
-const { trackEvent } = useMetaPixel()
-
-// 追踪注册结果
-const trackLead = (formData: Model.RegisterReq) => {
-    trackEvent('Lead', {
-        content_name: formData.mobilephone
-    })
-}
-</script>

+ 2 - 1
src/stores/modules/global.ts

@@ -20,7 +20,7 @@ export interface SystemInfo {
     i18nEnabled: boolean; // 是否启用多语言设置
     allCloseEnabled: boolean; // 是否启用全部平仓
     allDeliveryEnabled: boolean; // 是否启用全部交收
-    metaPixelId: string;
+    metaPixelId: string; // 是否启用像素追踪
 }
 
 export const useGlobalStore = defineStore(() => {
@@ -50,6 +50,7 @@ export const useGlobalStore = defineStore(() => {
             i18nEnabled: true,
             allCloseEnabled: false,
             allDeliveryEnabled: false,
+            metaPixelEnabled: false,
             metaPixelId: ''
         }
     })