Only track embed view events once the frame is shown (RND-12362) - #4517
Open
nolannbiron wants to merge 2 commits into
Open
Only track embed view events once the frame is shown (RND-12362)#4517nolannbiron wants to merge 2 commits into
nolannbiron wants to merge 2 commits into
Conversation
🦋 Changeset detectedLatest commit: 0620615 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
|
The latest updates on your projects. Learn more about Argos notifications ↗︎
|
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.
Fixes RND-12362.
The embedded Assistant emitted
ask_viewfrom a mount-time effect, with no checkthat a reader ever saw it. The frame is mounted long before it is shown:
getIframe(), whichconfigurecalls eagerly — so the documented quickstart loads the frame into a
display: nonecontainer on every host page load.
~gitbook/embedserver-redirects to/assistant, so the assistant mounts on everyframe load.
configureonly arrives later over the channel, so hosts whose tabsexclude the assistant still emitted an
ask_viewbefore being redirected away.Result: 9,012,281 embed
ask_viewagainst 26,609 embedask_questionin July 2026(339:1), versus 0.44:1 on the site surface, where the event is gated on
chat.opened.The same mechanism inflated
search_openand embedpage_viewwhenever theconfigured tabs made one of those the landing route, so those are gated too.
Approach
A new
VisibilityContextdetects real visibility from inside the frame with anIntersectionObserver: a non-rendered iframe has a zero-sized viewport, so theobserver stays non-intersecting until the host reveals it. Visibility latches once
shown — an observer inside an iframe also reports the host page scrolling it out of
view, and scrolling past an inline
GitBookFrameis not a new view. Returning to theAssistant tab still counts, because that remounts the consumer.
page_viewis unaffected on the site surface: with no provider, the context defaultsto
true.No
@gitbook/embedprotocol change, so this takes effect for every host immediatelyrather than only after they upgrade.
Verification
Verified against the real app using the
?trigger=customdemo, which loads the framebut leaves the window closed:
display: none,innerWidth: 0, nobody opened anything →ask_viewfires. Bug reproduced.
/~gitbook/__evtrequests. Open → exactly one
ask_view. Close and reopen → still one. Docs tab →page_view; back to Assistant → a newask_view. Site-surfacepage_viewstillfires on first paint with
displayContext: "site".Covered by a new e2e case in the
Docs Embed - Basicsuite.Note
A distinct frame-render event — the alternative suggested on the issue — isn't
possible from this repo:
SITE_INSIGHTS_EVENT_TYPE_ENUMlives in the external@gitbook/apipackage. If that's wanted too, it needs an API-side change first.