瀏覽代碼

fix: 增加事件埋点

Ansoni 5 月之前
父節點
當前提交
b60bce3429

+ 4 - 1
src/app/[locale]/(TabBar)/[[...share]]/@clientWidget/page.tsx

@@ -7,7 +7,7 @@ import { useEffect } from "react";
  * @description 主页初始化
  */
 const Page = () => {
-    useEventPoint();
+    const { eventView } = useEventPoint();
 
     // 获取分享id
     const pathname = usePathname();
@@ -22,6 +22,9 @@ const Page = () => {
         }
         sessionStorage.setItem("shareId", shareId);
     }, []);
+
+    eventView();
+
     return null;
 };
 

+ 7 - 1
src/app/[locale]/(enter)/components/Form/index.tsx

@@ -3,6 +3,7 @@ import { loginApi, registerApi, userInfoApi } from "@/api/login";
 import Box from "@/components/Box";
 import ButtonOwn from "@/components/ButtonOwn";
 import MobileField from "@/components/Fields/MobileField";
+import { useEventPoint } from "@/hooks/useEventPoint";
 import { Link, useRouter } from "@/i18n/routing";
 import { useSystemStore } from "@/stores/useSystemStore";
 import { useUserInfoStore } from "@/stores/useUserInfoStore";
@@ -143,6 +144,8 @@ const FormComponent: FC<Props> = (props) => {
     const searchParams = useSearchParams();
     const [statusText, setStatusText] = useState("");
 
+    const { eventLogin, eventRegister } = useEventPoint();
+
     /// 密码可见
     const [visible, setVisible] = useState(false);
     const spanClassName = clsx("iconfont", {
@@ -246,6 +249,8 @@ const FormComponent: FC<Props> = (props) => {
                             router.replace("/recharge");
                             Toast.clear();
                         });
+
+                        eventRegister();
                     }
                 })
                 .catch((error) => {
@@ -259,13 +264,14 @@ const FormComponent: FC<Props> = (props) => {
                 });
         } else {
             /// 登录
-            console.log(`🚀🚀🚀🚀🚀-> in index.tsx on 257`, values);
             loginHandler(values).then(() => {
                 Toast.clear();
                 const redirect = searchParams.get("redirect")
                     ? `/${searchParams.get("redirect")}`
                     : "/";
                 router.replace(redirect);
+
+                eventLogin();
             });
         }
     };

+ 1 - 1
src/app/[locale]/(enter)/register/page.tsx

@@ -11,7 +11,7 @@ import GoogleCom from "../components/GoogleCom";
 
 const Register: FC<Props> = async () => {
     const services = await getServicesApi();
-    console.log(`🚀🚀🚀🚀🚀-> in page.tsx on 14`, services);
+
     const defaultService = services?.filter((item) => item.register_show === 1);
     const t = await getTranslations("LoginPage");
     return (

File diff suppressed because it is too large
+ 64 - 19
src/app/[locale]/providers.tsx


+ 53 - 18
src/hooks/useEventPoint.tsx

@@ -1,7 +1,4 @@
-import { useSearchParams } from "next/navigation";
-import { useEffect } from "react";
-
-type SourceType = "facebook" | "Kwai";
+import { useEffect, useState } from "react";
 
 /**
  * @description
@@ -14,35 +11,73 @@ type SourceType = "facebook" | "Kwai";
   6.拉起订单 - InitiateCheckout    用户发起充值,调出第三方充值二维码
   7.首充事件 - Purchase   新用户第一次完成首充回传一次,之后复充不在回传
  */
+type PixelType = "kwai_pixel" | "facebook_pixel";
+
 const useEventPoint = () => {
-    const pathname = useSearchParams();
-    const a = pathname.get("source");
-    console.log(`🚀🚀🚀🚀🚀-> in useEventPoint.tsx on 20`, a);
-    const source: SourceType = "facebook";
+    const [source, setSource] = useState<PixelType | null>(null);
     useEffect(() => {
-        console.log(`🚀🚀🚀🚀🚀-> in useEventPoint.tsx on 6`, window.fbq("ViewContent"));
-    });
-    // 查看内容
+        setSource(localStorage.getItem("pixel_type") as PixelType | null);
+    }, []);
+
+    // 查看内容 | null
     const eventView = () => {
-        console.log(`🚀🚀🚀🚀🚀-> in useEventPoint.tsx on 10`, window.fbq);
+        if (source === "kwai_pixel") {
+            window.kwaiq.instance(localStorage.getItem("pixel_id")!).track("contentView");
+        }
+        if (source === "facebook_pixel") {
+            window.fbq("track", "ViewContent");
+        }
     };
     // 注册
-    const eventRegister = () => {};
+    const eventRegister = () => {
+        if (source === "kwai_pixel") {
+            window.kwaiq.instance(localStorage.getItem("pixel_id")!).track("completeRegistration");
+        }
+        if (source === "facebook_pixel") {
+            window.fbq("track", "CompleteRegistration");
+        }
+    };
 
     // 登录
-    const eventLogin = () => {};
+    const eventLogin = () => {
+        if (source === "facebook_pixel") {
+            window.fbq("track", "SubmitApplication");
+        }
+    };
 
     // 开始试用游戏
-    const eventStartTrial = () => {};
+    const eventStartTrial = () => {
+        if (source === "facebook_pixel") {
+            window.fbq("track", "StartTrial");
+        }
+    };
 
     // 加入购物车
-    const eventPurchase = () => {};
+    const eventPurchase = () => {
+        if (source === "kwai_pixel") {
+            window.kwaiq.instance(localStorage.getItem("pixel_id")!).track("purchase");
+        }
+        if (source === "facebook_pixel") {
+            window.fbq("track", "AddToCart");
+        }
+    };
 
     //拉起订单
-    const eventInitiate = () => {};
+    const eventInitiate = () => {
+        if (source === "facebook_pixel") {
+            window.fbq("track", "InitiateCheckout");
+        }
+    };
 
     //首充事件
-    const eventFirstDeposit = () => {};
+    const eventFirstDeposit = () => {
+        if (source === "kwai_pixel") {
+            window.kwaiq.instance(localStorage.getItem("pixel_id")!).track("firstDeposit");
+        }
+        if (source === "facebook_pixel") {
+            window.fbq("track", "Purchase");
+        }
+    };
 
     return {
         eventView,

+ 9 - 0
src/types/global.d.ts

@@ -1,8 +1,17 @@
 import { DefaultConfigTypes } from "@/api/setup";
 
+interface Kwaiq {
+    instance: (id: string) => Kwaiq;
+    track: (id: string, params?: any) => void;
+}
 declare global {
     namespace globalThis {
         var config: DefaultConfigTypes;
+        var fbq: (event: string, eventName: string, params?: any) => void;
+        var kwaiq: Kwaiq;
     }
+
+    namespace window {}
 }
+
 export {};

Some files were not shown because too many files changed in this diff