15 changed files with 834 additions and 447 deletions
@ -0,0 +1,341 @@ |
|||||||
|
import React from 'react'; |
||||||
|
import { NavigationContainer } from "@react-navigation/native"; |
||||||
|
import { createNativeStackNavigator } from "@react-navigation/native-stack"; |
||||||
|
import { RootStackParamList } from './types'; |
||||||
|
import * as Screens from './screens'; |
||||||
|
import Toast from "react-native-toast-message"; |
||||||
|
|
||||||
|
const Stack = createNativeStackNavigator<RootStackParamList>(); |
||||||
|
|
||||||
|
export const AppNavigator = () => { |
||||||
|
return ( |
||||||
|
<NavigationContainer> |
||||||
|
<Stack.Navigator |
||||||
|
screenOptions={{ |
||||||
|
headerShown: false, |
||||||
|
}} |
||||||
|
> |
||||||
|
<Stack.Screen name="CountrySelect" component={Screens.CountrySelect} /> |
||||||
|
<Stack.Screen |
||||||
|
name="Login" |
||||||
|
component={Screens.LoginScreen} |
||||||
|
options={{ |
||||||
|
presentation: "modal", |
||||||
|
animation: "slide_from_bottom", |
||||||
|
gestureEnabled: true, |
||||||
|
gestureDirection: "vertical", |
||||||
|
}} |
||||||
|
/> |
||||||
|
<Stack.Screen |
||||||
|
name="MainTabs" |
||||||
|
component={Screens.TabNavigator} |
||||||
|
options={{ |
||||||
|
gestureEnabled: false, |
||||||
|
}} |
||||||
|
/> |
||||||
|
<Stack.Screen |
||||||
|
name="EmailLogin" |
||||||
|
component={Screens.EmailLoginScreen} |
||||||
|
options={{ |
||||||
|
presentation: "modal", |
||||||
|
animation: "slide_from_bottom", |
||||||
|
gestureEnabled: true, |
||||||
|
gestureDirection: "vertical", |
||||||
|
}} |
||||||
|
/> |
||||||
|
<Stack.Screen |
||||||
|
name="Search" |
||||||
|
component={Screens.SearchScreen} |
||||||
|
options={{ |
||||||
|
presentation: "fullScreenModal", |
||||||
|
animation: "fade", |
||||||
|
animationDuration: 200, |
||||||
|
gestureEnabled: true, |
||||||
|
gestureDirection: "vertical", |
||||||
|
contentStyle: { backgroundColor: "#ffffff" }, |
||||||
|
}} |
||||||
|
/> |
||||||
|
<Stack.Screen |
||||||
|
name="SearchResult" |
||||||
|
component={Screens.SearchResultScreen} |
||||||
|
options={{ |
||||||
|
animation: "slide_from_right", |
||||||
|
gestureEnabled: true, |
||||||
|
gestureDirection: "horizontal", |
||||||
|
}} |
||||||
|
/> |
||||||
|
<Stack.Screen |
||||||
|
name="ProductDetail" |
||||||
|
component={Screens.ProductDetailScreen} |
||||||
|
options={{ |
||||||
|
animation: "slide_from_right", |
||||||
|
gestureEnabled: true, |
||||||
|
gestureDirection: "horizontal", |
||||||
|
}} |
||||||
|
/> |
||||||
|
<Stack.Screen |
||||||
|
name="Balance" |
||||||
|
component={Screens.BalanceScreen} |
||||||
|
options={{ |
||||||
|
animation: "slide_from_right", |
||||||
|
gestureEnabled: true, |
||||||
|
gestureDirection: "horizontal", |
||||||
|
}} |
||||||
|
/> |
||||||
|
<Stack.Screen |
||||||
|
name="ShippingDetailsSection" |
||||||
|
component={Screens.ShippingDetailsSection} |
||||||
|
options={{ |
||||||
|
animation: "slide_from_right", |
||||||
|
gestureEnabled: true, |
||||||
|
gestureDirection: "horizontal", |
||||||
|
}} |
||||||
|
/> |
||||||
|
<Stack.Screen |
||||||
|
name="InquiryScreen" |
||||||
|
component={Screens.InquiryScreen} |
||||||
|
options={{ |
||||||
|
animation: "slide_from_right", |
||||||
|
gestureEnabled: true, |
||||||
|
gestureDirection: "horizontal", |
||||||
|
}} |
||||||
|
/> |
||||||
|
<Stack.Screen |
||||||
|
name="Recipient" |
||||||
|
component={Screens.Recipient} |
||||||
|
options={{ |
||||||
|
animation: "slide_from_right", |
||||||
|
gestureEnabled: true, |
||||||
|
gestureDirection: "horizontal", |
||||||
|
}} |
||||||
|
/> |
||||||
|
<Stack.Screen |
||||||
|
name="AddRess" |
||||||
|
component={Screens.AddRess} |
||||||
|
options={{ |
||||||
|
animation: "slide_from_right", |
||||||
|
gestureEnabled: true, |
||||||
|
gestureDirection: "horizontal", |
||||||
|
}} |
||||||
|
/> |
||||||
|
<Stack.Screen |
||||||
|
name="SettingList" |
||||||
|
component={Screens.SettingList} |
||||||
|
options={{ |
||||||
|
animation: "slide_from_right", |
||||||
|
gestureEnabled: true, |
||||||
|
gestureDirection: "horizontal", |
||||||
|
}} |
||||||
|
/> |
||||||
|
<Stack.Screen |
||||||
|
name="CountrySetting" |
||||||
|
component={Screens.CountrySetting} |
||||||
|
options={{ |
||||||
|
animation: "slide_from_right", |
||||||
|
gestureEnabled: true, |
||||||
|
gestureDirection: "horizontal", |
||||||
|
}} |
||||||
|
/> |
||||||
|
<Stack.Screen |
||||||
|
name="MyAddress" |
||||||
|
component={Screens.MyAddress} |
||||||
|
options={{ |
||||||
|
animation: "slide_from_right", |
||||||
|
gestureEnabled: true, |
||||||
|
gestureDirection: "horizontal", |
||||||
|
}} |
||||||
|
/> |
||||||
|
<Stack.Screen |
||||||
|
name="CartScreen" |
||||||
|
component={Screens.CartScreen} |
||||||
|
options={{ |
||||||
|
animation: "slide_from_right", |
||||||
|
gestureEnabled: true, |
||||||
|
gestureDirection: "horizontal", |
||||||
|
}} |
||||||
|
/> |
||||||
|
<Stack.Screen |
||||||
|
name="PaymentSuccessScreen" |
||||||
|
component={Screens.PaymentSuccessScreen} |
||||||
|
options={{ |
||||||
|
animation: "slide_from_right", |
||||||
|
gestureEnabled: true, |
||||||
|
gestureDirection: "horizontal", |
||||||
|
}} |
||||||
|
/> |
||||||
|
<Stack.Screen |
||||||
|
name="MyAccount" |
||||||
|
component={Screens.MyAccount} |
||||||
|
options={{ |
||||||
|
animation: "slide_from_right", |
||||||
|
gestureEnabled: true, |
||||||
|
gestureDirection: "horizontal", |
||||||
|
}} |
||||||
|
/> |
||||||
|
<Stack.Screen |
||||||
|
name="Google" |
||||||
|
component={Screens.GoogleScreen} |
||||||
|
options={{ |
||||||
|
animation: "slide_from_right", |
||||||
|
gestureEnabled: true, |
||||||
|
gestureDirection: "horizontal", |
||||||
|
}} |
||||||
|
/> |
||||||
|
<Stack.Screen |
||||||
|
name="ConfirmOrder" |
||||||
|
component={Screens.ConfirmOrder} |
||||||
|
options={{ |
||||||
|
animation: "slide_from_right", |
||||||
|
gestureEnabled: true, |
||||||
|
gestureDirection: "horizontal", |
||||||
|
}} |
||||||
|
/> |
||||||
|
<Stack.Screen |
||||||
|
name="Pay" |
||||||
|
component={Screens.Pay} |
||||||
|
options={{ |
||||||
|
animation: "slide_from_right", |
||||||
|
gestureEnabled: true, |
||||||
|
gestureDirection: "horizontal", |
||||||
|
}} |
||||||
|
/> |
||||||
|
<Stack.Screen |
||||||
|
name="Status" |
||||||
|
component={Screens.Status} |
||||||
|
options={{ |
||||||
|
animation: "slide_from_right", |
||||||
|
gestureEnabled: true, |
||||||
|
gestureDirection: "horizontal", |
||||||
|
}} |
||||||
|
/> |
||||||
|
<Stack.Screen |
||||||
|
name="OrderDetails" |
||||||
|
component={Screens.OrderDetails} |
||||||
|
options={{ |
||||||
|
animation: "slide_from_right", |
||||||
|
gestureEnabled: true, |
||||||
|
gestureDirection: "horizontal", |
||||||
|
}} |
||||||
|
/> |
||||||
|
<Stack.Screen |
||||||
|
name="TikTokScreen" |
||||||
|
component={Screens.TikTokScreen} |
||||||
|
options={{ |
||||||
|
animation: "slide_from_right", |
||||||
|
gestureEnabled: true, |
||||||
|
gestureDirection: "horizontal", |
||||||
|
}} |
||||||
|
/> |
||||||
|
<Stack.Screen |
||||||
|
name="BrowseHistoryScreen" |
||||||
|
component={Screens.BrowseHistoryScreen} |
||||||
|
options={{ |
||||||
|
animation: "slide_from_right", |
||||||
|
gestureEnabled: true, |
||||||
|
gestureDirection: "horizontal", |
||||||
|
}} |
||||||
|
/> |
||||||
|
<Stack.Screen |
||||||
|
name="Collection" |
||||||
|
component={Screens.Collection} |
||||||
|
options={{ |
||||||
|
animation: "slide_from_right", |
||||||
|
gestureEnabled: true, |
||||||
|
gestureDirection: "horizontal", |
||||||
|
}} |
||||||
|
/> |
||||||
|
<Stack.Screen |
||||||
|
name="MemberIntroduction" |
||||||
|
component={Screens.MemberIntroduction} |
||||||
|
options={{ |
||||||
|
animation: "slide_from_right", |
||||||
|
gestureEnabled: true, |
||||||
|
gestureDirection: "horizontal", |
||||||
|
}} |
||||||
|
/> |
||||||
|
<Stack.Screen |
||||||
|
name="CompanyScreen" |
||||||
|
component={Screens.CompanyScreen} |
||||||
|
options={{ |
||||||
|
animation: "slide_from_right", |
||||||
|
gestureEnabled: true, |
||||||
|
gestureDirection: "horizontal", |
||||||
|
}} |
||||||
|
/> |
||||||
|
<Stack.Screen |
||||||
|
name="PreviewAddress" |
||||||
|
component={Screens.PreviewAddress} |
||||||
|
options={{ |
||||||
|
animation: "slide_from_right", |
||||||
|
gestureEnabled: true, |
||||||
|
gestureDirection: "horizontal", |
||||||
|
}} |
||||||
|
/> |
||||||
|
<Stack.Screen |
||||||
|
name="AddressList" |
||||||
|
component={Screens.AddressList} |
||||||
|
options={{ |
||||||
|
animation: "slide_from_right", |
||||||
|
gestureEnabled: true, |
||||||
|
gestureDirection: "horizontal", |
||||||
|
}} |
||||||
|
/> |
||||||
|
<Stack.Screen |
||||||
|
name="AddAddress" |
||||||
|
component={Screens.AddAddress} |
||||||
|
options={{ |
||||||
|
animation: "slide_from_right", |
||||||
|
gestureEnabled: true, |
||||||
|
gestureDirection: "horizontal", |
||||||
|
}} |
||||||
|
/> |
||||||
|
<Stack.Screen |
||||||
|
name="EditAddress" |
||||||
|
component={Screens.EditAddress} |
||||||
|
options={{ |
||||||
|
animation: "slide_from_right", |
||||||
|
gestureEnabled: true, |
||||||
|
gestureDirection: "horizontal", |
||||||
|
}} |
||||||
|
/> |
||||||
|
<Stack.Screen |
||||||
|
name="PaymentMethod" |
||||||
|
component={Screens.PaymentMethod} |
||||||
|
options={{ |
||||||
|
animation: "slide_from_right", |
||||||
|
gestureEnabled: true, |
||||||
|
gestureDirection: "horizontal", |
||||||
|
}} |
||||||
|
/> |
||||||
|
<Stack.Screen |
||||||
|
name="ShippingFee" |
||||||
|
component={Screens.ShippingFee} |
||||||
|
options={{ |
||||||
|
animation: "slide_from_right", |
||||||
|
gestureEnabled: true, |
||||||
|
gestureDirection: "horizontal", |
||||||
|
}} |
||||||
|
/> |
||||||
|
<Stack.Screen |
||||||
|
name="PreviewOrder" |
||||||
|
component={Screens.PreviewOrder} |
||||||
|
options={{ |
||||||
|
animation: "slide_from_right", |
||||||
|
gestureEnabled: true, |
||||||
|
gestureDirection: "horizontal", |
||||||
|
}} |
||||||
|
/> |
||||||
|
<Stack.Screen |
||||||
|
name="ForgotPhonePassword" |
||||||
|
component={Screens.ForgotPhonePassword} |
||||||
|
options={{ |
||||||
|
animation: "slide_from_right", |
||||||
|
gestureEnabled: true, |
||||||
|
gestureDirection: "horizontal", |
||||||
|
}} |
||||||
|
/> |
||||||
|
</Stack.Navigator> |
||||||
|
<Toast /> |
||||||
|
</NavigationContainer> |
||||||
|
); |
||||||
|
};
|
@ -0,0 +1,77 @@ |
|||||||
|
import { CountrySelect } from "../screens/CountrySelect"; |
||||||
|
import { MainApp } from "../screens/MainApp"; |
||||||
|
import { LoginScreen } from "../screens/loginList/index"; |
||||||
|
import { EmailLoginScreen } from "../screens/EmailLoginScreen"; |
||||||
|
import { TabNavigator } from "./TabNavigator"; |
||||||
|
import { SearchScreen } from "../screens/SearchScreen"; |
||||||
|
import { SearchResultScreen } from "../screens/SearchResultScreen"; |
||||||
|
import { ProductDetailScreen } from "../screens/ProductDetailScreen"; |
||||||
|
import { BalanceScreen } from "../screens/BalanceScreen"; |
||||||
|
import { ShippingDetailsSection } from "../screens/banner/ShippingDetailsSection"; |
||||||
|
import { InquiryScreen } from "../screens/banner/InquiryScreen"; |
||||||
|
import { Recipient } from "../screens/Recipient/Recipient"; |
||||||
|
import { AddRess } from "../screens/Recipient/Address"; |
||||||
|
import { SettingList } from "../screens/setting/SettingList"; |
||||||
|
import { CountrySetting } from "../screens/setting/CountrySetting"; |
||||||
|
import { MyAddress } from "../screens/setting/MyAddress"; |
||||||
|
import { CartScreen } from "../screens/CartScreen"; |
||||||
|
import { PaymentSuccessScreen } from "../screens/pay/PaySuccess"; |
||||||
|
import { MyAccount } from "../screens/MyAccount/myAccount"; |
||||||
|
import { GoogleScreen } from "../screens/login/Google"; |
||||||
|
import { ConfirmOrder } from "../screens/Recipient/ConfirmOrder"; |
||||||
|
import { Pay } from "../screens/pay/Pay"; |
||||||
|
import { Status } from "../screens/productStatus/Status"; |
||||||
|
import { OrderDetails } from "../screens/productStatus/OrderDatails"; |
||||||
|
import { TikTokScreen } from "../screens/banner/TikTokScreen"; |
||||||
|
import { BrowseHistoryScreen } from "../screens/function/BrowseHistoryScreen"; |
||||||
|
import { Collection } from "../screens/function/Collection"; |
||||||
|
import { MemberIntroduction } from "../screens/MemberScreen/MemberIntroduction"; |
||||||
|
import { CompanyScreen } from "../screens/MemberScreen/CompanyScreen"; |
||||||
|
import { PreviewAddress } from "../screens/previewOrder/PreviewAddress"; |
||||||
|
import { AddressList } from "../screens/address/AddressList"; |
||||||
|
import { AddAddress } from "../screens/address/AddAddress"; |
||||||
|
import { EditAddress } from "../screens/address/EditAddress"; |
||||||
|
import { PaymentMethod } from "../screens/previewOrder/PaymentMethod"; |
||||||
|
import { ShippingFee } from "../screens/previewOrder/ShippingFee"; |
||||||
|
import { PreviewOrder } from "../screens/previewOrder/perviewOrder"; |
||||||
|
import { ForgotPhonePassword } from "../screens/loginList/ForgotPhonePassword"; |
||||||
|
|
||||||
|
export { |
||||||
|
CountrySelect, |
||||||
|
MainApp, |
||||||
|
LoginScreen, |
||||||
|
EmailLoginScreen, |
||||||
|
TabNavigator, |
||||||
|
SearchScreen, |
||||||
|
SearchResultScreen, |
||||||
|
ProductDetailScreen, |
||||||
|
BalanceScreen, |
||||||
|
ShippingDetailsSection, |
||||||
|
InquiryScreen, |
||||||
|
Recipient, |
||||||
|
AddRess, |
||||||
|
SettingList, |
||||||
|
CountrySetting, |
||||||
|
MyAddress, |
||||||
|
CartScreen, |
||||||
|
PaymentSuccessScreen, |
||||||
|
MyAccount, |
||||||
|
GoogleScreen, |
||||||
|
ConfirmOrder, |
||||||
|
Pay, |
||||||
|
Status, |
||||||
|
OrderDetails, |
||||||
|
TikTokScreen, |
||||||
|
BrowseHistoryScreen, |
||||||
|
Collection, |
||||||
|
MemberIntroduction, |
||||||
|
CompanyScreen, |
||||||
|
PreviewAddress, |
||||||
|
AddressList, |
||||||
|
AddAddress, |
||||||
|
EditAddress, |
||||||
|
PaymentMethod, |
||||||
|
ShippingFee, |
||||||
|
PreviewOrder, |
||||||
|
ForgotPhonePassword |
||||||
|
};
|
@ -1,15 +1,41 @@ |
|||||||
import { MySetting } from '../services/api/setting'; |
import { MySetting } from '../services/api/setting'; |
||||||
|
|
||||||
export type RootStackParamList = { |
export type RootStackParamList = { |
||||||
Login: undefined; |
|
||||||
EmailLogin: undefined; |
|
||||||
CountrySelect: undefined; |
CountrySelect: undefined; |
||||||
MainApp: undefined; |
MainApp: undefined; |
||||||
|
Login: undefined; |
||||||
|
EmailLogin: undefined; |
||||||
MainTabs: undefined; |
MainTabs: undefined; |
||||||
|
Search: undefined; |
||||||
|
SearchResult: { keyword: string }; |
||||||
|
ProductDetail: { productId: string; searchKeyword?: string }; |
||||||
Balance: undefined; |
Balance: undefined; |
||||||
Recipient: undefined; |
ShippingDetailsSection: undefined; |
||||||
|
InquiryScreen: undefined; |
||||||
|
Recipient: { items: { cart_item_id: number }[] }; |
||||||
|
AddRess: undefined; |
||||||
SettingList: undefined; |
SettingList: undefined; |
||||||
CountrySetting: { mySetting?: MySetting | undefined }; |
CountrySetting: { mySetting?: MySetting }; |
||||||
MyAddress: undefined; |
MyAddress: undefined; |
||||||
|
CartScreen: undefined; |
||||||
|
PaymentSuccessScreen: undefined; |
||||||
MyAccount: undefined; |
MyAccount: undefined; |
||||||
|
Google: undefined; |
||||||
|
ConfirmOrder: undefined; |
||||||
|
Pay: undefined; |
||||||
|
Status: undefined; |
||||||
|
OrderDetails: undefined; |
||||||
|
TikTokScreen: undefined; |
||||||
|
BrowseHistoryScreen: undefined; |
||||||
|
Collection: undefined; |
||||||
|
MemberIntroduction: undefined; |
||||||
|
CompanyScreen: undefined; |
||||||
|
PreviewAddress: undefined; |
||||||
|
AddressList: undefined; |
||||||
|
AddAddress: undefined; |
||||||
|
EditAddress: undefined; |
||||||
|
PaymentMethod: undefined; |
||||||
|
ShippingFee: undefined; |
||||||
|
PreviewOrder: undefined; |
||||||
|
ForgotPhonePassword: undefined; |
||||||
}; |
}; |
||||||
|
@ -0,0 +1,325 @@ |
|||||||
|
import { Platform } from "react-native"; |
||||||
|
import { create } from 'zustand'; |
||||||
|
import useUserStore from "./user"; |
||||||
|
|
||||||
|
// 定义事件属性类型为灵活的记录类型
|
||||||
|
type EventProperty = Record<string, any>; |
||||||
|
|
||||||
|
// 定义事件类型
|
||||||
|
type BurialEvent = { |
||||||
|
event_name: string; |
||||||
|
page_name: string | null; |
||||||
|
referre_page: string | null; // 注意这里字段名已更正为referre_page
|
||||||
|
event_properties: EventProperty[]; |
||||||
|
} |
||||||
|
|
||||||
|
// 定义产品属性类型
|
||||||
|
type ProductProperty = { |
||||||
|
offer_id: number; |
||||||
|
category_id: number; |
||||||
|
price: number; |
||||||
|
sku_id: number; |
||||||
|
currency: string; |
||||||
|
product_name: string; |
||||||
|
timestamp: string; |
||||||
|
product_img: string; |
||||||
|
} |
||||||
|
|
||||||
|
// 定义搜索属性类型
|
||||||
|
type SearchProperty = { |
||||||
|
key_word: string; |
||||||
|
timestamp: string; |
||||||
|
} |
||||||
|
|
||||||
|
// 定义地址信息属性类型
|
||||||
|
type AddressProperty = { |
||||||
|
last_name: string; |
||||||
|
first_name: string; |
||||||
|
country: string; |
||||||
|
phone_number: number; |
||||||
|
whatsApp_number: number; |
||||||
|
timestamp: string; |
||||||
|
} |
||||||
|
|
||||||
|
// 定义物流信息属性类型
|
||||||
|
type ShippingProperty = { |
||||||
|
shipping_method: number; |
||||||
|
shipping_price_outside: number; |
||||||
|
shipping_price_within: number; |
||||||
|
currency: string; |
||||||
|
forwarder_name: string; |
||||||
|
country_city: string; |
||||||
|
timestamp: string; |
||||||
|
product_list_text?: string; |
||||||
|
} |
||||||
|
|
||||||
|
// 定义支付方式属性类型
|
||||||
|
type PaymentProperty = { |
||||||
|
pay_method: string; |
||||||
|
offline_payment: number; |
||||||
|
all_price: number; |
||||||
|
currency: string; |
||||||
|
pay_product?: string; |
||||||
|
shipping_method: number; |
||||||
|
shipping_price_outside: number; |
||||||
|
shipping_price_within: number; |
||||||
|
timestamp: string; |
||||||
|
} |
||||||
|
|
||||||
|
// 定义支付结账属性类型
|
||||||
|
type CheckoutProperty = { |
||||||
|
is_suc: number; |
||||||
|
all_price: number; |
||||||
|
currency: string; |
||||||
|
shipping_method: number; |
||||||
|
shipping_price_outside: number; |
||||||
|
shipping_price_within: number; |
||||||
|
pay_product?: string; |
||||||
|
timestamp: string; |
||||||
|
} |
||||||
|
|
||||||
|
// 生成唯一ID函数,替代md5
|
||||||
|
const generateUniqueId = () => { |
||||||
|
return `${Date.now()}-${Math.random().toString(36).substr(2, 9)}`; |
||||||
|
}; |
||||||
|
|
||||||
|
// 创建唯一的session_id
|
||||||
|
const SESSION_ID = generateUniqueId(); |
||||||
|
|
||||||
|
// 定义埋点store的状态
|
||||||
|
type BurialPointState = { |
||||||
|
device_id: string; |
||||||
|
version: string; |
||||||
|
session_id: string; |
||||||
|
event_list: BurialEvent[]; |
||||||
|
addEvent: (event: BurialEvent) => void; |
||||||
|
logAppLaunch: (isSuccess?: boolean) => void; |
||||||
|
logLogin: (isSuccess: boolean, loginMethod: string) => void; |
||||||
|
logRegister: (isSuccess: boolean, registerMethod: string) => void; |
||||||
|
logViewProduct: (productInfo: ProductProperty, fromPage?: string) => void; |
||||||
|
logSearch: (keyword: string, fromPage?: string) => void; |
||||||
|
logAddressInfo: (addressInfo: Omit<AddressProperty, "timestamp">, fromPage?: string) => void; |
||||||
|
logShippingConfirm: (shippingInfo: Omit<ShippingProperty, "timestamp">, fromPage?: string) => void; |
||||||
|
logPaymentConfirm: (paymentInfo: Omit<PaymentProperty, "timestamp">, fromPage?: string) => void; |
||||||
|
logPreviewOrder: (fromPage?: string) => void; |
||||||
|
logCheckout: (checkoutInfo: Omit<CheckoutProperty, "timestamp">, fromPage?: string) => void; |
||||||
|
clearData: () => void; |
||||||
|
} |
||||||
|
|
||||||
|
// 获取当前格式化的时间字符串 YYYY-MM-DD HH:MM:SS
|
||||||
|
const getCurrentFormattedTime = (): string => { |
||||||
|
return new Date().toISOString().replace('T', ' ').substr(0, 19); |
||||||
|
}; |
||||||
|
|
||||||
|
// 创建埋点store
|
||||||
|
const useBurialPointStore = create<BurialPointState>((set, get) => ({ |
||||||
|
device_id: Platform.OS, |
||||||
|
version: generateUniqueId(), |
||||||
|
session_id: SESSION_ID, |
||||||
|
event_list: [], |
||||||
|
|
||||||
|
// 添加事件
|
||||||
|
addEvent: (event: BurialEvent) => { |
||||||
|
set((state) => { |
||||||
|
const newEventList = [...state.event_list, event]; |
||||||
|
|
||||||
|
// 检查是否需要清理数据
|
||||||
|
if (newEventList.length >= 10) { |
||||||
|
// 这里可以在清理前添加发送数据到服务器的逻辑
|
||||||
|
console.log('Data cleared, event count:', newEventList.length); |
||||||
|
return { event_list: [] }; |
||||||
|
} |
||||||
|
|
||||||
|
return { event_list: newEventList }; |
||||||
|
}); |
||||||
|
}, |
||||||
|
|
||||||
|
// 记录应用启动埋点
|
||||||
|
logAppLaunch: (isSuccess = true) => { |
||||||
|
const appLaunchEvent: BurialEvent = { |
||||||
|
event_name: "app_launch", |
||||||
|
page_name: null, |
||||||
|
referre_page: null, |
||||||
|
event_properties: [ |
||||||
|
{ |
||||||
|
is_open: isSuccess ? 1 : 0, // 1表示成功,0表示失败
|
||||||
|
timestamp: getCurrentFormattedTime() |
||||||
|
} |
||||||
|
] |
||||||
|
}; |
||||||
|
|
||||||
|
get().addEvent(appLaunchEvent); |
||||||
|
}, |
||||||
|
|
||||||
|
// 记录登录事件埋点
|
||||||
|
logLogin: (isSuccess = true, loginMethod = "phone") => { |
||||||
|
const loginEvent: BurialEvent = { |
||||||
|
event_name: "login", |
||||||
|
page_name: null, |
||||||
|
referre_page: null, |
||||||
|
event_properties: [ |
||||||
|
{ |
||||||
|
is_login: isSuccess ? 1 : 0, // 1表示成功,0表示失败
|
||||||
|
login_method: loginMethod, // 登录方式
|
||||||
|
timestamp: getCurrentFormattedTime() |
||||||
|
} |
||||||
|
] |
||||||
|
}; |
||||||
|
|
||||||
|
get().addEvent(loginEvent); |
||||||
|
}, |
||||||
|
|
||||||
|
// 记录注册事件埋点
|
||||||
|
logRegister: (isSuccess = true, registerMethod = "phone") => { |
||||||
|
const registerEvent: BurialEvent = { |
||||||
|
event_name: "register", |
||||||
|
page_name: null, |
||||||
|
referre_page: null, |
||||||
|
event_properties: [ |
||||||
|
{ |
||||||
|
is_register: isSuccess ? 1 : 0, // 1表示成功,0表示失败
|
||||||
|
register_method: registerMethod, // 注册方式
|
||||||
|
timestamp: getCurrentFormattedTime() |
||||||
|
} |
||||||
|
] |
||||||
|
}; |
||||||
|
|
||||||
|
get().addEvent(registerEvent); |
||||||
|
}, |
||||||
|
|
||||||
|
// 记录浏览商品事件埋点
|
||||||
|
logViewProduct: (productInfo: ProductProperty, fromPage = "home") => { |
||||||
|
const viewProductEvent: BurialEvent = { |
||||||
|
event_name: "view-product", |
||||||
|
page_name: "product", |
||||||
|
referre_page: fromPage, |
||||||
|
event_properties: [productInfo] |
||||||
|
}; |
||||||
|
|
||||||
|
get().addEvent(viewProductEvent); |
||||||
|
}, |
||||||
|
|
||||||
|
// 记录搜索事件埋点
|
||||||
|
logSearch: (keyword: string, fromPage = "home") => { |
||||||
|
const searchEvent: BurialEvent = { |
||||||
|
event_name: "search", |
||||||
|
page_name: "search", |
||||||
|
referre_page: fromPage, |
||||||
|
event_properties: [ |
||||||
|
{ |
||||||
|
key_word: keyword, |
||||||
|
timestamp: getCurrentFormattedTime() |
||||||
|
} |
||||||
|
] |
||||||
|
}; |
||||||
|
|
||||||
|
get().addEvent(searchEvent); |
||||||
|
}, |
||||||
|
|
||||||
|
// 记录填写地址信息事件埋点
|
||||||
|
logAddressInfo: (addressInfo: Omit<AddressProperty, "timestamp">, fromPage = "cart") => { |
||||||
|
const addressEvent: BurialEvent = { |
||||||
|
event_name: "fill_information", |
||||||
|
page_name: "address", |
||||||
|
referre_page: fromPage, |
||||||
|
event_properties: [ |
||||||
|
{ |
||||||
|
...addressInfo, |
||||||
|
timestamp: getCurrentFormattedTime() |
||||||
|
} |
||||||
|
] |
||||||
|
}; |
||||||
|
|
||||||
|
get().addEvent(addressEvent); |
||||||
|
}, |
||||||
|
|
||||||
|
// 记录物流信息确认事件埋点
|
||||||
|
logShippingConfirm: (shippingInfo: Omit<ShippingProperty, "timestamp">, fromPage = "address") => { |
||||||
|
const shippingEvent: BurialEvent = { |
||||||
|
event_name: "shipping_confirm", |
||||||
|
page_name: "shipping", |
||||||
|
referre_page: fromPage, |
||||||
|
event_properties: [ |
||||||
|
{ |
||||||
|
...shippingInfo, |
||||||
|
timestamp: getCurrentFormattedTime() |
||||||
|
} |
||||||
|
] |
||||||
|
}; |
||||||
|
|
||||||
|
get().addEvent(shippingEvent); |
||||||
|
}, |
||||||
|
|
||||||
|
// 记录支付方式确认事件埋点
|
||||||
|
logPaymentConfirm: (paymentInfo: Omit<PaymentProperty, "timestamp">, fromPage = "shipping") => { |
||||||
|
const paymentEvent: BurialEvent = { |
||||||
|
event_name: "payment_confirm", |
||||||
|
page_name: "pay_method", |
||||||
|
referre_page: fromPage, |
||||||
|
event_properties: [ |
||||||
|
{ |
||||||
|
...paymentInfo, |
||||||
|
timestamp: getCurrentFormattedTime() |
||||||
|
} |
||||||
|
] |
||||||
|
}; |
||||||
|
|
||||||
|
get().addEvent(paymentEvent); |
||||||
|
}, |
||||||
|
|
||||||
|
// 记录预览订单事件埋点
|
||||||
|
logPreviewOrder: (fromPage = "pay_method") => { |
||||||
|
const previewEvent: BurialEvent = { |
||||||
|
event_name: "preview_order", |
||||||
|
page_name: "preview", |
||||||
|
referre_page: fromPage, |
||||||
|
event_properties: [ |
||||||
|
{ |
||||||
|
timestamp: getCurrentFormattedTime() |
||||||
|
} |
||||||
|
] |
||||||
|
}; |
||||||
|
|
||||||
|
get().addEvent(previewEvent); |
||||||
|
}, |
||||||
|
|
||||||
|
// 记录支付结账事件埋点
|
||||||
|
logCheckout: (checkoutInfo: Omit<CheckoutProperty, "timestamp">, fromPage = "perview") => { |
||||||
|
const checkoutEvent: BurialEvent = { |
||||||
|
event_name: "check_out", |
||||||
|
page_name: "pay", |
||||||
|
referre_page: fromPage, |
||||||
|
event_properties: [ |
||||||
|
{ |
||||||
|
...checkoutInfo, |
||||||
|
timestamp: getCurrentFormattedTime() |
||||||
|
} |
||||||
|
] |
||||||
|
}; |
||||||
|
|
||||||
|
get().addEvent(checkoutEvent); |
||||||
|
}, |
||||||
|
|
||||||
|
// 清空数据
|
||||||
|
clearData: () => { |
||||||
|
// 这里可以添加发送数据到服务器的逻辑
|
||||||
|
console.log('Data cleared, event count:', get().event_list.length); |
||||||
|
set({ event_list: [] }); |
||||||
|
} |
||||||
|
})); |
||||||
|
|
||||||
|
// 获取埋点数据,包括从userStore获取的user_id
|
||||||
|
export const getBurialPointData = () => { |
||||||
|
const burialState = useBurialPointStore.getState(); |
||||||
|
const user = useUserStore.getState().user; |
||||||
|
|
||||||
|
return { |
||||||
|
user_id: user?.user_id || null, |
||||||
|
device_id: burialState.device_id, |
||||||
|
version: burialState.version, |
||||||
|
session_id: burialState.session_id, |
||||||
|
event_list: burialState.event_list |
||||||
|
}; |
||||||
|
}; |
||||||
|
|
||||||
|
export default useBurialPointStore;
|
@ -0,0 +1,3 @@ |
|||||||
|
declare module 'react-native-md5' { |
||||||
|
export function md5(str: string): string; |
||||||
|
}
|
Loading…
Reference in new issue