useEventPoint.tsx 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import { Local } from "@/utils/storage";
  2. import { useEffect, useState } from "react";
  3. /**
  4. * @description
  5. *
  6. 1、查看内容 - ViewContent 打开首页
  7. 2.完成注册 - CompleteRegistration
  8. 3.登陆 - SubmitApplication
  9. 4.开始试用游戏 - StartTrial 启动一次游戏就触发
  10. 5.加入购物车 - AddToCart 付费一次就回传一次,包含复充
  11. 6.拉起订单 - InitiateCheckout 用户发起充值,调出第三方充值二维码
  12. 7.首充事件 - Purchase 新用户第一次完成首充回传一次,之后复充不在回传
  13. */
  14. type PixelType = "kwai_pixel" | "facebook_pixel";
  15. const useEventPoint = () => {
  16. const [source, setSource] = useState<PixelType | null>(null);
  17. useEffect(() => {
  18. setSource(Local.getKey("ban_pixel_type"));
  19. }, []);
  20. // 查看内容 | null
  21. const eventView = () => {
  22. if (source === "kwai_pixel") {
  23. window.kwaiq.track("contentView");
  24. }
  25. if (source === "facebook_pixel") {
  26. window.fbq("track", "ViewContent");
  27. }
  28. };
  29. // 注册
  30. const eventRegister = () => {
  31. if (source === "kwai_pixel") {
  32. window.kwaiq.instance(Local.getKey("ban_pixel_id")).track("completeRegistration");
  33. }
  34. if (source === "facebook_pixel") {
  35. window.fbq("track", "CompleteRegistration");
  36. }
  37. };
  38. // 登录
  39. const eventLogin = () => {
  40. if (source === "facebook_pixel") {
  41. window.fbq("track", "SubmitApplication");
  42. }
  43. };
  44. // 开始试用游戏
  45. const eventStartTrial = () => {
  46. if (source === "facebook_pixel") {
  47. window.fbq("track", "StartTrial");
  48. }
  49. };
  50. // 充值
  51. const eventPurchase = () => {
  52. if (source === "kwai_pixel") {
  53. window.kwaiq.instance(Local.getKey("ban_pixel_id")).track("purchase");
  54. }
  55. if (source === "facebook_pixel") {
  56. window.fbq("track", "AddToCart");
  57. }
  58. };
  59. //拉起订单
  60. const eventInitiate = () => {
  61. if (source === "facebook_pixel") {
  62. window.fbq("track", "InitiateCheckout");
  63. }
  64. };
  65. //首充事件
  66. const eventFirstDeposit = () => {
  67. if (source === "kwai_pixel") {
  68. window.kwaiq.instance(Local.getKey("ban_pixel_id")).track("firstDeposit");
  69. }
  70. if (source === "facebook_pixel") {
  71. window.fbq("track", "Purchase");
  72. }
  73. };
  74. return {
  75. eventView,
  76. eventRegister,
  77. eventLogin,
  78. eventStartTrial,
  79. eventPurchase,
  80. eventInitiate,
  81. eventFirstDeposit,
  82. };
  83. };
  84. export { useEventPoint };