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