From 3030e96d623d65d0bcb02c2260de6ab090780ea3 Mon Sep 17 00:00:00 2001 From: Milos Vetesnik Date: Wed, 29 Mar 2023 11:13:06 +0200 Subject: [PATCH 1/3] feat: starting migration from GA to Matomo for better privacy (#6398) Co-authored-by: dwelle --- .env.development | 5 +++++ .env.production | 7 +++++++ public/index.html | 33 ++++++++++++++++++++++++++++-- src/analytics.ts | 52 +++++++++++++++++++++++++++-------------------- src/global.d.ts | 2 ++ src/utils.ts | 6 +----- 6 files changed, 76 insertions(+), 29 deletions(-) diff --git a/.env.development b/.env.development index 397a565656..0c2fb5527c 100644 --- a/.env.development +++ b/.env.development @@ -23,6 +23,11 @@ REACT_APP_DEV_DISABLE_LIVE_RELOAD= FAST_REFRESH=false +# MATOMO +REACT_APP_MATOMO_URL= +REACT_APP_CDN_MATOMO_TRACKER_URL= +REACT_APP_MATOMO_SITE_ID= + #Debug flags # To enable bounding box for text containers diff --git a/.env.production b/.env.production index 183db7ea2a..8737c63c7f 100644 --- a/.env.production +++ b/.env.production @@ -12,6 +12,13 @@ REACT_APP_WS_SERVER_URL= REACT_APP_FIREBASE_CONFIG='{"apiKey":"AIzaSyAd15pYlMci_xIp9ko6wkEsDzAAA0Dn0RU","authDomain":"excalidraw-room-persistence.firebaseapp.com","databaseURL":"https://excalidraw-room-persistence.firebaseio.com","projectId":"excalidraw-room-persistence","storageBucket":"excalidraw-room-persistence.appspot.com","messagingSenderId":"654800341332","appId":"1:654800341332:web:4a692de832b55bd57ce0c1"}' # production-only vars +# GOOGLE ANALYTICS REACT_APP_GOOGLE_ANALYTICS_ID=UA-387204-13 +# MATOMO +REACT_APP_MATOMO_URL=https://excalidraw.matomo.cloud/ +REACT_APP_CDN_MATOMO_TRACKER_URL=//cdn.matomo.cloud/excalidraw.matomo.cloud/matomo.js +REACT_APP_MATOMO_SITE_ID=1 + + REACT_APP_PLUS_APP=https://app.excalidraw.com diff --git a/public/index.html b/public/index.html index 35640c0dcd..47a59624b8 100644 --- a/public/index.html +++ b/public/index.html @@ -146,8 +146,10 @@ // setting this so that libraries installation reuses this window tab. window.name = "_excalidraw"; - <% if (process.env.REACT_APP_DISABLE_TRACKING !== 'true' && - process.env.REACT_APP_GOOGLE_ANALYTICS_ID) { %> + <% if (process.env.REACT_APP_DISABLE_TRACKING !== 'true') { %> + + + <% if (process.env.REACT_APP_GOOGLE_ANALYTICS_ID) { %> + <% } %> + + <% } %> diff --git a/src/analytics.ts b/src/analytics.ts index 668d49c250..1e9a429b62 100644 --- a/src/analytics.ts +++ b/src/analytics.ts @@ -1,22 +1,30 @@ -export const trackEvent = - typeof process !== "undefined" && - process.env?.REACT_APP_GOOGLE_ANALYTICS_ID && - typeof window !== "undefined" && - window.gtag - ? (category: string, action: string, label?: string, value?: number) => { - try { - window.gtag("event", action, { - event_category: category, - event_label: label, - value, - }); - } catch (error) { - console.error("error logging to ga", error); - } - } - : typeof process !== "undefined" && process.env?.JEST_WORKER_ID - ? (category: string, action: string, label?: string, value?: number) => {} - : (category: string, action: string, label?: string, value?: number) => { - // Uncomment the next line to track locally - // console.log("Track Event", { category, action, label, value }); - }; +export const trackEvent = ( + category: string, + action: string, + label?: string, + value?: number, +) => { + try { + // Uncomment the next line to track locally + // console.log("Track Event", { category, action, label, value }); + + if (typeof window === "undefined" || process.env.JEST_WORKER_ID) { + return; + } + + if (process.env.REACT_APP_GOOGLE_ANALYTICS_ID && window.gtag) { + window.gtag("event", action, { + event_category: category, + event_label: label, + value, + }); + } + + // MATOMO event tracking _paq must be same as the one in index.html + if (window._paq) { + window._paq.push(["trackEvent", category, action, label, value]); + } + } catch (error) { + console.error("error during analytics", error); + } +}; diff --git a/src/global.d.ts b/src/global.d.ts index 4a70443d4e..73c8fc8139 100644 --- a/src/global.d.ts +++ b/src/global.d.ts @@ -18,6 +18,8 @@ interface Window { EXCALIDRAW_EXPORT_SOURCE: string; EXCALIDRAW_THROTTLE_RENDER: boolean | undefined; gtag: Function; + _paq: any[]; + _mtm: any[]; } interface CanvasRenderingContext2D { diff --git a/src/utils.ts b/src/utils.ts index 4a01e587d2..1d545f9779 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -689,11 +689,7 @@ export const arrayToMapWithIndex = ( return acc; }, new Map()); -export const isTestEnv = () => - typeof process !== "undefined" && process.env?.NODE_ENV === "test"; - -export const isProdEnv = () => - typeof process !== "undefined" && process.env?.NODE_ENV === "production"; +export const isTestEnv = () => process.env.NODE_ENV === "test"; export const wrapEvent = (name: EVENT, nativeEvent: T) => { return new CustomEvent(name, { From f8e65bb77ee76cf6d623be116fc0a9cd746139a0 Mon Sep 17 00:00:00 2001 From: Aakansha Doshi Date: Wed, 29 Mar 2023 18:53:03 +0530 Subject: [PATCH 2/3] fix: Revert use `ideographic` textBaseline to improve layout shift when editing text" (#6400) Revert "fix: use `ideographic` textBaseline to improve layout shift when editing text (#6384)" This reverts commit 9e52c30ce86d7f7e61ffdb5ecad2523e179f620e. --- src/renderer/renderElement.ts | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/renderer/renderElement.ts b/src/renderer/renderElement.ts index 66d2096cfe..0861315cce 100644 --- a/src/renderer/renderElement.ts +++ b/src/renderer/renderElement.ts @@ -34,7 +34,6 @@ import { AppState, BinaryFiles, Zoom } from "../types"; import { getDefaultAppState } from "../appState"; import { BOUND_TEXT_PADDING, - FONT_FAMILY, MAX_DECIMALS_FOR_SVG_EXPORT, MIME_TYPES, SVG_NS, @@ -287,13 +286,7 @@ const drawElementOnCanvas = ( : element.textAlign === "right" ? element.width : 0; - - // FIXME temporary hack - context.textBaseline = - element.fontFamily === FONT_FAMILY.Virgil || - element.fontFamily === FONT_FAMILY.Cascadia - ? "ideographic" - : "bottom"; + context.textBaseline = "bottom"; const lineHeightPx = getLineHeightInPx( element.fontSize, From d2b8f4d2f8e79fbe2cddfb06afee82c1f95c0118 Mon Sep 17 00:00:00 2001 From: Coyote <46889283+CoyoteWaltz@users.noreply.github.com> Date: Thu, 30 Mar 2023 03:16:23 +0800 Subject: [PATCH 3/3] fix: getDefaultLineHeight should return default font family line height for unknown font (#6399) * fix(getDefaultLineHeight): make getDefaultLineHeight always has a default value * test: add getDefaultLineHeight test case when using unknown font * test: add getDefaultLineHeight test case when using unknown font * Revert "test: add getDefaultLineHeight test case when using unknown font" This reverts commit d41da5493b6edab9e599a13a23c387d38345bf03. * test: add getDefaultLineHeight test case when using unknown font * newline * newline * tweaks * trigger action * trigger action * fix --------- Co-authored-by: Aakansha Doshi --- src/element/textElement.test.ts | 6 ++++++ src/element/textElement.ts | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/element/textElement.test.ts b/src/element/textElement.test.ts index aa7df8ee6a..106ed7beab 100644 --- a/src/element/textElement.test.ts +++ b/src/element/textElement.test.ts @@ -332,6 +332,12 @@ describe("Test getDefaultLineHeight", () => { //@ts-ignore expect(getDefaultLineHeight()).toBe(1.25); }); + + it("should return line height using default font family for unknown font", () => { + const UNKNOWN_FONT = 5; + expect(getDefaultLineHeight(UNKNOWN_FONT)).toBe(1.25); + }); + it("should return correct line height", () => { expect(getDefaultLineHeight(FONT_FAMILY.Cascadia)).toBe(1.2); }); diff --git a/src/element/textElement.ts b/src/element/textElement.ts index fd501c1414..8b3979133e 100644 --- a/src/element/textElement.ts +++ b/src/element/textElement.ts @@ -887,7 +887,7 @@ const DEFAULT_LINE_HEIGHT = { }; export const getDefaultLineHeight = (fontFamily: FontFamilyValues) => { - if (fontFamily) { + if (fontFamily in DEFAULT_LINE_HEIGHT) { return DEFAULT_LINE_HEIGHT[fontFamily]; } return DEFAULT_LINE_HEIGHT[DEFAULT_FONT_FAMILY];