adjust analytics to wait for server before track

This commit is contained in:
jeffvli
2025-12-30 13:59:52 -08:00
parent 3ee92b068b
commit 62183ecb58
@@ -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) {