li.shaoyi 4 月之前
父節點
當前提交
b5d658d7e5

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

@@ -13,5 +13,6 @@
     "holdvolume"
   ],
   "riskType": 1,
-  "metaPixelId": "3835518800009765"
+  "metaPixelId": "3835518800009765",
+  "appsFlyerKey": "uFB8ocrd4ExTgKYPMyYfYD"
 }

+ 76 - 0
src/hooks/appsflyer/index.ts

@@ -0,0 +1,76 @@
+import { useGlobalStore } from '@/stores'
+import { CallbackMessage } from './types'
+//import appsFlyer from 'nativescript-plugin-appsflyer'
+import plus from '@/utils/h5plus'
+
+// https://support.appsflyer.com/hc/en-us/articles/217183026-NativeScript-plugin
+export const useAppsFlyer = (() => {
+    const { getSystemInfo } = useGlobalStore()
+    //const appsFlyerId = getSystemInfo('appsFlyerId')
+    const appsFlyerKey = getSystemInfo('appsFlyerKey')
+
+    const appsFlyerPromise = new Promise<CallbackMessage>((resolve, reject) => {
+        if (appsFlyerKey) {
+            const startSuccess = (res: CallbackMessage) => {
+                console.log(res)
+                resolve(res)
+            }
+
+            const fail = (err: CallbackMessage) => {
+                console.error(err)
+                reject(err)
+            }
+
+            if (plus.hasPlus()) {
+                const initSuccess = () => {
+                    window.plus.bridge.exec('AppsFlyerExpand', 'startSDK', [startCallbackID])
+                }
+
+                const initCallbackID = window.plus.bridge.callbackId(initSuccess, fail)
+                const startCallbackID = window.plus.bridge.callbackId(startSuccess, fail)
+
+                window.plus.bridge.exec('AppsFlyerExpand', 'initSDK', [initCallbackID, 'uFB8ocrd4ExTgKYPMyYfYD', false])
+            } else {
+                // appsFlyer.initSdk({
+                //     devKey: appsFlyerKey,
+                //     //appId: appsFlyerId
+                // }).then((res) => {
+                //     startSuccess(res)
+                // }).catch((err) => {
+                //     fail(err)
+                // })
+            }
+        } else {
+            reject()
+        }
+    })
+
+    return () => {
+        // 跟踪自定义事件
+        const logEvent = (eventName: 'af_complete_registration' | 'af_purchase', eventValues: Record<string, any> = {}) => {
+            appsFlyerPromise.then(() => {
+                const success = (res: CallbackMessage) => console.log(res)
+                const fail = (err: CallbackMessage) => console.error(err)
+
+                if (plus.hasPlus()) {
+                    const callbackID = window.plus.bridge.callbackId(success, fail)
+
+                    window.plus.bridge.exec('AppsFlyerExpand', 'logEvent', [callbackID, eventName, JSON.stringify(eventValues)])
+                } else {
+                    // appsFlyer.logEvent({
+                    //     eventName,
+                    //     eventValues
+                    // }).then((res) => {
+                    //     success(res)
+                    // }).catch((err) => {
+                    //     fail(err)
+                    // })
+                }
+            })
+        }
+
+        return {
+            logEvent
+        }
+    }
+})()

+ 5 - 0
src/hooks/appsflyer/types.ts

@@ -0,0 +1,5 @@
+export interface CallbackMessage {
+    status: string;
+    action: string;
+    message: string;
+}

+ 12 - 12
src/hooks/meta-pixel/index.ts → src/hooks/facebook/index.ts

@@ -2,7 +2,6 @@ import { onMounted } from 'vue'
 import { useGlobalStore } from '@/stores'
 import plus from '@/utils/h5plus'
 
-// https://developers.facebook.com/docs/meta-pixel/reference
 declare global {
     interface Window {
         fbq: any;
@@ -10,13 +9,14 @@ declare global {
     }
 }
 
-export function useMetaPixel() {
+// https://developers.facebook.com/docs/meta-pixel/reference
+export function useFacebook() {
     const { getSystemInfo } = useGlobalStore()
-    const pixelId = getSystemInfo('metaPixelId')
+    const metaPixelId = getSystemInfo('metaPixelId')
 
     // 初始化 MetaPixel
-    const initPixel = () => {
-        if (pixelId) {
+    const initMetaPixel = () => {
+        if (metaPixelId) {
             if (window.fbq) return
 
             const fbq: any = <T>(...args: T[]) => {
@@ -42,31 +42,31 @@ export function useMetaPixel() {
             tag.parentNode?.insertBefore(el, tag)
 
             window.fbq = fbq
-            window.fbq('init', pixelId)
+            window.fbq('init', metaPixelId)
         }
     }
 
     // 跟踪页面视图
     const trackPageView = () => {
-        if (pixelId) {
+        if (metaPixelId) {
             window.fbq('track', 'PageView')
         }
     }
 
     // 跟踪自定义事件
-    const trackEvent = (eventName: 'CompleteRegistration' | 'Purchase', parameters: Record<string, any> = {}) => {
-        if (pixelId) {
+    const trackEvent = (eventName: 'CompleteRegistration' | 'Purchase', eventValues: Record<string, any> = {}) => {
+        if (metaPixelId) {
             if (plus.hasPlus()) {
-                window.plus.bridge.exec('FacebookExpand', 'metaPixelFunction', [eventName, JSON.stringify(parameters)])
+                window.plus.bridge.exec('FacebookExpand', 'metaPixelFunction', [eventName, JSON.stringify(eventValues)])
             } else {
-                window.fbq('track', eventName, parameters)
+                window.fbq('track', eventName, eventValues)
             }
         }
     }
 
     // 在组件挂载时初始化
     onMounted(() => {
-        initPixel()
+        initMetaPixel()
         trackPageView()
     })
 

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

@@ -78,7 +78,8 @@ import { CellGroup, Cell, Button, Field, Form, FormInstance, Checkbox, showFailT
 import { useCountDown } from '@vant/use'
 import { fullloading, dialog } from '@/utils/vant'
 import { validateRules } from '@/constants/regex'
-import { useMetaPixel } from '@/hooks/meta-pixel'
+import { useFacebook } from '@/hooks/facebook'
+import { useAppsFlyer } from '@/hooks/appsflyer'
 import { useNavigation } from '@mobile/router/navigation'
 import { userRegister, sendRegisterVerifyCode, queryMyRegisterMoney } from '@/services/api/common'
 import { i18n, useGlobalStore, useUserStore, useErrorInfoStore } from '@/stores'
@@ -107,7 +108,8 @@ defineProps({
 const emit = defineEmits<{ (event: string, ...args: unknown[]): void }>()
 
 const { t } = i18n.global
-const { trackEvent } = useMetaPixel()
+const { trackEvent } = useFacebook()
+const { logEvent } = useAppsFlyer()
 
 const attrs = useAttrs()
 
@@ -227,6 +229,10 @@ const formRules: { [key: string]: FieldRule[] } = {
 const routerAction = () => {
   // 追踪注册结果
   trackEvent('CompleteRegistration')
+  
+  logEvent('af_complete_registration', {
+    af_registration_method: 'Mobile'
+  })
 
   if (attrs.onRouterAction) {
     emit('routerAction')

+ 10 - 2
src/packages/tss/views/bank/wallet/components/deposit/Index.vue

@@ -110,7 +110,8 @@ import { useDoDeposit, useDoCusBankExtendConfigs, getMethodTypeKeys, useHybridCo
 import { getServerTime } from '@/services/api/common'
 import { useUserStore, useAccountStore, i18n } from '@/stores'
 import { useComponent } from '@/hooks/component'
-import { useMetaPixel } from '@/hooks/meta-pixel'
+import { useFacebook } from '@/hooks/facebook'
+import { useAppsFlyer } from '@/hooks/appsflyer'
 import Stepper from '@mobile/components/base/stepper/index.vue'
 import AppSelect from '@mobile/components/base/select/index.vue'
 import moment from 'moment'
@@ -123,7 +124,8 @@ const props = defineProps({
     }
 })
 
-const { trackEvent } = useMetaPixel()
+const { trackEvent } = useFacebook()
+const { logEvent } = useAppsFlyer()
 
 const formRef = shallowRef<FormInstance>()
 const { formData, onSubmit, sign } = useDoDeposit()
@@ -246,6 +248,7 @@ const doDepositWarning = () => {
                     message: t('banksign.wallet.deposit.goldisnotwithinthetimeframe'),
                     confirmButtonText: t('common.ikonw')
                 })
+                hideLoading()
             }
         }).catch(() => {
             hideLoading(t('banksign.wallet.deposit.failedtogetservertime'), 'fail')
@@ -297,6 +300,11 @@ const formSubmit = (hideLoading: () => void) => {
             value: formData.Amount,
         })
 
+        logEvent('af_purchase', {
+            af_currency: formData.Currency,
+            af_revenue: formData.Amount,
+        })
+
         dialog({
             message: i18n.global.t('banksign.wallet.deposit.submitsuccess')
         }).then(() => {

+ 0 - 82
src/packages/tss/views/home/main/index.vue

@@ -11,18 +11,6 @@
     <!-- 任务 #6996 -->
     <Banner :data-list="topBanners" :height="290" />
     <div class="home-main__container">
-
-
-      <button type="button" style="border: 1px solid #000; padding: 20px; background-color: #fff;"
-        @click="trackEvent">initSDK Test</button>
-
-      <button type="button" style="border: 1px solid #000; padding: 20px; background-color: #fff;"
-        @click="registrationEvent">registration Test</button>
-
-      <button type="button" style="border: 1px solid #000; padding: 20px; background-color: #fff;"
-        @click="purchaseEvent">purchase Test</button>
-
-
       <app-block class="home-main__notice">
         <h4 @click="$router.push({ name: 'notice-list' })">
           <span>{{ $t('routes.notice') }}</span>
@@ -73,76 +61,6 @@ import Banner from '@mobile/components/base/banner/index.vue'
 import plus from '@/utils/h5plus'
 import ProductList from '../../product/list/components/waterfall-list/index.vue'
 
-
-
-const trackEvent = () => {
-  plus.onPlusReady(() => {
-
-    const startSDKsuccess = (args: unknown) => {
-      window.alert('成功:' + JSON.stringify(args))
-    }
-
-
-    const success = (args: unknown) => {
-
-      window.plus.bridge.exec('AppsFlyerExpand', 'startSDK', [startSDKcallbackID])
-
-    }
-
-    const fail = (code: unknown) => {
-      window.alert('失败:' + JSON.stringify(code))
-    }
-
-    const callbackID = window.plus.bridge.callbackId(success, fail)
-
-
-    const startSDKcallbackID = window.plus.bridge.callbackId(startSDKsuccess, fail)
-
-    window.plus.bridge.exec('AppsFlyerExpand', 'initSDK', [callbackID, '123', false])
-  })
-}
-
-
-
-const registrationEvent = () => {
-  plus.onPlusReady(() => {
-
-    const success = (args: unknown) => {
-      window.alert('成功:' + JSON.stringify(args))
-    }
-
-    const fail = (code: unknown) => {
-      window.alert('失败:' + JSON.stringify(code))
-    }
-
-    const callbackID = window.plus.bridge.callbackId(success, fail)
-
-    window.plus.bridge.exec('AppsFlyerExpand', 'logEvent', [callbackID, 'af_complete_registration', JSON.stringify({ af_registration_method: "Mobile" })])
-  })
-}
-
-
-
-const purchaseEvent = () => {
-  plus.onPlusReady(() => {
-
-    const success = (args: unknown) => {
-      window.alert('成功:' + JSON.stringify(args))
-    }
-
-    const fail = (code: unknown) => {
-      window.alert('失败:' + JSON.stringify(code))
-    }
-
-    const callbackID = window.plus.bridge.callbackId(success, fail)
-
-    window.plus.bridge.exec('AppsFlyerExpand', 'logEvent', [callbackID, 'af_purchase', JSON.stringify({ af_revenue: 9.99, af_currency: "USD" })])
-  })
-}
-
-
-
-
 const noticeStore = useNoticeStore()
 const goodsCollectionStore = useGoodsCollectionStore()
 

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

@@ -21,6 +21,8 @@ export interface SystemInfo {
     allCloseEnabled: boolean; // 是否启用全部平仓
     allDeliveryEnabled: boolean; // 是否启用全部交收
     metaPixelId: string; // 是否启用像素追踪
+    appsFlyerId: string; // 是否启用像素追踪
+    appsFlyerKey: string; // 是否启用像素追踪
 }
 
 export const useGlobalStore = defineStore(() => {
@@ -51,7 +53,9 @@ export const useGlobalStore = defineStore(() => {
             allCloseEnabled: false,
             allDeliveryEnabled: false,
             metaPixelEnabled: false,
-            metaPixelId: ''
+            metaPixelId: '',
+            appsFlyerId: '',
+            appsFlyerKey: ''
         }
     })