diff --git a/src/excalidraw-app/index.tsx b/src/excalidraw-app/index.tsx index d63eb71b..9dbdf544 100644 --- a/src/excalidraw-app/index.tsx +++ b/src/excalidraw-app/index.tsx @@ -229,7 +229,19 @@ function ExcalidrawWrapper(props: { collab: CollabAPI }) { const { collab } = props; useEffect(() => { - trackEvent("load", "version", getVersion()); + // delayed by 15 sec so that the app has a time to load the latest SW + setTimeout(() => { + const version = getVersion(); + const loggedVersion = window.localStorage.getItem( + "excalidraw-lastLoggedVersion", + ); + // prevent logging on multiple visits + if (version && version !== loggedVersion) { + window.localStorage.setItem("excalidraw-lastLoggedVersion", version); + trackEvent("load", "version", version); + } + }, 15000); + excalidrawRef.current!.readyPromise.then((excalidrawApi) => { initializeScene({ resetScene: excalidrawApi.resetScene, diff --git a/src/utils.ts b/src/utils.ts index 933765c2..936b2850 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -364,6 +364,8 @@ export const nFormatter = (num: number, digits: number): string => { }; export const getVersion = () => { - const version = document.querySelector('meta[name="version"]'); - return version ? (version as any).content : DEFAULT_VERSION; + return ( + document.querySelector('meta[name="version"]')?.content || + DEFAULT_VERSION + ); };