Skip to content

fix(analytics): run heatmap view mode in a window Studio opened - #848

Merged
thalesvf merged 2 commits into
mainfrom
analytics-view-in-window
Nov 25, 2026
Merged

thalesvf merged 2 commits into
mainfrom
analytics-view-in-window

Conversation

@thalesvf

@thalesvf thalesvf commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Why

This keeps the analytics copy in sync with decocms/analytics#77. Some commerce platforms fix a store's frame-ancestors to the store's own domain, so Studio's Heatmap tab can never frame those stores. Studio now opens the store in a window instead, and the view chunk has to talk to the window that opened it.

What changes

  • runtime/src/index.ts: view mode starts when the URL has dq_view=1 and the page is framed or has an opener.
  • runtime/view/view.ts: the parent is window.parent when framed, else window.opener. A frame keeps the *.decocms.com allow-list. An opener must be Studio itself (studio.decocms.com, studio-stg.decocms.com or localhost): a window skips the store's frame-ancestors and carries the visitor's cookies, and the wildcard includes sandbox previews.

Until decocms/analytics builds the tag from this package (task 3.7), its runtime/ is what production serves. That is why the change lands in both copies.

Verification

  • node ops/build-tag.mjs --check --src <this repo>/packages/blocks/src/v8/analytics, run from decocms/analytics#77: "matches worker/tag.lock.json (10 bundles)".
  • bun run typecheck passed on every package.
  • biome check on src/v8/analytics/runtime is clean.
  • npx vitest run packages/blocks/src/v8/analytics: 48 passed.

Summary by cubic

Fixes analytics heatmap view mode to work on stores that can't be framed by Studio. Some commerce platforms fix a store's frame-ancestors to its own domain, so Studio now opens those stores in a window, and the heatmap view chunk must talk to the window that opened it. View mode starts when the URL carries dq_view=1 and the page is framed or has an opener; the parent is window.parent when framed, else window.opener. Because a window carries the visitor's cookies and skips the store's frame-ancestors, windows accept only Studio itself (studio.decocms.com, studio-stg.decocms.com, localhost) as opener, while frames keep the existing *.decocms.com allow-list. Mirrors decocms/analytics#77 so both copies build to the same bytes.

Written for commit 21fc38a. Summary will update on new commits.

View guided diff Turn on auto-fix

Some commerce platforms fix a store's frame-ancestors to its own domain,
so Studio can never frame those stores to draw their heatmap. View mode
now also starts when the page has an opener, and the view chunk speaks
to window.opener when it is not framed. The allow-list and origin pinning
are unchanged.

Mirrors decocms/analytics#77: both copies build to the same bytes.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Mirrors decocms/analytics#77. Frames accept any *.decocms.com parent,
sandbox previews included. A window skips the store's frame-ancestors
and carries the visitor's cookies, so an opener must be
studio.decocms.com, studio-stg.decocms.com or localhost.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@thalesvf
thalesvf merged commit 3f2e6d3 into main Nov 25, 2026
4 checks passed
@thalesvf
thalesvf deleted the analytics-view-in-window branch November 25, 2026 20:16
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 8.22.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants