feat: capture marketplace app iframe sessions in Fullstory [AIS-488] - #11284
Draft
Jared Jolton (jjolton-contentful) wants to merge 1 commit into
Draft
Jared Jolton (jjolton-contentful) wants to merge 1 commit into
Jared Jolton (jjolton-contentful) wants to merge 1 commit into
Conversation
Wrap the app root in SegmentAnalyticsProvider so the app reports to its own Segment source, and set the Fullstory iframe flag before Segment loads so the app's session capture is attributed to the parent web app session instead of a standalone one. The write key is supplied at build time as VITE_SEGMENT_WRITE_KEY. Segment write keys are write-only ingest keys and are safe to expose in a client bundle. Only the toolkit is added as a direct dependency; it already brings @segment/analytics-next, so the app does not need it separately. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
AIS-488
Summary
SegmentAnalyticsProviderso the app reports to its own Segment source. The write key comes fromVITE_SEGMENT_WRITE_KEY, injected at build time the same way the app's four existingVITE_*variables are.window._fs_run_in_iframe = trueat entrypoint module scope. Without it, Fullstory treats a cross-origin iframe as its own root session, so the app's capture would be disjoint from the surrounding web app session. Apps are served from*.ctfapps.netwhile the parent isapp.contentful.com, so this is always cross-origin. The assignment has to happen before Segment loadsfs.js, which is why it is in the entrypoint rather than a component.@segment/analytics-next, so the app does not need it separately.Segment write keys are write-only ingest keys and are safe to expose in a client bundle.
Verified
npx tsc --noEmitexits 0npm run buildexits 0, and the emitted bundle contains both the flag and the injected key_fs_run_in_iframeistrue,_fs_is_outer_scriptisundefined,_fs_orgmatches the parent, andfs.jsloaded.fs-debug.jslogsAsking for a frame ID.followed byFrameId received within frame ..., which is the inner and outer Fullstory instances negotiating so the iframe joins the parent's capture rather than starting its own.npm.pkg.github.comURLs.Not ready yet
VITE_SEGMENT_WRITE_KEYneeds to exist in CircleCI. Merging before then would build staging and production with an empty key, making the provider a no-op.Test plan
VITE_SEGMENT_WRITE_KEYpresent in the staging buildGenerated with Claude Code