Skip to content

iImplement fullStory analytics instrumentation - #93051

Merged
JS00001 merged 45 commits into
Expensify:mainfrom
nabi-ebrahimi:feat/fullstory-analytics-instrumentation
Jul 22, 2026
Merged

JS00001 merged 45 commits into
Expensify:mainfrom
nabi-ebrahimi:feat/fullstory-analytics-instrumentation

Conversation

@nabi-ebrahimi

@nabi-ebrahimi nabi-ebrahimi commented Jun 9, 2026 •

Copy link
Copy Markdown

Explanation of Change

These changes add the first part of the FullStory instrumentation requested in this issue.

Previously, the app initialized FullStory but did not sync the requested user/workspace/onboarding context or emit an explicit Page_viewed event. Now, a renderless useOnyx-based handler derives and syncs FullStory user vars through FS.setUserVars(...), and navigation changes emit a Page_viewed event.

Fixed Issues

$ #92006
PROPOSAL: #92006 (Comment)

Tests

  • Verify that no errors appear in the JS console

Offline tests

N/A

QA Steps

N/A

// TODO: These must be filled out, or the issue title must include "[No QA]."

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari

@codecov

codecov Bot commented Jun 9, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ Changes either increased or maintained existing code coverage, great job!

Files with missing lines Coverage Δ
src/Expensify.tsx 87.28% <ø> (ø)
src/libs/Navigation/NavigationRoot.tsx 77.67% <100.00%> (+1.44%) ⬆️
src/libs/Fullstory/common.ts 56.52% <95.00%> (+56.52%) ⬆️
src/libs/Fullstory/index.ts 0.00% <0.00%> (ø)
src/libs/Fullstory/index.native.ts 0.00% <0.00%> (ø)
src/libs/Fullstory/utils.ts 86.51% <86.51%> (ø)
src/FullstoryUserContextHandler.tsx 45.65% <45.65%> (ø)
... and 6 files with indirect coverage changes

@melvin-bot
melvin-bot Bot requested review from situchan and trjExpensify and removed request for a team June 9, 2026 12:22
@melvin-bot

melvin-bot Bot commented Jun 9, 2026

Copy link
Copy Markdown

@situchan Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@melvin-bot
melvin-bot Bot removed the request for review from a team June 9, 2026 12:22
Comment thread tests/unit/FullstoryUtilsTest.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e17bd10545

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/FullstoryUserContextHandler.tsx Resolved
Comment thread src/libs/Fullstory/utils.ts Resolved
Comment thread src/FullstoryUserContextHandler.tsx Resolved
trjExpensify
trjExpensify previously approved these changes Jun 9, 2026

@trjExpensify trjExpensify left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excited for it! 👍

@nabi-ebrahimi

Copy link
Copy Markdown
Author

@situchan, I've addressed all the feedback. all yours—thanks!

@nabi-ebrahimi

Copy link
Copy Markdown
Author

@situchan, friendly bump. thanks.

@nabi-ebrahimi

Copy link
Copy Markdown
Author

@situchan, kindly bump, thanks

@JS00001

JS00001 commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

@situchan can you please review/help move this along

@situchan

Copy link
Copy Markdown
Contributor

@nabi-ebrahimi please pull main

@dylanexpensify

Copy link
Copy Markdown
Contributor

@nabi-ebrahimi bump!

@situchan

Copy link
Copy Markdown
Contributor

Lots of tests failing

@nabi-ebrahimi

Copy link
Copy Markdown
Author

@situchan, I addressed the actionable items: entry_point now uses the previous tracked path, native identify keeps the existing property shape, and the session URL readiness check is documented.

The remaining points look intentional/non-blocking for this first slice, especially the web/native FullStory property format difference.

@nabi-ebrahimi

Copy link
Copy Markdown
Author

@situchan, Gentle bump. thanks.

@situchan

Copy link
Copy Markdown
Contributor

I am still not seeing my accounts in FS dashboard. Isn't fullstory supposed to be enabled in adhoc build?

@nabi-ebrahimi can you share your test emails so I can see if they're shown in dashboard? Also test adhoc builds.

@situchan

Copy link
Copy Markdown
Contributor

const shouldInitializeFullstory: ShouldInitialize = (userMetadata, envName) => {
const isTestEmail = userMetadata.email !== undefined && userMetadata.email.startsWith('fullstory') && userMetadata.email.endsWith(CONST.EMAIL.QA_DOMAIN);
if ((CONST.ENVIRONMENT.PRODUCTION !== envName && !isTestEmail) || Str.extractEmailDomain(userMetadata.email ?? '') === CONST.EXPENSIFY_PARTNER_NAME) {
return false;
}
return true;
};

Looks like Fullstory is enabled only in production or when email has fullstory prefix.

@nabi-ebrahimi

Copy link
Copy Markdown
Author

@nabi-ebrahimi can you share your test emails so I can see if they're shown in dashboard? Also test adhoc builds.

@situchan Thanks for checking. As I mentioned earlier, I don’t have a FullStory-enabled QA account, so I’m not able to verify this directly in the FullStory dashboard from my side.

I tested what I could locally via console logs based on your earlier suggestion:

@situchan

Copy link
Copy Markdown
Contributor

@nabi-ebrahimi please check this last feedback from AI:

🔴 Cross-platform bug — free-trial date fails to parse on Safari/iOS/Android

utils.ts getFreeTrialEndDate:

const endDate = new Date(`${dateString}Z`);   // dateString = "2099-05-31 23:59:59"

freeTrialEndDate comes from the backend in the DB format YYYY-MM-DD HH:mm:ss (space-separated — confirmed by DateUtils.ts:357). Appending Z yields "2099-05-31 23:59:59Z", which is not valid ISO 8601 (ISO requires a T separator). Parsing behavior:

  • Chrome / Node-V8 (jest): lenient → parses fine. ✅
  • mWeb Safari (JSC), iOS native, Android native (Hermes, hermesEnabled=true): strict → Invalid Date. ❌

On every platform except Chrome, getFreeTrialEndDate returns undefined, so free_trial_end_date, days_till_trial_end, and free_trial_status are all silently dropped from the FullStory user vars. Three of the advertised metrics won't be recorded on the majority of platforms.

Critically, the tests don't catch this: FullstoryUtilsTest runs on jest/V8 (lenient), and FullstoryCommonTest sidesteps the parser entirely by constructing new Date('2099-05-31T23:59:59Z') with a literal T. So CI is green while native/Safari silently lose the data.

Fix: use the codebase's established safe parser — fromZonedTime(dateString, 'UTC') from date-fns-tz (already used at DateUtils.ts:371) — or at minimum normalize the separator: new Date(${dateString.replace(' ', 'T')}Z). And add a test that exercises the space-separated input through getFreeTrialEndDate/buildFullstoryUserVars.

🟡 previousFullstoryPath is a module global, never reset across sessions

NavigationRoot.tsx:

let previousFullstoryPath: string | undefined;
...
trackFullstoryEvent('Page_viewed', buildPageViewedEvent(focusedRouteName, currentPath, previousFullstoryPath));
previousFullstoryPath = currentPath;

entry_point is now the previous path. Since previousFullstoryPath is module-scoped and never cleared on logout/account switch, the first Page_viewed for a newly logged-in user carries the previous user's last path as entry_point. Minor accuracy/cross-session-leak concern. (Positive side: it's only updated inside the !isTransitionRoute branch, so it never holds an authToken-bearing transition path — good.)

Recommendation

One blocker: the date-parsing bug (🔴) — it silently breaks the free-trial metrics on Safari, iOS, and Android (i.e. everywhere but Chrome), and current tests give false confidence. Switch to fromZonedTime/T-separator and add a native-representative test.
The previousFullstoryPath reset is a nice-to-fix; the two behavior changes just need confirmation.

@nabi-ebrahimi

Copy link
Copy Markdown
Author

@situchan Addressed both points. Please take another look when you get a chance. Thanks!

@situchan

Copy link
Copy Markdown
Contributor

const shouldInitializeFullstory: ShouldInitialize = (userMetadata, envName) => {
const isTestEmail = userMetadata.email !== undefined && userMetadata.email.startsWith('fullstory') && userMetadata.email.endsWith(CONST.EMAIL.QA_DOMAIN);
if ((CONST.ENVIRONMENT.PRODUCTION !== envName && !isTestEmail) || Str.extractEmailDomain(userMetadata.email ?? '') === CONST.EXPENSIFY_PARTNER_NAME) {
return false;
}
return true;
};

Looks like Fullstory is enabled only in production or when email has fullstory prefix.

@JS00001 I think we can merge this as-is and observe logs when this PR reaches production

@melvin-bot
melvin-bot Bot requested a review from JS00001 July 21, 2026 15:13

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2a7d0f4238

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/libs/Navigation/NavigationRoot.tsx Resolved
JS00001
JS00001 previously approved these changes Jul 21, 2026
@nabi-ebrahimi

Copy link
Copy Markdown
Author

@JS00001, Addressed the latest feedback, all yours. Thanks!

@JS00001
JS00001 merged commit 046d450 into Expensify:main Jul 22, 2026
36 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

🚧 JS00001 has triggered a test Expensify/App build. You can view the workflow run here.

@OSBotify

Copy link
Copy Markdown
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify OSBotify mentioned this pull request Jul 22, 2026
52 tasks done
@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/JS00001 in version: 9.4.43-0 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

@MelvinBot

Copy link
Copy Markdown
Contributor

🤖 Help site review — no changes required

I reviewed the changes in this PR against the help site articles under App/docs/articles.

Conclusion: No help site updates are needed, so I have not created a draft PR.

Why: These changes are purely internal analytics instrumentation for FullStory:

  • A renderless FullstoryUserContextHandler that derives user/workspace/onboarding context and syncs it via FS.setUserVars(...).
  • Navigation changes now emit a Page_viewed telemetry event.
  • Supporting utilities, types, and unit tests.

None of this introduces or changes any user-facing feature, UI, setting, button, or copy. FullStory instrumentation runs behind the scenes for session analytics and is invisible to customers, so there is nothing to document on the public help site. The only strings touched (e.g. element_label, /settings/... path matchers) are internal analytics variable names and test fixtures, not product-facing labels.


@nabi-ebrahimi, there is no linked help site PR since no documentation changes were required. If you believe a customer-facing aspect of this work does warrant a help site update, let me know the specifics and I'll draft one.

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/yuwenmemon in version: 9.4.43-1 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

Bundle Size Analysis (Sentry):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants