From e4beae46031181c445301d432cbe69e2f5e394c3 Mon Sep 17 00:00:00 2001 From: Daniel Silva Date: Tue, 23 Apr 2024 17:25:23 +0200 Subject: [PATCH 01/15] creating new type for metadata --- src/types/onyx/UserMetadata.ts | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 src/types/onyx/UserMetadata.ts diff --git a/src/types/onyx/UserMetadata.ts b/src/types/onyx/UserMetadata.ts new file mode 100644 index 000000000000..2a51a0a86de6 --- /dev/null +++ b/src/types/onyx/UserMetadata.ts @@ -0,0 +1,8 @@ +type UserMetadata = { + planType?: string; + role?: string; + freeTrial?: boolean; + accountID?: number; +}; + +export default UserMetadata; \ No newline at end of file From 346c66d73ce3660983c85173f898756cc5ec69fb Mon Sep 17 00:00:00 2001 From: Daniel Silva Date: Tue, 23 Apr 2024 17:25:46 +0200 Subject: [PATCH 02/15] exporting new object type --- src/types/onyx/index.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/types/onyx/index.ts b/src/types/onyx/index.ts index ea0870a7b8c6..84a8d5c85c40 100644 --- a/src/types/onyx/index.ts +++ b/src/types/onyx/index.ts @@ -72,6 +72,7 @@ import type {TransactionViolation, ViolationName} from './TransactionViolation'; import type TransactionViolations from './TransactionViolation'; import type User from './User'; import type UserLocation from './UserLocation'; +import type UserMetadata from './UserMetadata'; import type UserWallet from './UserWallet'; import type WalletAdditionalDetails from './WalletAdditionalDetails'; import type {WalletAdditionalQuestionDetails} from './WalletAdditionalDetails'; @@ -155,6 +156,7 @@ export type { TransactionViolations, User, UserLocation, + UserMetadata, UserWallet, ViolationName, WalletAdditionalDetails, From 7c96e55c8755ad066ac6f334977edf875c3be956 Mon Sep 17 00:00:00 2001 From: Daniel Silva Date: Tue, 23 Apr 2024 17:26:32 +0200 Subject: [PATCH 03/15] mapping new key to a specific type --- src/ONYXKEYS.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/ONYXKEYS.ts b/src/ONYXKEYS.ts index 95d383345ec6..e1aa6ef7c9f1 100755 --- a/src/ONYXKEYS.ts +++ b/src/ONYXKEYS.ts @@ -184,6 +184,9 @@ const ONYXKEYS = { /** User's Expensify Wallet */ USER_WALLET: 'userWallet', + /** User's metadata that will be used to segmentation */ + USER_METADATA: 'userMetadata', + /** Object containing Onfido SDK Token + applicantID */ WALLET_ONFIDO: 'walletOnfido', @@ -592,6 +595,7 @@ type OnyxValuesMapping = { [ONYXKEYS.USER_LOCATION]: OnyxTypes.UserLocation; [ONYXKEYS.LOGIN_LIST]: OnyxTypes.LoginList; [ONYXKEYS.SESSION]: OnyxTypes.Session; + [ONYXKEYS.USER_METADATA]: OnyxTypes.UserMetadata; [ONYXKEYS.STASHED_SESSION]: OnyxTypes.Session; [ONYXKEYS.BETAS]: OnyxTypes.Beta[]; [ONYXKEYS.NVP_PRIORITY_MODE]: ValueOf; From d90952e20ac4e6ffb9af4d3a72d803059d8c5910 Mon Sep 17 00:00:00 2001 From: Daniel Silva Date: Tue, 23 Apr 2024 17:32:32 +0200 Subject: [PATCH 04/15] removing unecessary type --- src/libs/fullstory/types.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/libs/fullstory/types.ts b/src/libs/fullstory/types.ts index 386e35536d97..1c0d2fb6efd5 100644 --- a/src/libs/fullstory/types.ts +++ b/src/libs/fullstory/types.ts @@ -1,10 +1,5 @@ -type UserSession = { - email: string | undefined; - accountID: number | undefined; -}; - type NavigationProperties = { path: string; }; -export type {UserSession, NavigationProperties}; +export type {NavigationProperties}; From a28ecff16ea8db01413e7868f5728434216705d9 Mon Sep 17 00:00:00 2001 From: Daniel Silva Date: Tue, 23 Apr 2024 17:32:52 +0200 Subject: [PATCH 05/15] using new property on native --- src/libs/fullstory/index.native.ts | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/src/libs/fullstory/index.native.ts b/src/libs/fullstory/index.native.ts index e1781e6fed2d..d552294ebe28 100644 --- a/src/libs/fullstory/index.native.ts +++ b/src/libs/fullstory/index.native.ts @@ -1,7 +1,6 @@ import FullStory, {FSPage} from '@fullstory/react-native'; import type {OnyxEntry} from 'react-native-onyx'; -import type Session from '@src/types/onyx/Session'; -import type {UserSession} from './types'; +import { UserMetadata } from '@src/types/onyx'; /** * Fullstory React-Native lib adapter @@ -21,15 +20,11 @@ const FS = { /** * Initializes the FullStory session with the provided session information. */ - consentAndIdentify: (value: OnyxEntry) => { + consentAndIdentify: (value: OnyxEntry) => { try { - const session: UserSession = { - email: value?.email, - accountID: value?.accountID, - }; // set consent FullStory.consent(true); - FS.fsIdentify(session); + FS.fsIdentify(value); } catch (e) { // error handler } @@ -38,19 +33,16 @@ const FS = { /** * Sets the FullStory user identity based on the provided session information. * If the session is null or the email is 'undefined', the user identity is anonymized. - * If the session contains an email, the user identity is defined with the email and account ID. + * If the session contains an accountID, the user identity is defined with it. */ - fsIdentify: (session: UserSession) => { - if (!session || session.email === 'undefined') { - // anonymize FullStory user identity session + fsIdentify: (metadata: UserMetadata | null) => { + if (!metadata || !metadata.accountID) { + // anonymize FullStory user identity metadata FullStory.anonymize(); } else { // define FullStory user identity - FullStory.identify(String(session.accountID), { - properties: { - displayName: session.email, - email: session.email, - }, + FullStory.identify(String(metadata.accountID), { + properties: metadata, }); } }, From 54253b16b3c0a7ca6e731da9dead9c23f1165abb Mon Sep 17 00:00:00 2001 From: Daniel Silva Date: Tue, 23 Apr 2024 17:34:19 +0200 Subject: [PATCH 06/15] changing language to metadata --- src/libs/fullstory/index.native.ts | 8 ++++---- src/libs/fullstory/index.ts | 33 ++++++++++++------------------ 2 files changed, 17 insertions(+), 24 deletions(-) diff --git a/src/libs/fullstory/index.native.ts b/src/libs/fullstory/index.native.ts index d552294ebe28..873d01d483d5 100644 --- a/src/libs/fullstory/index.native.ts +++ b/src/libs/fullstory/index.native.ts @@ -18,7 +18,7 @@ const FS = { consent: (c: boolean) => FullStory.consent(c), /** - * Initializes the FullStory session with the provided session information. + * Initializes the FullStory metadata with the provided metadata information. */ consentAndIdentify: (value: OnyxEntry) => { try { @@ -31,9 +31,9 @@ const FS = { }, /** - * Sets the FullStory user identity based on the provided session information. - * If the session is null or the email is 'undefined', the user identity is anonymized. - * If the session contains an accountID, the user identity is defined with it. + * 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: UserMetadata | null) => { if (!metadata || !metadata.accountID) { diff --git a/src/libs/fullstory/index.ts b/src/libs/fullstory/index.ts index 0cb849983c80..a519d9147663 100644 --- a/src/libs/fullstory/index.ts +++ b/src/libs/fullstory/index.ts @@ -1,7 +1,7 @@ import {FullStory, init, isInitialized} from '@fullstory/browser'; import type {OnyxEntry} from 'react-native-onyx'; -import type Session from '@src/types/onyx/Session'; -import type {NavigationProperties, UserSession} from './types'; +import type {NavigationProperties} from './types'; +import { UserMetadata } from '@src/types/onyx'; // Placeholder Browser API does not support Manual Page definition class FSPage { @@ -46,18 +46,13 @@ const FS = { consent: (c: boolean) => FullStory('setIdentity', {consent: c}), /** - * Initializes the FullStory session with the provided session information. + * Initializes the FullStory metadata with the provided metadata information. */ - consentAndIdentify: (value: OnyxEntry) => { + consentAndIdentify: (value: OnyxEntry) => { try { FS.onReady().then(() => { - const session: UserSession = { - email: value?.email, - accountID: value?.accountID, - }; - // set consent FS.consent(true); - FS.fsIdentify(session); + FS.fsIdentify(value); }); } catch (e) { // error handler @@ -65,21 +60,19 @@ const FS = { }, /** - * Sets the FullStory user identity based on the provided session information. - * If the session does not contain an email, the user identity is anonymized. - * If the session contains an email, the user identity is defined with the email and account ID. + * Sets the FullStory user identity based on the provided metadata information. + * 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: (session: UserSession) => { - if (typeof session.email === 'undefined') { - // anonymize FullStory user identity session + fsIdentify: (metadata: UserMetadata | null) => { + if (!metadata || !metadata.accountID) { + // anonymize FullStory user identity metadata FS.anonymize(); } else { // define FullStory user identity FullStory('setIdentity', { - uid: String(session.accountID), - properties: { - accountID: session.accountID, - }, + uid: String(metadata.accountID), + properties: metadata, }); } }, From 56e7e4640867d45db089b747a132881fb730d391 Mon Sep 17 00:00:00 2001 From: Daniel Silva Date: Tue, 23 Apr 2024 17:34:51 +0200 Subject: [PATCH 07/15] changing key to use metadata --- src/libs/actions/Session/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/Session/index.ts b/src/libs/actions/Session/index.ts index 52cd4469f253..dd3a7152fb70 100644 --- a/src/libs/actions/Session/index.ts +++ b/src/libs/actions/Session/index.ts @@ -65,7 +65,7 @@ Onyx.connect({ }); Onyx.connect({ - key: ONYXKEYS.SESSION, + key: ONYXKEYS.USER_METADATA, callback: Fullstory.consentAndIdentify, }); From d90322ce88ec15e152dac687723e5143d321685e Mon Sep 17 00:00:00 2001 From: Daniel Silva Date: Tue, 23 Apr 2024 17:53:46 +0200 Subject: [PATCH 08/15] addressing lint issues --- src/libs/fullstory/index.native.ts | 4 ++-- src/libs/fullstory/index.ts | 4 ++-- src/libs/fullstory/types.ts | 2 +- src/types/onyx/UserMetadata.ts | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/libs/fullstory/index.native.ts b/src/libs/fullstory/index.native.ts index 873d01d483d5..10f225ae5c67 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 type {OnyxEntry} from 'react-native-onyx'; -import { UserMetadata } from '@src/types/onyx'; +import type {UserMetadata} from '@src/types/onyx'; /** * Fullstory React-Native lib adapter @@ -36,7 +36,7 @@ const FS = { * If the metadata contains an accountID, the user identity is defined with it. */ fsIdentify: (metadata: UserMetadata | null) => { - if (!metadata || !metadata.accountID) { + if (!metadata?.accountID) { // anonymize FullStory user identity metadata FullStory.anonymize(); } else { diff --git a/src/libs/fullstory/index.ts b/src/libs/fullstory/index.ts index a519d9147663..4cb09d6d2604 100644 --- a/src/libs/fullstory/index.ts +++ b/src/libs/fullstory/index.ts @@ -1,7 +1,7 @@ import {FullStory, init, isInitialized} from '@fullstory/browser'; import type {OnyxEntry} from 'react-native-onyx'; +import type {UserMetadata} from '@src/types/onyx'; import type {NavigationProperties} from './types'; -import { UserMetadata } from '@src/types/onyx'; // Placeholder Browser API does not support Manual Page definition class FSPage { @@ -65,7 +65,7 @@ const FS = { * If the metadata contains an accountID, the user identity is defined with it. */ fsIdentify: (metadata: UserMetadata | null) => { - if (!metadata || !metadata.accountID) { + if (!metadata?.accountID) { // anonymize FullStory user identity metadata FS.anonymize(); } else { diff --git a/src/libs/fullstory/types.ts b/src/libs/fullstory/types.ts index 1c0d2fb6efd5..24878fd0fbd3 100644 --- a/src/libs/fullstory/types.ts +++ b/src/libs/fullstory/types.ts @@ -2,4 +2,4 @@ type NavigationProperties = { path: string; }; -export type {NavigationProperties}; +export default NavigationProperties; diff --git a/src/types/onyx/UserMetadata.ts b/src/types/onyx/UserMetadata.ts index 2a51a0a86de6..fc6490264087 100644 --- a/src/types/onyx/UserMetadata.ts +++ b/src/types/onyx/UserMetadata.ts @@ -5,4 +5,4 @@ type UserMetadata = { accountID?: number; }; -export default UserMetadata; \ No newline at end of file +export default UserMetadata; From 5d7a00ece2a5c5b13e807afa5ce6df7493a9231a Mon Sep 17 00:00:00 2001 From: Daniel Silva Date: Tue, 23 Apr 2024 18:09:25 +0200 Subject: [PATCH 09/15] typescript issue --- src/libs/fullstory/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/fullstory/index.ts b/src/libs/fullstory/index.ts index 4cb09d6d2604..60f0b5619f0f 100644 --- a/src/libs/fullstory/index.ts +++ b/src/libs/fullstory/index.ts @@ -1,7 +1,7 @@ import {FullStory, init, isInitialized} from '@fullstory/browser'; import type {OnyxEntry} from 'react-native-onyx'; import type {UserMetadata} from '@src/types/onyx'; -import type {NavigationProperties} from './types'; +import NavigationProperties from './types'; // Placeholder Browser API does not support Manual Page definition class FSPage { From 62f44e65156c2369b7a4c14fac7ba3ceedaa37fd Mon Sep 17 00:00:00 2001 From: Daniel Silva Date: Tue, 23 Apr 2024 18:16:44 +0200 Subject: [PATCH 10/15] typescript checks again --- src/libs/fullstory/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/fullstory/index.ts b/src/libs/fullstory/index.ts index 60f0b5619f0f..82b4860f12c8 100644 --- a/src/libs/fullstory/index.ts +++ b/src/libs/fullstory/index.ts @@ -1,7 +1,7 @@ import {FullStory, init, isInitialized} from '@fullstory/browser'; import type {OnyxEntry} from 'react-native-onyx'; import type {UserMetadata} from '@src/types/onyx'; -import NavigationProperties from './types'; +import type NavigationProperties from './types'; // Placeholder Browser API does not support Manual Page definition class FSPage { From 5a225730b3fa3f2647c1b3f17f7e83a6131b0dc3 Mon Sep 17 00:00:00 2001 From: Daniel Silva Date: Tue, 23 Apr 2024 21:38:09 +0200 Subject: [PATCH 11/15] adding check for fullstory on production environment --- src/libs/fullstory/index.native.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/libs/fullstory/index.native.ts b/src/libs/fullstory/index.native.ts index 10f225ae5c67..c090428fe900 100644 --- a/src/libs/fullstory/index.native.ts +++ b/src/libs/fullstory/index.native.ts @@ -1,6 +1,8 @@ import FullStory, {FSPage} from '@fullstory/react-native'; import type {OnyxEntry} from 'react-native-onyx'; import type {UserMetadata} from '@src/types/onyx'; +import * as Environment from '@src/libs/Environment/Environment'; +import CONST from '@src/CONST'; /** * Fullstory React-Native lib adapter @@ -22,9 +24,14 @@ const FS = { */ consentAndIdentify: (value: OnyxEntry) => { try { - // set consent - FullStory.consent(true); - FS.fsIdentify(value); + Environment.getEnvironment().then((envName: string) => { + if(CONST.ENVIRONMENT.PRODUCTION !== envName) { + return; + } + // We only use FullStory in production environment + FullStory.consent(true); + FS.fsIdentify(value); + }); } catch (e) { // error handler } From e423af17fe3ea50e730540d1b5f3c740c08cc368 Mon Sep 17 00:00:00 2001 From: Daniel Silva Date: Tue, 23 Apr 2024 22:10:40 +0200 Subject: [PATCH 12/15] prettier --- src/libs/fullstory/index.native.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libs/fullstory/index.native.ts b/src/libs/fullstory/index.native.ts index c090428fe900..8b114f5f2c24 100644 --- a/src/libs/fullstory/index.native.ts +++ b/src/libs/fullstory/index.native.ts @@ -1,8 +1,8 @@ import FullStory, {FSPage} from '@fullstory/react-native'; import type {OnyxEntry} from 'react-native-onyx'; -import type {UserMetadata} from '@src/types/onyx'; -import * as Environment from '@src/libs/Environment/Environment'; import CONST from '@src/CONST'; +import * as Environment from '@src/libs/Environment/Environment'; +import type {UserMetadata} from '@src/types/onyx'; /** * Fullstory React-Native lib adapter @@ -25,7 +25,7 @@ const FS = { consentAndIdentify: (value: OnyxEntry) => { try { Environment.getEnvironment().then((envName: string) => { - if(CONST.ENVIRONMENT.PRODUCTION !== envName) { + if (CONST.ENVIRONMENT.PRODUCTION !== envName) { return; } // We only use FullStory in production environment From bd6e49237dd0f5e537f9fcc3406e306504f961c7 Mon Sep 17 00:00:00 2001 From: Daniel Silva Date: Wed, 24 Apr 2024 13:29:43 +0200 Subject: [PATCH 13/15] moving logic to web file --- src/libs/fullstory/index.native.ts | 14 ++++---------- src/libs/fullstory/index.ts | 30 +++++++++++++++++++++--------- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/libs/fullstory/index.native.ts b/src/libs/fullstory/index.native.ts index 8b114f5f2c24..2e097e5ec546 100644 --- a/src/libs/fullstory/index.native.ts +++ b/src/libs/fullstory/index.native.ts @@ -1,7 +1,5 @@ import FullStory, {FSPage} from '@fullstory/react-native'; import type {OnyxEntry} from 'react-native-onyx'; -import CONST from '@src/CONST'; -import * as Environment from '@src/libs/Environment/Environment'; import type {UserMetadata} from '@src/types/onyx'; /** @@ -24,14 +22,10 @@ const FS = { */ consentAndIdentify: (value: OnyxEntry) => { try { - Environment.getEnvironment().then((envName: string) => { - if (CONST.ENVIRONMENT.PRODUCTION !== envName) { - return; - } - // We only use FullStory in production environment - FullStory.consent(true); - FS.fsIdentify(value); - }); + // We only use FullStory in production environment + FullStory.consent(true); + FS.fsIdentify(value); + } catch (e) { // error handler } diff --git a/src/libs/fullstory/index.ts b/src/libs/fullstory/index.ts index 82b4860f12c8..9acced9bdb54 100644 --- a/src/libs/fullstory/index.ts +++ b/src/libs/fullstory/index.ts @@ -1,5 +1,7 @@ import {FullStory, init, isInitialized} from '@fullstory/browser'; import type {OnyxEntry} from 'react-native-onyx'; +import CONST from '@src/CONST'; +import * as Environment from '@src/libs/Environment/Environment'; import type {UserMetadata} from '@src/types/onyx'; import type NavigationProperties from './types'; @@ -27,12 +29,17 @@ const FS = { */ onReady: () => new Promise((resolve) => { - // Initialised via HEAD snippet - if (isInitialized()) { - init({orgId: ''}, resolve); - } else { - FullStory('observe', {type: 'start', callback: 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}); + } + }); }), /** @@ -50,9 +57,14 @@ const FS = { */ consentAndIdentify: (value: OnyxEntry) => { try { - FS.onReady().then(() => { - FS.consent(true); - FS.fsIdentify(value); + Environment.getEnvironment().then((envName: string) => { + if (CONST.ENVIRONMENT.PRODUCTION !== envName) { + return; + } + FS.onReady().then(() => { + FS.consent(true); + FS.fsIdentify(value); + }); }); } catch (e) { // error handler From 669936270d21ea59c34a798d445efd6a1f35a0ac Mon Sep 17 00:00:00 2001 From: Daniel Silva Date: Wed, 24 Apr 2024 13:34:55 +0200 Subject: [PATCH 14/15] prettier --- src/libs/fullstory/index.native.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libs/fullstory/index.native.ts b/src/libs/fullstory/index.native.ts index 2e097e5ec546..67d7c7f2fe90 100644 --- a/src/libs/fullstory/index.native.ts +++ b/src/libs/fullstory/index.native.ts @@ -25,7 +25,6 @@ const FS = { // We only use FullStory in production environment FullStory.consent(true); FS.fsIdentify(value); - } catch (e) { // error handler } From bdad22607809103ffa0ac14f25bb09df0754e99a Mon Sep 17 00:00:00 2001 From: Daniel Silva Date: Wed, 24 Apr 2024 13:42:46 +0200 Subject: [PATCH 15/15] changing function to init only if it's not initialized --- src/libs/fullstory/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/fullstory/index.ts b/src/libs/fullstory/index.ts index 9acced9bdb54..5b60f20f9ddf 100644 --- a/src/libs/fullstory/index.ts +++ b/src/libs/fullstory/index.ts @@ -34,7 +34,7 @@ const FS = { return; } // Initialised via HEAD snippet - if (isInitialized()) { + if (!isInitialized()) { init({orgId: ''}, resolve); } else { FullStory('observe', {type: 'start', callback: resolve});