diff --git a/src/CONST.ts b/src/CONST.ts index 4ed6780ab4cd..36c025344923 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -1705,6 +1705,10 @@ const CONST = { CONCIERGE: 'concierge', OTHER: 'other', WEB_PROP_ATTR: 'data-testid', + SHUTDOWN: 'shutdown', + RESTART: 'restart', + SET_IDENTITY: 'setIdentity', + OBSERVE: 'observe', }, CONCIERGE_DISPLAY_NAME: 'Concierge', diff --git a/src/libs/Fullstory/index.native.ts b/src/libs/Fullstory/index.native.ts index 930c12241b78..d1f1bc2223d2 100644 --- a/src/libs/Fullstory/index.native.ts +++ b/src/libs/Fullstory/index.native.ts @@ -1,6 +1,6 @@ import FullStory, {FSPage} from '@fullstory/react-native'; +import {Str} from 'expensify-common'; import type {OnyxEntry} from 'react-native-onyx'; -import {isExpensifyTeam} from '@libs/PolicyUtils'; import {isConciergeChatReport, shouldUnmaskChat} from '@libs/ReportUtils'; import CONST from '@src/CONST'; import * as Environment from '@src/libs/Environment/Environment'; @@ -43,7 +43,7 @@ const FS = { // UserMetadata onyx key. Environment.getEnvironment().then((envName: string) => { const isTestEmail = value.email !== undefined && value.email.startsWith('fullstory') && value.email.endsWith(CONST.EMAIL.QA_DOMAIN); - if ((CONST.ENVIRONMENT.PRODUCTION !== envName && !isTestEmail) || isExpensifyTeam(value?.email)) { + if ((CONST.ENVIRONMENT.PRODUCTION !== envName && !isTestEmail) || Str.extractEmailDomain(value.email ?? '') === CONST.EXPENSIFY_PARTNER_NAME) { return; } FullStory.restart(); diff --git a/src/libs/Fullstory/index.ts b/src/libs/Fullstory/index.ts index c7b1c2c9eb7a..421dad2a7b7f 100644 --- a/src/libs/Fullstory/index.ts +++ b/src/libs/Fullstory/index.ts @@ -1,7 +1,8 @@ import {FullStory, init, isInitialized} from '@fullstory/browser'; +import {Str} from 'expensify-common'; import type {OnyxEntry} from 'react-native-onyx'; -import {isExpensifyTeam} from '@libs/PolicyUtils'; import {isConciergeChatReport, shouldUnmaskChat} from '@libs/ReportUtils'; +import * as Session from '@userActions/Session'; import CONST from '@src/CONST'; import * as Environment from '@src/libs/Environment/Environment'; import type {OnyxInputOrEntry, PersonalDetailsList, Report, UserMetadata} from '@src/types/onyx'; @@ -103,20 +104,26 @@ const FS = { new Promise((resolve) => { if (!isInitialized()) { init({orgId: ''}, resolve); + + // FS init function might have a race condition with the head snippet. If the head snipped is loaded first, + // then the init function will not call the resolve function, and we'll never identify the user logging in, + // and we need to call resolve manually. We're adding a 1s timeout to make sure the init function has enough + // time to call the resolve function in case it ran successfully. + setTimeout(resolve, 1000); } else { - FullStory('observe', {type: 'start', callback: resolve}); + FullStory(CONST.FULL_STORY.OBSERVE, {type: 'start', callback: resolve}); } }), /** * Sets the identity as anonymous using the FullStory library. */ - anonymize: () => FullStory('setIdentity', {anonymous: true}), + anonymize: () => FullStory(CONST.FULL_STORY.SET_IDENTITY, {anonymous: true}), /** * Sets the identity consent status using the FullStory library. */ - consent: (c: boolean) => FullStory('setIdentity', {consent: c}), + consent: (c: boolean) => FullStory(CONST.FULL_STORY.SET_IDENTITY, {consent: c}), /** * Initializes the FullStory metadata with the provided metadata information. @@ -130,9 +137,16 @@ const FS = { try { Environment.getEnvironment().then((envName: string) => { const isTestEmail = value.email !== undefined && value.email.startsWith('fullstory') && value.email.endsWith(CONST.EMAIL.QA_DOMAIN); - if ((CONST.ENVIRONMENT.PRODUCTION !== envName && !isTestEmail) || isExpensifyTeam(value?.email)) { + if ( + (CONST.ENVIRONMENT.PRODUCTION !== envName && !isTestEmail) || + Str.extractEmailDomain(value.email ?? '') === CONST.EXPENSIFY_PARTNER_NAME || + Session.isSupportAuthToken() + ) { + // On web, if we started FS at some point in a browser, it will run forever. So let's shut it down if we don't want it to run. + FullStory(CONST.FULL_STORY.SHUTDOWN); return; } + FullStory(CONST.FULL_STORY.RESTART); FS.onReady().then(() => { FS.consent(true); const localMetadata = value; @@ -151,7 +165,7 @@ const FS = { * If the metadata contains an accountID, the user identity is defined with it. */ fsIdentify: (metadata: UserMetadata) => { - FullStory('setIdentity', { + FullStory(CONST.FULL_STORY.SET_IDENTITY, { uid: String(metadata.accountID), properties: metadata, }); diff --git a/src/pages/home/report/ReportActionsList.tsx b/src/pages/home/report/ReportActionsList.tsx index 7eb3711ec637..a3cef660cf1a 100644 --- a/src/pages/home/report/ReportActionsList.tsx +++ b/src/pages/home/report/ReportActionsList.tsx @@ -19,7 +19,7 @@ import useResponsiveLayout from '@hooks/useResponsiveLayout'; import useThemeStyles from '@hooks/useThemeStyles'; import useWindowDimensions from '@hooks/useWindowDimensions'; import DateUtils from '@libs/DateUtils'; -import {getChatFSAttributes} from '@libs/Fullstory'; +import {getChatFSAttributes, parseFSAttributes} from '@libs/Fullstory'; import isReportScreenTopmostCentralPane from '@libs/Navigation/isReportScreenTopmostCentralPane'; import isSearchTopmostCentralPane from '@libs/Navigation/isSearchTopmostCentralPane'; import Navigation from '@libs/Navigation/Navigation'; @@ -782,6 +782,9 @@ function ReportActionsList({ loadOlderChats(false); }, [loadOlderChats]); + // Parse Fullstory attributes on initial render + useLayoutEffect(parseFSAttributes, []); + const [reportActionsListTestID, reportActionsListFSClass] = getChatFSAttributes(participantsContext, 'ReportActionsList', report); return ( diff --git a/tests/perf-test/ReportActionsList.perf-test.tsx b/tests/perf-test/ReportActionsList.perf-test.tsx index da56a0ab0adf..dff140a3e63a 100644 --- a/tests/perf-test/ReportActionsList.perf-test.tsx +++ b/tests/perf-test/ReportActionsList.perf-test.tsx @@ -32,6 +32,7 @@ jest.mock('@libs/Fullstory', () => ({ }, getFSAttributes: jest.fn(), getChatFSAttributes: jest.fn().mockReturnValue(['mockTestID', 'mockFSClass']), + parseFSAttributes: jest.fn(), })); jest.mock('@components/withCurrentUserPersonalDetails', () => {