Skip to content

feat: support analytics for custom code section#1262

Merged
jhelenek merged 4 commits into
mainfrom
analytics-branch
Jul 13, 2026
Merged

feat: support analytics for custom code section#1262
jhelenek merged 4 commits into
mainfrom
analytics-branch

Conversation

@jhelenek

@jhelenek jhelenek commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

This PR supports analytics for custom code section. It adds the Analytics track method to the window so that inner-components are able to reference it. Each analytics is registered by componentId so multiple custom code components can coexist without overwriting each other's handlers.

TEST=manual
Created a dev-release with this change and set it up with a site. For that site's layout, create 3 separate custom code components, each with different analytic calls. Deployed changes and saw analytic events come in both on the network tab and in Snowflake.

Snowflake query:
select * from prod_analytics2.public.analytics_events where original_business_id = 4146665 order by event_timestamp desc;

Example Javascript used in custom code component:

function trackCustomClick(button) {
  button.textContent = "Clickedddddd";

  window.YextCustomCodeAnalytics.track({
    scope: "customCodeComponent",
    eventName: "Custom Button Clicked",
    action: "LINK",
    buttonText: "Track Click",
  });
}

Video:
https://drive.google.com/file/d/1SVUUV4njl_fKxF-ZfO3aDrCqPrm3PgAx/view?usp=drive_link

@jhelenek jhelenek added the create-dev-release Triggers dev release workflow label Jul 9, 2026
@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Warning: Component files have been updated but no migrations have been added. See https://github.com/yext/visual-editor/blob/main/packages/visual-editor/src/components/migrations/README.md for more information.

@pkg-pr-new

pkg-pr-new Bot commented Jul 9, 2026

Copy link
Copy Markdown

commit: 474193d

@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@jhelenek, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 16 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: c3c7abb2-014f-48a3-9b97-df5ef956f94d

📥 Commits

Reviewing files that changed from the base of the PR and between e1dec70 and 474193d.

📒 Files selected for processing (1)
  • packages/visual-editor/src/utils/VisualEditorProvider.tsx

Walkthrough

VisualEditorProvider now imports analytics support and exposes a typed window.YextCustomCodeAnalytics global. Its track method forwards requests to pagesAnalytics.track when available. A browser-aware effect uses useLayoutEffect in the browser and useEffect during SSR, and removes the global analytics object when the provider unmounts.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly summarizes the main change: adding analytics support for the custom code section.
Description check ✅ Passed The description matches the change and explains exposing track on window for custom code components.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch analytics-branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/visual-editor/src/components/customCode/CustomCodeSection.tsx`:
- Around line 205-216: The injected user script in CustomCodeSection’s script
creation is wrapped in a block, which prevents global handler resolution for
inline callbacks like onclick="changeColor(this)". Update the script injection
around processedJavascript so user code runs at top level instead of inside a
block, and provide yextAnalytics through another mechanism in the same
CustomCodeSection flow without relying on block-scoped declarations.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: f613126d-9a2d-4221-aba2-0222a8921d7f

📥 Commits

Reviewing files that changed from the base of the PR and between 99d3414 and cbe76b4.

📒 Files selected for processing (1)
  • packages/visual-editor/src/components/customCode/CustomCodeSection.tsx

Comment thread packages/visual-editor/src/components/customCode/CustomCodeSection.tsx Outdated
@jhelenek jhelenek changed the title [DRAFT] Support analytics for custom code section feat: support analytics for custom code section Jul 9, 2026
@jhelenek
jhelenek marked this pull request as ready for review July 9, 2026 20:13
Comment thread packages/visual-editor/src/components/customCode/CustomCodeSection.tsx Outdated
Comment thread packages/visual-editor/src/components/customCode/CustomCodeSection.tsx Outdated

@mkilpatrick mkilpatrick left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I was thinking how to make it easy to use but there's nothing that's going to work since it's raw JS (no TS) anyways. We'll have to rely on documentation.

Comment thread packages/visual-editor/src/utils/VisualEditorProvider.tsx
@jhelenek
jhelenek requested a review from mkilpatrick July 13, 2026 13:45
@jhelenek
jhelenek merged commit 2f06827 into main Jul 13, 2026
17 checks passed
@jhelenek
jhelenek deleted the analytics-branch branch July 13, 2026 16:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

create-dev-release Triggers dev release workflow

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants