mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-07 12:30:12 +02:00
add page view tracker
This commit is contained in:
@@ -214,6 +214,7 @@ const getServer = (): 'unknown' | ServerType => {
|
||||
|
||||
export const useAppTracker = () => {
|
||||
const { mutate: trackAppMutation } = useMutation(appTrackerMutation);
|
||||
const { mutate: trackAppViewMutation } = useMutation(appViewMutation);
|
||||
const hasRunOnMountRef = useRef(false);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -258,6 +259,10 @@ export const useAppTracker = () => {
|
||||
meta: { properties, todayUTC },
|
||||
});
|
||||
|
||||
trackAppViewMutation(undefined, {
|
||||
onError: () => {},
|
||||
});
|
||||
|
||||
trackAppMutation(properties, {
|
||||
onError: () => {},
|
||||
onSettled: () => {
|
||||
@@ -287,9 +292,10 @@ export const useAppTracker = () => {
|
||||
const interval = setInterval(checkAndTrack, 1000 * 60 * 60);
|
||||
|
||||
return () => clearInterval(interval);
|
||||
}, [trackAppMutation]);
|
||||
}, [trackAppMutation, trackAppViewMutation]);
|
||||
};
|
||||
|
||||
// Sends the app event to the analytics server which includes usage data
|
||||
const appTrackerMutation = mutationOptions({
|
||||
mutationFn: (properties: AppTrackerProperties) => {
|
||||
try {
|
||||
@@ -308,3 +314,24 @@ const appTrackerMutation = mutationOptions({
|
||||
retry: false,
|
||||
throwOnError: false,
|
||||
});
|
||||
|
||||
// Sends a view event to the analytics server which only includes language, screen, and website
|
||||
// and triggers a page view event
|
||||
const appViewMutation = mutationOptions({
|
||||
mutationFn: () => {
|
||||
try {
|
||||
window.umami?.track((props) => ({
|
||||
language: props.language,
|
||||
screen: props.screen,
|
||||
website: props.website,
|
||||
}));
|
||||
return Promise.resolve();
|
||||
} catch (error) {
|
||||
return Promise.reject(error);
|
||||
}
|
||||
},
|
||||
mutationKey: ['analytics', 'app-view'],
|
||||
onSuccess: () => {},
|
||||
retry: false,
|
||||
throwOnError: false,
|
||||
});
|
||||
|
||||
Vendored
+1
@@ -4,6 +4,7 @@ declare global {
|
||||
identify(unique_id: string): void;
|
||||
identify(unique_id: string, data: object): void;
|
||||
identify(data: object): void;
|
||||
track(): void;
|
||||
track(event_name: string, data: object): void;
|
||||
track(
|
||||
callback: (props: {
|
||||
|
||||
Reference in New Issue
Block a user