Parcourir la source

fix: delay version logging & prevent duplicates (#2770)

David Luzar il y a 4 ans
Parent
commit
adcd28f348
2 fichiers modifiés avec 17 ajouts et 3 suppressions
  1. 13 1
      src/excalidraw-app/index.tsx
  2. 4 2
      src/utils.ts

+ 13 - 1
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,

+ 4 - 2
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<HTMLMetaElement>('meta[name="version"]')?.content ||
+    DEFAULT_VERSION
+  );
 };