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

This commit is contained in:
David Luzar 2021-01-12 17:47:31 +01:00 committed by GitHub
parent 62f1ed74f1
commit adcd28f348
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 3 deletions

View File

@ -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,

View File

@ -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
);
};