Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
8079078
iImplement fullStory analytics instrumentation
nabi-ebrahimi Jun 9, 2026
e17bd10
Merge branch 'main' into feat/fullstory-analytics-instrumentation
nabi-ebrahimi Jun 9, 2026
53d9ab3
wait for FullStory before syncing user vars
nabi-ebrahimi Jun 9, 2026
a047a71
add FullStory timing constants
nabi-ebrahimi Jun 9, 2026
ffe367b
fix lint
nabi-ebrahimi Jun 9, 2026
c9af14a
fix FullStory test fixture
nabi-ebrahimi Jun 9, 2026
44c3334
Merge branch 'main' into feat/fullstory-analytics-instrumentation
nabi-ebrahimi Jun 9, 2026
067f697
Merge branch 'main' into feat/fullstory-analytics-instrumentation
nabi-ebrahimi Jun 10, 2026
aae1cbf
fix fullStory login list key
nabi-ebrahimi Jun 10, 2026
27ad354
Format FullStory files
nabi-ebrahimi Jun 10, 2026
2bf7e1a
Merge branch 'main' into feat/fullstory-analytics-instrumentation
nabi-ebrahimi Jun 19, 2026
5ff2b0c
Merge branch 'main' into feat/fullstory-analytics-instrumentation
nabi-ebrahimi Jun 19, 2026
41bc5ce
Fix FullStory route typecheck
nabi-ebrahimi Jun 19, 2026
09ca2c8
fix prettier
nabi-ebrahimi Jun 19, 2026
37ae691
Merge branch 'main' into feat/fullstory-analytics-instrumentation
nabi-ebrahimi Jun 23, 2026
092386b
Avoid FullStory auto-init
nabi-ebrahimi Jun 23, 2026
e056ce9
Merge branch 'main' into feat/fullstory-analytics-instrumentation
nabi-ebrahimi Jun 24, 2026
0d86c0b
fix fullStory onboarding path matching
nabi-ebrahimi Jun 24, 2026
c877b85
fix fullStory context tracking
nabi-ebrahimi Jun 24, 2026
9416fff
fix fullStory toggle key
nabi-ebrahimi Jun 24, 2026
5aed0a9
Merge branch 'main' into feat/fullstory-analytics-instrumentation
nabi-ebrahimi Jun 24, 2026
cd8eac2
Merge branch 'main' into feat/fullstory-analytics-instrumentation
nabi-ebrahimi Jun 30, 2026
439f83b
skip fullStory transition routes
nabi-ebrahimi Jun 30, 2026
7bb6cce
fix fullStory tracking
nabi-ebrahimi Jun 30, 2026
25bf535
Merge branch 'main' into feat/fullstory-analytics-instrumentation
nabi-ebrahimi Jul 2, 2026
391a960
add native FullStory property normalization
nabi-ebrahimi Jul 2, 2026
dab71d8
fix fullStory lint
nabi-ebrahimi Jul 2, 2026
0fb7fff
Merge branch 'main' into feat/fullstory-analytics-instrumentation
nabi-ebrahimi Jul 3, 2026
94b9ecb
fix fmt
nabi-ebrahimi Jul 3, 2026
5c0d986
fix FullStory user vars
nabi-ebrahimi Jul 3, 2026
0b2d491
sync fullStory trial dates
nabi-ebrahimi Jul 3, 2026
0127530
Merge branch 'main' into feat/fullstory-analytics-instrumentation
nabi-ebrahimi Jul 4, 2026
d462d75
fix FullStory dedupe and dates
nabi-ebrahimi Jul 4, 2026
f136558
Guard native FullStory events
nabi-ebrahimi Jul 4, 2026
038a046
fix lint
nabi-ebrahimi Jul 4, 2026
649e766
Merge branch 'main' into feat/fullstory-analytics-instrumentation
nabi-ebrahimi Jul 15, 2026
1f5a394
Fix FullStory entry point
nabi-ebrahimi Jul 15, 2026
7b4b829
Document FullStory readiness gate
nabi-ebrahimi Jul 15, 2026
a8b35f3
Preserve native identify vars
nabi-ebrahimi Jul 15, 2026
636032f
Fix FullStory entry point
nabi-ebrahimi Jul 15, 2026
4492876
Merge branch 'main' into feat/fullstory-analytics-instrumentation
nabi-ebrahimi Jul 21, 2026
a6b4f6c
fix FullStory trial date parsing
nabi-ebrahimi Jul 21, 2026
2a7d0f4
Reset FullStory entry point
nabi-ebrahimi Jul 21, 2026
d69b0d3
Merge branch 'main' into feat/fullstory-analytics-instrumentation
nabi-ebrahimi Jul 22, 2026
8936975
Track initial FullStory page view
nabi-ebrahimi Jul 22, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Expensify.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import CONST from './CONST';
import DeepLinkHandler from './DeepLinkHandler';
import DelegateAccessHandler from './DelegateAccessHandler';
import FullstoryInitHandler from './FullstoryInitHandler';
import FullstoryUserContextHandler from './FullstoryUserContextHandler';
import GlobalModals from './GlobalModals';
import useDebugShortcut from './hooks/useDebugShortcut';
import useIsAuthenticated from './hooks/useIsAuthenticated';
Expand Down Expand Up @@ -288,6 +289,7 @@ function Expensify() {
<PriorityModeHandler />
<DelegateAccessHandler />
<FullstoryInitHandler />
<FullstoryUserContextHandler />
<DeepLinkHandler onInitialUrl={setInitialUrl} />
<AppleAuthWrapper />
{/* Wait for the initial URL to resolve before mounting NavigationRoot, because its initialState
Expand Down
120 changes: 120 additions & 0 deletions src/FullstoryUserContextHandler.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import {useEffect, useRef} from 'react';

import useOnyx from './hooks/useOnyx';
import getEnvironment from './libs/Environment/getEnvironment';
import FS from './libs/Fullstory';
import {buildFullstoryUserVars, getComparableFullstoryUserVars} from './libs/Fullstory/utils';
import {shallowCompare} from './libs/ObjectUtils';
import ONYXKEYS from './ONYXKEYS';

const SESSION_URL_RETRY_DELAY_MS = 250;
const MAX_SESSION_URL_RETRY_ATTEMPTS = 20;

function FullstoryUserContextHandler() {
const [account] = useOnyx(ONYXKEYS.ACCOUNT);
const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID);
const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED);
const [onboarding] = useOnyx(ONYXKEYS.NVP_ONBOARDING);
const [onboardingCompanySize] = useOnyx(ONYXKEYS.ONBOARDING_COMPANY_SIZE);
const [onboardingLastVisitedPath] = useOnyx(ONYXKEYS.ONBOARDING_LAST_VISITED_PATH);
const [onboardingPurposeSelected] = useOnyx(ONYXKEYS.ONBOARDING_PURPOSE_SELECTED);
const [policies] = useOnyx(ONYXKEYS.COLLECTION.POLICY);
const [session] = useOnyx(ONYXKEYS.SESSION);
const [userMetadata] = useOnyx(ONYXKEYS.USER_METADATA);

const activePolicy = activePolicyID ? policies?.[`${ONYXKEYS.COLLECTION.POLICY}${activePolicyID}`] : undefined;

const previousUserVars = useRef<ReturnType<typeof getComparableFullstoryUserVars> | undefined>(undefined);
const previousAccountID = useRef<number | undefined>(undefined);
const sessionURLRetryAttempts = useRef(0);

useEffect(() => {
if (!userMetadata?.accountID) {
return;
}

let didCancel = false;
let retryTimeoutID: ReturnType<typeof setTimeout> | undefined;

const syncUserVars = () => {
getEnvironment()
.then((envName) => {
if (didCancel || !FS.shouldInitialize(userMetadata, envName)) {
return;
}

// Use the session URL only as a readiness signal so this handler waits for the existing FullStory init path.
return FS.getSessionURL().then((sessionURL) => {
if (didCancel) {
return;
}

if (!sessionURL) {
sessionURLRetryAttempts.current += 1;
if (sessionURLRetryAttempts.current >= MAX_SESSION_URL_RETRY_ATTEMPTS) {
return;
}

retryTimeoutID = setTimeout(syncUserVars, SESSION_URL_RETRY_DELAY_MS);
return;
}

sessionURLRetryAttempts.current = 0;

if (previousAccountID.current !== userMetadata.accountID) {
previousAccountID.current = userMetadata.accountID;
previousUserVars.current = undefined;
}

const userVars = buildFullstoryUserVars({
account,
activePolicy,
introSelected,
onboarding,
onboardingCompanySize,
onboardingLastVisitedPath,
onboardingPurposeSelected,
policies,
session,
userMetadata,
});

const comparableUserVars = getComparableFullstoryUserVars(userVars);

if (shallowCompare(previousUserVars.current, comparableUserVars)) {
return;
}

previousUserVars.current = comparableUserVars;
FS.setUserVars(userVars);
Comment thread
nabi-ebrahimi marked this conversation as resolved.
Resolved
});
})
.catch(() => {
if (didCancel) {
return;
}

sessionURLRetryAttempts.current += 1;
if (sessionURLRetryAttempts.current >= MAX_SESSION_URL_RETRY_ATTEMPTS) {
return;
}

retryTimeoutID = setTimeout(syncUserVars, SESSION_URL_RETRY_DELAY_MS);
});
};

syncUserVars();

return () => {
didCancel = true;
sessionURLRetryAttempts.current = 0;
if (retryTimeoutID) {
clearTimeout(retryTimeoutID);
}
};
}, [account, activePolicy, introSelected, onboarding, onboardingCompanySize, onboardingLastVisitedPath, onboardingPurposeSelected, policies, session, userMetadata]);

return null;
}

export default FullstoryUserContextHandler;
42 changes: 41 additions & 1 deletion src/libs/Fullstory/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ const allowedReportChatTypes = new Set<ValueOf<typeof CONST.REPORT.CHAT_TYPE>>([

const allowedReportTypes = new Set<ValueOf<typeof CONST.REPORT.TYPE>>([CONST.REPORT.TYPE.IOU, CONST.REPORT.TYPE.EXPENSE, CONST.REPORT.TYPE.INVOICE]);

type FullstoryPropertyValue = string | number | boolean | Date | null | undefined;

type NormalizeFullstoryPropertiesForNativeOptions = {
preserveKeys?: readonly string[];
};

const getChatFSClass: GetChatFSClass = (report) => {
if (!report) {
return CONST.FULLSTORY.CLASS.UNMASK;
Expand Down Expand Up @@ -76,4 +82,38 @@ const shouldInitializeFullstory: ShouldInitialize = (userMetadata, envName) => {
return true;
};

export {getChatFSClass, shouldInitializeFullstory};
function normalizeFullstoryPropertiesForNative(
properties: Record<string, FullstoryPropertyValue>,
{preserveKeys = []}: NormalizeFullstoryPropertiesForNativeOptions = {},
): Record<string, string | number | boolean> {
const normalizedProperties: Record<string, string | number | boolean> = {};
const preservedKeys = new Set(preserveKeys);

for (const [key, value] of Object.entries(properties)) {
if (value === undefined || value === null) {
continue;
}

if (preservedKeys.has(key)) {
normalizedProperties[key] = value instanceof Date ? value.toISOString() : value;
continue;
}

if (value instanceof Date) {
normalizedProperties[`${key}_date`] = value.toISOString();
continue;
}

if (typeof value === 'string') {
normalizedProperties[`${key}_str`] = value;
} else if (typeof value === 'number') {
normalizedProperties[`${key}_real`] = value;
} else if (typeof value === 'boolean') {
normalizedProperties[`${key}_bool`] = value;
}
}

return normalizedProperties;
}

export {getChatFSClass, normalizeFullstoryPropertiesForNative, shouldInitializeFullstory};
23 changes: 17 additions & 6 deletions src/libs/Fullstory/index.native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import FullStory, {FSPage} from '@fullstory/react-native';

import type {Fullstory} from './types';

import {getChatFSClass, shouldInitializeFullstory} from './common';
import {getChatFSClass, normalizeFullstoryPropertiesForNative, shouldInitializeFullstory} from './common';

let isFullstoryTrackingEnabled = false;

const FS: Fullstory = {
Page: FSPage,
Expand All @@ -20,8 +22,7 @@ const FS: Fullstory = {
consent: (shouldConsent) => FullStory.consent(shouldConsent),

identify: (userMetadata, envName) => {
const localMetadata = userMetadata;
localMetadata.environment = envName;
const localMetadata = {...userMetadata, environment: envName};
FullStory.identify(String(localMetadata.accountID), localMetadata);
},

Expand All @@ -36,6 +37,7 @@ const FS: Fullstory = {
// 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.
isFullstoryTrackingEnabled = false;
getEnvironment().then((envName: string) => {
if (!FS.shouldInitialize(userMetadata, envName)) {
return;
Expand All @@ -44,6 +46,7 @@ const FS: Fullstory = {
FullStory.restart();
FullStory.consent(true);
FS.identify(userMetadata, envName);
isFullstoryTrackingEnabled = true;
});
} catch (e) {
// error handler
Expand All @@ -60,8 +63,12 @@ const FS: Fullstory = {
return FullStory.getCurrentSessionURL();
},

event: (eventName, eventProperties = {}) => {
FullStory.event(eventName, eventProperties);
event: (eventName, eventProperties) => {
if (!isFullstoryTrackingEnabled) {
return;
}

FullStory.event(eventName, normalizeFullstoryPropertiesForNative(eventProperties ?? {}));
},

log: (level, message) => {
Expand All @@ -75,7 +82,11 @@ const FS: Fullstory = {
},

setUserVars: (userVars) => {
FullStory.setUserVars(userVars);
FullStory.setUserVars(
normalizeFullstoryPropertiesForNative(userVars, {
preserveKeys: ['displayName', 'email'],
}),
);
},

resetIdleTimer: () => {
Expand Down
4 changes: 2 additions & 2 deletions src/libs/Fullstory/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ const FS: Fullstory = {
return FullStory('getSessionAsync', {format: 'url'});
},

event: (eventName, eventProperties = {}) => {
event: (eventName, eventProperties) => {
if (!isInitialized()) {
return;
}
FullStory(CONST.FULLSTORY.OPERATION.TRACK_EVENT, {name: eventName, properties: eventProperties});
FullStory(CONST.FULLSTORY.OPERATION.TRACK_EVENT, {name: eventName, properties: eventProperties ?? {}});
},

log: (level, message) => {
Expand Down
Loading
Loading