|
@@ -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,
|