From 382809ac8410fb7a781e76552c3f25f4877d7759 Mon Sep 17 00:00:00 2001 From: Adam Horodyski Date: Thu, 29 May 2025 17:39:05 +0200 Subject: [PATCH 1/4] fix: add open_app and splash_screen metrics tracking --- src/CONST.ts | 2 ++ src/SplashScreenStateContext.tsx | 11 ++++++++++- src/libs/actions/App.ts | 1 + src/pages/Search/SearchPage.tsx | 5 +++++ src/setup/index.ts | 3 +++ src/setup/telemetry/index.native.ts | 17 +++++++++++++++++ src/setup/telemetry/index.ts | 15 +++++++++++++++ 7 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 src/setup/telemetry/index.native.ts create mode 100644 src/setup/telemetry/index.ts diff --git a/src/CONST.ts b/src/CONST.ts index 7a8635895071..c19adca9867f 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -1614,6 +1614,8 @@ const CONST = { TIMING: { GET_ORDERED_REPORT_IDS: 'get_ordered_report_ids', CALCULATE_MOST_RECENT_LAST_MODIFIED_ACTION: 'calc_most_recent_last_modified_action', + OPEN_APP: 'open_app', + SPLASH_SCREEN: 'splash_screen', OPEN_SEARCH: 'open_search', OPEN_REPORT: 'open_report', OPEN_REPORT_FROM_PREVIEW: 'open_report_from_preview', diff --git a/src/SplashScreenStateContext.tsx b/src/SplashScreenStateContext.tsx index 90a858f70c42..3c392b5a371b 100644 --- a/src/SplashScreenStateContext.tsx +++ b/src/SplashScreenStateContext.tsx @@ -1,5 +1,6 @@ -import React, {useContext, useMemo, useState} from 'react'; +import React, {useContext, useEffect, useMemo, useState} from 'react'; import type {ValueOf} from 'type-fest'; +import Timing from './libs/actions/Timing'; import CONST from './CONST'; import type ChildrenProps from './types/utils/ChildrenProps'; @@ -23,6 +24,14 @@ function SplashScreenStateContextProvider({children}: ChildrenProps) { [splashScreenState], ); + useEffect(() => { + if (splashScreenState !== "hidden") { + return; + } + + Timing.end(CONST.TIMING.SPLASH_SCREEN); + }, [splashScreenState]); + return {children}; } diff --git a/src/libs/actions/App.ts b/src/libs/actions/App.ts index 8b95c70fc9a6..e208607cd35a 100644 --- a/src/libs/actions/App.ts +++ b/src/libs/actions/App.ts @@ -162,6 +162,7 @@ const isReadyToOpenApp = new Promise((resolve) => { }); function confirmReadyToOpenApp() { + Timing.end(CONST.TIMING.OPEN_APP); resolveIsReadyPromise(); } diff --git a/src/pages/Search/SearchPage.tsx b/src/pages/Search/SearchPage.tsx index c8fe13e6d712..d76f30ab7284 100644 --- a/src/pages/Search/SearchPage.tsx +++ b/src/pages/Search/SearchPage.tsx @@ -54,6 +54,7 @@ import ROUTES from '@src/ROUTES'; import type SCREENS from '@src/SCREENS'; import type {SearchResults} from '@src/types/onyx'; import SearchPageNarrow from './SearchPageNarrow'; +import { confirmReadyToOpenApp } from '@libs/actions/App'; type SearchPageProps = PlatformStackScreenProps; @@ -90,6 +91,10 @@ function SearchPage({route}: SearchPageProps) { const [currentSearchResults] = useOnyx(`${ONYXKEYS.COLLECTION.SNAPSHOT}${queryJSON?.hash ?? CONST.DEFAULT_NUMBER_ID}`, {canBeMissing: true}); const [lastNonEmptySearchResults, setLastNonEmptySearchResults] = useState(undefined); + useEffect(() => { + confirmReadyToOpenApp(); + }, []); + useEffect(() => { if (!currentSearchResults?.search?.type) { return; diff --git a/src/setup/index.ts b/src/setup/index.ts index 5cc21e47373c..a327f8e8df93 100644 --- a/src/setup/index.ts +++ b/src/setup/index.ts @@ -8,8 +8,11 @@ import ONYXKEYS from '@src/ONYXKEYS'; import addUtilsToWindow from './addUtilsToWindow'; import initializeLastVisitedPath from './initializeLastVisitedPath'; import platformSetup from './platformSetup'; +import telemetry from './telemetry'; export default function () { + telemetry(); + /* * Initialize the Onyx store when the app loads for the first time. * diff --git a/src/setup/telemetry/index.native.ts b/src/setup/telemetry/index.native.ts new file mode 100644 index 000000000000..2822a6862c80 --- /dev/null +++ b/src/setup/telemetry/index.native.ts @@ -0,0 +1,17 @@ +import {AppState} from 'react-native'; +import type {AppStateStatus} from 'react-native'; +import Timing from '@userActions/Timing'; +import CONST from '@src/CONST'; + +export default function () { + Timing.start(CONST.TIMING.SPLASH_SCREEN); + Timing.start(CONST.TIMING.OPEN_APP); + + AppState.addEventListener('change', (nextState: AppStateStatus) => { + if (nextState !== "active") { + return; + } + + Timing.clearData(); + }); +} diff --git a/src/setup/telemetry/index.ts b/src/setup/telemetry/index.ts new file mode 100644 index 000000000000..171fa2b1b97a --- /dev/null +++ b/src/setup/telemetry/index.ts @@ -0,0 +1,15 @@ +import CONST from '@src/CONST'; +import Timing from '@userActions/Timing'; + +export default function () { + Timing.start(CONST.TIMING.SPLASH_SCREEN); + Timing.start(CONST.TIMING.OPEN_APP); + + document.addEventListener('visibilitychange', () => { + if (!document.hidden) { + return; + } + + Timing.clearData(); + }); +} From d400760544bb4912d160b80ff4649a0684f6c0eb Mon Sep 17 00:00:00 2001 From: Adam Horodyski Date: Fri, 30 May 2025 13:11:35 +0200 Subject: [PATCH 2/4] fix: stop reporting sidebar_loaded layout to the timing module --- src/libs/actions/App.ts | 1 - src/pages/home/sidebar/BaseSidebarScreen.tsx | 1 - 2 files changed, 2 deletions(-) diff --git a/src/libs/actions/App.ts b/src/libs/actions/App.ts index e208607cd35a..8426468d9e84 100644 --- a/src/libs/actions/App.ts +++ b/src/libs/actions/App.ts @@ -216,7 +216,6 @@ function setSidebarLoaded() { Onyx.set(ONYXKEYS.IS_SIDEBAR_LOADED, true); Performance.markEnd(CONST.TIMING.SIDEBAR_LOADED); - Timing.end(CONST.TIMING.SIDEBAR_LOADED); } function setAppLoading(isLoading: boolean) { diff --git a/src/pages/home/sidebar/BaseSidebarScreen.tsx b/src/pages/home/sidebar/BaseSidebarScreen.tsx index b1c6f2fcdf28..cd9f6136ee87 100644 --- a/src/pages/home/sidebar/BaseSidebarScreen.tsx +++ b/src/pages/home/sidebar/BaseSidebarScreen.tsx @@ -21,7 +21,6 @@ function BaseSidebarScreen() { useEffect(() => { Performance.markStart(CONST.TIMING.SIDEBAR_LOADED); - Timing.start(CONST.TIMING.SIDEBAR_LOADED); }, []); return ( From 082404b26a55cf90d96618ee63cb31a7858afd78 Mon Sep 17 00:00:00 2001 From: Adam Horodyski Date: Fri, 30 May 2025 13:17:55 +0200 Subject: [PATCH 3/4] fix: linter errors --- src/pages/Search/SearchPage.tsx | 2 +- src/pages/home/sidebar/BaseSidebarScreen.tsx | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/pages/Search/SearchPage.tsx b/src/pages/Search/SearchPage.tsx index d76f30ab7284..a17b1f35880c 100644 --- a/src/pages/Search/SearchPage.tsx +++ b/src/pages/Search/SearchPage.tsx @@ -53,8 +53,8 @@ import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import type SCREENS from '@src/SCREENS'; import type {SearchResults} from '@src/types/onyx'; -import SearchPageNarrow from './SearchPageNarrow'; import { confirmReadyToOpenApp } from '@libs/actions/App'; +import SearchPageNarrow from './SearchPageNarrow'; type SearchPageProps = PlatformStackScreenProps; diff --git a/src/pages/home/sidebar/BaseSidebarScreen.tsx b/src/pages/home/sidebar/BaseSidebarScreen.tsx index cd9f6136ee87..b713f09429d7 100644 --- a/src/pages/home/sidebar/BaseSidebarScreen.tsx +++ b/src/pages/home/sidebar/BaseSidebarScreen.tsx @@ -9,7 +9,6 @@ import useResponsiveLayout from '@hooks/useResponsiveLayout'; import useThemeStyles from '@hooks/useThemeStyles'; import {isMobile} from '@libs/Browser'; import Performance from '@libs/Performance'; -import Timing from '@userActions/Timing'; import CONST from '@src/CONST'; import SidebarLinksData from './SidebarLinksData'; From 57b94c3aca9ac4300891374ece066746b9c8e7f2 Mon Sep 17 00:00:00 2001 From: Adam Horodyski Date: Fri, 30 May 2025 13:58:59 +0200 Subject: [PATCH 4/4] fix: prettier --- src/SplashScreenStateContext.tsx | 14 +++++++------- src/pages/Search/SearchPage.tsx | 4 ++-- src/setup/telemetry/index.native.ts | 16 ++++++++-------- src/setup/telemetry/index.ts | 18 +++++++++--------- 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/SplashScreenStateContext.tsx b/src/SplashScreenStateContext.tsx index 3c392b5a371b..edceb6a9da47 100644 --- a/src/SplashScreenStateContext.tsx +++ b/src/SplashScreenStateContext.tsx @@ -1,7 +1,7 @@ import React, {useContext, useEffect, useMemo, useState} from 'react'; import type {ValueOf} from 'type-fest'; -import Timing from './libs/actions/Timing'; import CONST from './CONST'; +import Timing from './libs/actions/Timing'; import type ChildrenProps from './types/utils/ChildrenProps'; type SplashScreenStateContextType = { @@ -24,13 +24,13 @@ function SplashScreenStateContextProvider({children}: ChildrenProps) { [splashScreenState], ); - useEffect(() => { - if (splashScreenState !== "hidden") { - return; - } + useEffect(() => { + if (splashScreenState !== 'hidden') { + return; + } - Timing.end(CONST.TIMING.SPLASH_SCREEN); - }, [splashScreenState]); + Timing.end(CONST.TIMING.SPLASH_SCREEN); + }, [splashScreenState]); return {children}; } diff --git a/src/pages/Search/SearchPage.tsx b/src/pages/Search/SearchPage.tsx index a17b1f35880c..a3f3e34d3b19 100644 --- a/src/pages/Search/SearchPage.tsx +++ b/src/pages/Search/SearchPage.tsx @@ -26,6 +26,7 @@ import usePermissions from '@hooks/usePermissions'; import useResponsiveLayout from '@hooks/useResponsiveLayout'; import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; +import {confirmReadyToOpenApp} from '@libs/actions/App'; import {searchInServer} from '@libs/actions/Report'; import { approveMoneyRequestOnSearch, @@ -53,7 +54,6 @@ import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import type SCREENS from '@src/SCREENS'; import type {SearchResults} from '@src/types/onyx'; -import { confirmReadyToOpenApp } from '@libs/actions/App'; import SearchPageNarrow from './SearchPageNarrow'; type SearchPageProps = PlatformStackScreenProps; @@ -92,7 +92,7 @@ function SearchPage({route}: SearchPageProps) { const [lastNonEmptySearchResults, setLastNonEmptySearchResults] = useState(undefined); useEffect(() => { - confirmReadyToOpenApp(); + confirmReadyToOpenApp(); }, []); useEffect(() => { diff --git a/src/setup/telemetry/index.native.ts b/src/setup/telemetry/index.native.ts index 2822a6862c80..821f3b30447b 100644 --- a/src/setup/telemetry/index.native.ts +++ b/src/setup/telemetry/index.native.ts @@ -4,14 +4,14 @@ import Timing from '@userActions/Timing'; import CONST from '@src/CONST'; export default function () { - Timing.start(CONST.TIMING.SPLASH_SCREEN); - Timing.start(CONST.TIMING.OPEN_APP); + Timing.start(CONST.TIMING.SPLASH_SCREEN); + Timing.start(CONST.TIMING.OPEN_APP); - AppState.addEventListener('change', (nextState: AppStateStatus) => { - if (nextState !== "active") { - return; - } + AppState.addEventListener('change', (nextState: AppStateStatus) => { + if (nextState !== 'active') { + return; + } - Timing.clearData(); - }); + Timing.clearData(); + }); } diff --git a/src/setup/telemetry/index.ts b/src/setup/telemetry/index.ts index 171fa2b1b97a..419176e84f76 100644 --- a/src/setup/telemetry/index.ts +++ b/src/setup/telemetry/index.ts @@ -1,15 +1,15 @@ -import CONST from '@src/CONST'; import Timing from '@userActions/Timing'; +import CONST from '@src/CONST'; export default function () { - Timing.start(CONST.TIMING.SPLASH_SCREEN); - Timing.start(CONST.TIMING.OPEN_APP); + Timing.start(CONST.TIMING.SPLASH_SCREEN); + Timing.start(CONST.TIMING.OPEN_APP); - document.addEventListener('visibilitychange', () => { - if (!document.hidden) { - return; - } + document.addEventListener('visibilitychange', () => { + if (!document.hidden) { + return; + } - Timing.clearData(); - }); + Timing.clearData(); + }); }