mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-09 20:29:36 +02:00
adjust analytics to wait for server before track
This commit is contained in:
@@ -208,8 +208,21 @@ const getSettingsProperties = (): SettingsProperties => {
|
|||||||
|
|
||||||
const getServer = (): 'unknown' | ServerType => {
|
const getServer = (): 'unknown' | ServerType => {
|
||||||
const auth = useAuthStore.getState();
|
const auth = useAuthStore.getState();
|
||||||
|
|
||||||
const currentServer = auth.currentServer;
|
const currentServer = auth.currentServer;
|
||||||
return currentServer?.type || 'unknown';
|
|
||||||
|
if (currentServer) {
|
||||||
|
return currentServer.type;
|
||||||
|
}
|
||||||
|
|
||||||
|
const serverList = auth.serverList;
|
||||||
|
const server = Object.values(serverList)[0];
|
||||||
|
|
||||||
|
if (server) {
|
||||||
|
return server.type;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 'unknown';
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useAppTracker = () => {
|
export const useAppTracker = () => {
|
||||||
@@ -222,6 +235,18 @@ export const useAppTracker = () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const waitForServer = async (): Promise<void> => {
|
||||||
|
if (useAuthStore.getState().currentServer) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const pollInterval = 1000 * 60;
|
||||||
|
|
||||||
|
while (!useAuthStore.getState().currentServer) {
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, pollInterval));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const getProperties = () => {
|
const getProperties = () => {
|
||||||
const platform = getPlatform();
|
const platform = getPlatform();
|
||||||
const version = getVersion();
|
const version = getVersion();
|
||||||
@@ -285,8 +310,10 @@ export const useAppTracker = () => {
|
|||||||
|
|
||||||
// Check immediately on mount
|
// Check immediately on mount
|
||||||
if (!hasRunOnMountRef.current) {
|
if (!hasRunOnMountRef.current) {
|
||||||
|
waitForServer().then(() => {
|
||||||
|
checkAndTrack();
|
||||||
|
});
|
||||||
hasRunOnMountRef.current = true;
|
hasRunOnMountRef.current = true;
|
||||||
checkAndTrack();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const interval = setInterval(checkAndTrack, 1000 * 60 * 60);
|
const interval = setInterval(checkAndTrack, 1000 * 60 * 60);
|
||||||
@@ -300,9 +327,11 @@ const appTrackerMutation = mutationOptions({
|
|||||||
mutationFn: (properties: AppTrackerProperties) => {
|
mutationFn: (properties: AppTrackerProperties) => {
|
||||||
try {
|
try {
|
||||||
window.umami?.track((props) => ({
|
window.umami?.track((props) => ({
|
||||||
...props,
|
|
||||||
data: properties,
|
data: properties,
|
||||||
|
language: props.language,
|
||||||
name: 'app',
|
name: 'app',
|
||||||
|
screen: props.screen,
|
||||||
|
website: props.website,
|
||||||
}));
|
}));
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user