From 33cfb76fd1dfc027fc04ca3729ac6115085694b0 Mon Sep 17 00:00:00 2001 From: Daniel Silva Date: Wed, 9 Oct 2024 14:30:33 -0300 Subject: [PATCH 01/11] fixed web to only record if identified --- src/libs/Fullstory/index.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/libs/Fullstory/index.ts b/src/libs/Fullstory/index.ts index 8419bccabb90..c1cd0e0d37b2 100644 --- a/src/libs/Fullstory/index.ts +++ b/src/libs/Fullstory/index.ts @@ -56,6 +56,11 @@ const FS = { * Initializes the FullStory metadata with the provided metadata information. */ consentAndIdentify: (value: OnyxEntry) => { + // On the first subscribe for UserMetadata, this function will be called. We need + // to confirm that we actually have any value here before proceeding. + if (!value?.accountID) { + return; + } try { Environment.getEnvironment().then((envName: string) => { if (CONST.ENVIRONMENT.PRODUCTION !== envName) { @@ -63,11 +68,9 @@ const FS = { } FS.onReady().then(() => { FS.consent(true); - if (value) { - const localMetadata = value; - localMetadata.environment = envName; - FS.fsIdentify(localMetadata); - } + const localMetadata = value; + localMetadata.environment = envName; + FS.fsIdentify(localMetadata); }); }); } catch (e) { From 4259ad89bee7832ce0f7c6a31179cd2f83be4b56 Mon Sep 17 00:00:00 2001 From: Daniel Silva Date: Wed, 9 Oct 2024 14:39:49 -0300 Subject: [PATCH 02/11] simplifying web --- src/libs/Fullstory/index.ts | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/src/libs/Fullstory/index.ts b/src/libs/Fullstory/index.ts index c1cd0e0d37b2..f5e85ba67cf9 100644 --- a/src/libs/Fullstory/index.ts +++ b/src/libs/Fullstory/index.ts @@ -29,17 +29,11 @@ const FS = { */ onReady: () => new Promise((resolve) => { - Environment.getEnvironment().then((envName: string) => { - if (CONST.ENVIRONMENT.PRODUCTION !== envName) { - return; - } - // Initialised via HEAD snippet - if (!isInitialized()) { - init({orgId: ''}, resolve); - } else { - FullStory('observe', {type: 'start', callback: resolve}); - } - }); + if (!isInitialized()) { + init({orgId: ''}, resolve); + } else { + FullStory('observe', {type: 'start', callback: resolve}); + } }), /** @@ -83,17 +77,11 @@ const FS = { * If the metadata does not contain an email, the user identity is anonymized. * If the metadata contains an accountID, the user identity is defined with it. */ - fsIdentify: (metadata: OnyxEntry) => { - if (!metadata?.accountID) { - // anonymize FullStory user identity metadata - FS.anonymize(); - } else { - // define FullStory user identity - FullStory('setIdentity', { - uid: String(metadata.accountID), - properties: metadata, - }); - } + fsIdentify: (metadata: UserMetadata) => { + FullStory('setIdentity', { + uid: String(metadata.accountID), + properties: metadata, + }); }, /** From 63787c4e5d45efb66fbe677b1d11c00b63f23eb3 Mon Sep 17 00:00:00 2001 From: Daniel Silva Date: Wed, 9 Oct 2024 14:40:13 -0300 Subject: [PATCH 03/11] adjusting mobile to only record if we have a way of identifying our users --- src/libs/Fullstory/index.native.ts | 48 ++++++++++++++---------------- 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/src/libs/Fullstory/index.native.ts b/src/libs/Fullstory/index.native.ts index 7974c35562ca..65233ccf016f 100644 --- a/src/libs/Fullstory/index.native.ts +++ b/src/libs/Fullstory/index.native.ts @@ -15,15 +15,8 @@ const FS = { * Initializes FullStory */ init: () => { - Environment.getEnvironment().then((envName: string) => { - // We only want to start fullstory if the app is running in production - if (envName !== CONST.ENVIRONMENT.PRODUCTION) { - return; - } - FullStory.restart(); - const [session] = useOnyx(ONYXKEYS.USER_METADATA); - FS.fsIdentify(session); - }); + const [session] = useOnyx(ONYXKEYS.USER_METADATA); + FS.consentAndIdentify(session); }, /** @@ -40,10 +33,23 @@ const FS = { * Initializes the FullStory metadata with the provided metadata information. */ consentAndIdentify: (value: OnyxEntry) => { + // On the first subscribe for UserMetadta, this function will be called. We need + // to confirm that we actually have any value here before proceeding. + if (!value?.accountID) { + return; + } try { - // We only use FullStory in production environment - FullStory.consent(true); - FS.fsIdentify(value); + // We only use FullStory in production environment. We need to check this here + // after the init function since this function is also called on updates for + // UserMetadata onyx key. + Environment.getEnvironment().then((envName: string) => { + if (envName !== CONST.ENVIRONMENT.PRODUCTION) { + return; + } + FullStory.restart(); + FullStory.consent(true); + FS.fsIdentify(value, envName); + }); } catch (e) { // error handler } @@ -51,21 +57,11 @@ const FS = { /** * Sets the FullStory user identity based on the provided metadata information. - * If the metadata is null or the email is 'undefined', the user identity is anonymized. - * If the metadata contains an accountID, the user identity is defined with it. */ - fsIdentify: (metadata: OnyxEntry) => { - if (!metadata?.accountID) { - // anonymize FullStory user identity metadata - FullStory.anonymize(); - } else { - Environment.getEnvironment().then((envName: string) => { - // define FullStory user identity - const localMetadata = metadata; - localMetadata.environment = envName; - FullStory.identify(String(localMetadata.accountID), localMetadata); - }); - } + fsIdentify: (metadata: UserMetadata, envName: string) => { + const localMetadata = metadata; + localMetadata.environment = envName; + FullStory.identify(String(localMetadata.accountID), localMetadata); }, }; From 374d964340f7869210cee2cdfd9a25e2fcfb7f34 Mon Sep 17 00:00:00 2001 From: Daniel Silva Date: Wed, 9 Oct 2024 14:55:19 -0300 Subject: [PATCH 04/11] adjusting session to be passed as a parameter to the FS lib --- src/Expensify.tsx | 3 ++- src/libs/Fullstory/index.native.ts | 5 ++--- src/libs/Fullstory/index.ts | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Expensify.tsx b/src/Expensify.tsx index f5d4655c4861..e1fe19b3e6c8 100644 --- a/src/Expensify.tsx +++ b/src/Expensify.tsx @@ -149,7 +149,8 @@ function Expensify({ ActiveClientManager.init(); // Initialize Fullstory lib - FS.init(); + const [session] = useOnyx(ONYXKEYS.USER_METADATA); + FS.init(session); // Used for the offline indicator appearing when someone is offline const unsubscribeNetInfo = NetworkConnection.subscribeToNetInfo(); diff --git a/src/libs/Fullstory/index.native.ts b/src/libs/Fullstory/index.native.ts index 65233ccf016f..cd3290b6e529 100644 --- a/src/libs/Fullstory/index.native.ts +++ b/src/libs/Fullstory/index.native.ts @@ -14,9 +14,8 @@ const FS = { /** * Initializes FullStory */ - init: () => { - const [session] = useOnyx(ONYXKEYS.USER_METADATA); - FS.consentAndIdentify(session); + init: (value: OnyxEntry) => { + FS.consentAndIdentify(value); }, /** diff --git a/src/libs/Fullstory/index.ts b/src/libs/Fullstory/index.ts index f5e85ba67cf9..4c2f923b0e79 100644 --- a/src/libs/Fullstory/index.ts +++ b/src/libs/Fullstory/index.ts @@ -87,7 +87,7 @@ const FS = { /** * Init function, created so we're consistent with the native file */ - init: () => {}, + init: (value: OnyxEntry) => {}, }; export default FS; From 0c4dc63e0d0df365104b91bd0e1c2636c8b758fe Mon Sep 17 00:00:00 2001 From: Daniel Silva Date: Wed, 9 Oct 2024 14:59:08 -0300 Subject: [PATCH 05/11] fixing issues with eslint --- src/Expensify.tsx | 4 ++-- src/libs/Fullstory/index.native.ts | 2 -- src/libs/Fullstory/index.ts | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/Expensify.tsx b/src/Expensify.tsx index e1fe19b3e6c8..8d3bf6d67071 100644 --- a/src/Expensify.tsx +++ b/src/Expensify.tsx @@ -98,6 +98,7 @@ function Expensify({ const [account] = useOnyx(ONYXKEYS.ACCOUNT); const [session] = useOnyx(ONYXKEYS.SESSION); const [lastRoute] = useOnyx(ONYXKEYS.LAST_ROUTE); + const [userMetadata] = useOnyx(ONYXKEYS.USER_METADATA); const [shouldShowRequire2FAModal, setShouldShowRequire2FAModal] = useState(false); useEffect(() => { @@ -149,8 +150,7 @@ function Expensify({ ActiveClientManager.init(); // Initialize Fullstory lib - const [session] = useOnyx(ONYXKEYS.USER_METADATA); - FS.init(session); + FS.init(userMetadata); // Used for the offline indicator appearing when someone is offline const unsubscribeNetInfo = NetworkConnection.subscribeToNetInfo(); diff --git a/src/libs/Fullstory/index.native.ts b/src/libs/Fullstory/index.native.ts index cd3290b6e529..8d97b8d4307e 100644 --- a/src/libs/Fullstory/index.native.ts +++ b/src/libs/Fullstory/index.native.ts @@ -1,9 +1,7 @@ import FullStory, {FSPage} from '@fullstory/react-native'; import type {OnyxEntry} from 'react-native-onyx'; -import {useOnyx} from 'react-native-onyx'; import CONST from '@src/CONST'; import * as Environment from '@src/libs/Environment/Environment'; -import ONYXKEYS from '@src/ONYXKEYS'; import type {UserMetadata} from '@src/types/onyx'; /** diff --git a/src/libs/Fullstory/index.ts b/src/libs/Fullstory/index.ts index 4c2f923b0e79..e9a10c4eabfa 100644 --- a/src/libs/Fullstory/index.ts +++ b/src/libs/Fullstory/index.ts @@ -87,7 +87,7 @@ const FS = { /** * Init function, created so we're consistent with the native file */ - init: (value: OnyxEntry) => {}, + init: (_value: OnyxEntry) => {}, }; export default FS; From e8c4fdcbd6b5ba5a57f1a580444371f186a2adbf Mon Sep 17 00:00:00 2001 From: Daniel Silva Date: Wed, 9 Oct 2024 15:01:41 -0300 Subject: [PATCH 06/11] fixing last style issue --- src/libs/Fullstory/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libs/Fullstory/index.ts b/src/libs/Fullstory/index.ts index e9a10c4eabfa..df65af358a55 100644 --- a/src/libs/Fullstory/index.ts +++ b/src/libs/Fullstory/index.ts @@ -87,6 +87,7 @@ const FS = { /** * Init function, created so we're consistent with the native file */ + // eslint-disable-next-line @typescript-eslint/no-unused-vars init: (_value: OnyxEntry) => {}, }; From 343171766bb5cd87a6533df04a51be28cca97a71 Mon Sep 17 00:00:00 2001 From: Daniel Silva Date: Wed, 9 Oct 2024 15:18:17 -0300 Subject: [PATCH 07/11] removing withOnyx --- src/Expensify.tsx | 50 ++++++++++------------------------------------- 1 file changed, 10 insertions(+), 40 deletions(-) diff --git a/src/Expensify.tsx b/src/Expensify.tsx index 8d3bf6d67071..c4403c559ae9 100644 --- a/src/Expensify.tsx +++ b/src/Expensify.tsx @@ -55,7 +55,7 @@ Onyx.registerLogger(({level, message}) => { } }); -type ExpensifyOnyxProps = { +type ExpensifyProps = { /** Whether the app is waiting for the server's response to determine if a room is public */ isCheckingPublicRoom: OnyxEntry; @@ -77,18 +77,7 @@ type ExpensifyOnyxProps = { /** Last visited path in the app */ lastVisitedPath: OnyxEntry; }; - -type ExpensifyProps = ExpensifyOnyxProps; - -function Expensify({ - isCheckingPublicRoom = true, - updateAvailable, - isSidebarLoaded = false, - screenShareRequest, - updateRequired = false, - focusModeNotification = false, - lastVisitedPath, -}: ExpensifyProps) { +function Expensify() { const appStateChangeListener = useRef(null); const [isNavigationReady, setIsNavigationReady] = useState(false); const [isOnyxMigrated, setIsOnyxMigrated] = useState(false); @@ -100,6 +89,13 @@ function Expensify({ const [lastRoute] = useOnyx(ONYXKEYS.LAST_ROUTE); const [userMetadata] = useOnyx(ONYXKEYS.USER_METADATA); const [shouldShowRequire2FAModal, setShouldShowRequire2FAModal] = useState(false); + const [isCheckingPublicRoom] = useOnyx(ONYXKEYS.IS_CHECKING_PUBLIC_ROOM); + const [updateAvailable] = useOnyx(ONYXKEYS.UPDATE_AVAILABLE); + const [updateRequired] = useOnyx(ONYXKEYS.UPDATE_REQUIRED); + const [isSidebarLoaded] = useOnyx(ONYXKEYS.IS_SIDEBAR_LOADED); + const [screenShareRequest] = useOnyx(ONYXKEYS.SCREEN_SHARE_REQUEST); + const [focusModeNotification] = useOnyx(ONYXKEYS.FOCUS_MODE_NOTIFICATION); + const [lastVisitedPath] = useOnyx(ONYXKEYS.LAST_VISITED_PATH); useEffect(() => { if (!account?.needsTwoFactorAuthSetup || account.requiresTwoFactorAuth) { @@ -305,30 +301,4 @@ function Expensify({ Expensify.displayName = 'Expensify'; -export default withOnyx({ - isCheckingPublicRoom: { - key: ONYXKEYS.IS_CHECKING_PUBLIC_ROOM, - initWithStoredValues: false, - }, - updateAvailable: { - key: ONYXKEYS.UPDATE_AVAILABLE, - initWithStoredValues: false, - }, - updateRequired: { - key: ONYXKEYS.UPDATE_REQUIRED, - initWithStoredValues: false, - }, - isSidebarLoaded: { - key: ONYXKEYS.IS_SIDEBAR_LOADED, - }, - screenShareRequest: { - key: ONYXKEYS.SCREEN_SHARE_REQUEST, - }, - focusModeNotification: { - key: ONYXKEYS.FOCUS_MODE_NOTIFICATION, - initWithStoredValues: false, - }, - lastVisitedPath: { - key: ONYXKEYS.LAST_VISITED_PATH, - }, -})(Expensify); +Expensify(); \ No newline at end of file From 117552734179079c3153cf876ff185322e603480 Mon Sep 17 00:00:00 2001 From: Daniel Silva Date: Wed, 9 Oct 2024 15:23:04 -0300 Subject: [PATCH 08/11] exporting component correctly --- src/Expensify.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Expensify.tsx b/src/Expensify.tsx index c4403c559ae9..557ee1a64311 100644 --- a/src/Expensify.tsx +++ b/src/Expensify.tsx @@ -301,4 +301,4 @@ function Expensify() { Expensify.displayName = 'Expensify'; -Expensify(); \ No newline at end of file +export default Expensify; \ No newline at end of file From 741c5c189104ca8e3c59fa0753e0058d61f7bea7 Mon Sep 17 00:00:00 2001 From: Daniel Silva Date: Wed, 9 Oct 2024 15:26:55 -0300 Subject: [PATCH 09/11] style --- src/Expensify.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Expensify.tsx b/src/Expensify.tsx index 557ee1a64311..5600c3b54d28 100644 --- a/src/Expensify.tsx +++ b/src/Expensify.tsx @@ -3,7 +3,7 @@ import React, {useCallback, useContext, useEffect, useLayoutEffect, useMemo, use import type {NativeEventSubscription} from 'react-native'; import {AppState, Linking, NativeModules, Platform} from 'react-native'; import type {OnyxEntry} from 'react-native-onyx'; -import Onyx, {useOnyx, withOnyx} from 'react-native-onyx'; +import Onyx, {useOnyx} from 'react-native-onyx'; import ConfirmModal from './components/ConfirmModal'; import DeeplinkWrapper from './components/DeeplinkWrapper'; import EmojiPicker from './components/EmojiPicker/EmojiPicker'; @@ -301,4 +301,4 @@ function Expensify() { Expensify.displayName = 'Expensify'; -export default Expensify; \ No newline at end of file +export default Expensify; From 9e481ebe616d3e80fdc0c83a3c8103371f55f397 Mon Sep 17 00:00:00 2001 From: Daniel Silva Date: Wed, 9 Oct 2024 17:26:53 -0300 Subject: [PATCH 10/11] disable linter --- src/Expensify.tsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Expensify.tsx b/src/Expensify.tsx index 5600c3b54d28..b0c74e82edf9 100644 --- a/src/Expensify.tsx +++ b/src/Expensify.tsx @@ -152,6 +152,10 @@ function Expensify() { const unsubscribeNetInfo = NetworkConnection.subscribeToNetInfo(); return unsubscribeNetInfo; + + // This would alerting because of userMetadata. We'll remove the linter rule since + // we don't really need to run this effect again if that value changes. + // eslint-disable-next-line react-hooks/exhaustive-deps }, []); // Log the platform and config to debug .env issues From 084aaac39aef942c3e6e4e9af47447bf5ca9a52d Mon Sep 17 00:00:00 2001 From: Daniel Silva Date: Wed, 9 Oct 2024 18:18:31 -0300 Subject: [PATCH 11/11] moving value to useEffect --- src/Expensify.tsx | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/Expensify.tsx b/src/Expensify.tsx index b0c74e82edf9..7822ec16b879 100644 --- a/src/Expensify.tsx +++ b/src/Expensify.tsx @@ -145,19 +145,17 @@ function Expensify() { // Initialize this client as being an active client ActiveClientManager.init(); - // Initialize Fullstory lib - FS.init(userMetadata); - // Used for the offline indicator appearing when someone is offline const unsubscribeNetInfo = NetworkConnection.subscribeToNetInfo(); return unsubscribeNetInfo; - - // This would alerting because of userMetadata. We'll remove the linter rule since - // we don't really need to run this effect again if that value changes. - // eslint-disable-next-line react-hooks/exhaustive-deps }, []); + useEffect(() => { + // Initialize Fullstory lib + FS.init(userMetadata); + }, [userMetadata]); + // Log the platform and config to debug .env issues useEffect(() => { Log.info('App launched', false, {Platform, CONFIG});