Skip to content

Redo Segment integration#2119

Merged
alexandratran merged 1 commit into
mainfrom
sdk-react-fixes
Jun 25, 2025
Merged

Redo Segment integration#2119
alexandratran merged 1 commit into
mainfrom
sdk-react-fixes

Conversation

@alexandratran

@alexandratran alexandratran commented Jun 25, 2025

Copy link
Copy Markdown
Contributor

Description

Fix for Segment duplicate page event issue identified in audit.

  • Remove outdated Segment plugin
  • Remove previous Segment script for tracking OpenRPC parser and Faucet events (not being monitored)
  • Add custom Segment plugin with analytics set up for preview and production deployments

This was tested via the preview deployment, and fires a single page view event per page as expected.

Preview

https://metamask-docs-git-sdk-react-fixes-consensys-ddffed67.vercel.app/

To test:

  1. Visit the preview link – make sure you have enabled analytics cookies on the MM site.
  2. Navigate to the browser developer tools -> network tab.
  3. Filter for "segment" events.
  4. Navigate around the website using different links – top nav, sidebar, internal links. Each page should generate one "p" event (page view event). When you look at the payload of each "p" event, the path should match the path of the visited page.

Checklist

Complete this checklist before merging your PR:

  • If this PR contains a major change to the documentation content, I have added an entry to the top of the "What's new?" page.
  • The proposed changes have been reviewed and approved by a member of the documentation team.

Copilot AI review requested due to automatic review settings June 25, 2025 22:30
@alexandratran alexandratran requested review from a team as code owners June 25, 2025 22:30
@vercel

vercel Bot commented Jun 25, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
metamask-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 25, 2025 10:30pm

Copilot AI 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.

Pull Request Overview

This PR replaces the legacy Segment setup with a custom Docusaurus plugin that conditionally loads the Segment script client-side and emits a single page view per route change.

  • Introduce src/plugins/segment plugin to initialize and hook Segment analytics
  • Drop all old @site/src/lib/segmentAnalytics code and remove manual track* calls throughout components
  • Wire up SEGMENT_ANALYTICS_KEY in docusaurus.config.js and remove the external plugin dependency

Reviewed Changes

Copilot reviewed 16 out of 17 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/plugins/segment/segment.ts Client-side snippet to lazy-load Segment and track pages
src/plugins/segment/index.ts Docusaurus plugin entry registering the client module
src/plugins/segment/package.json Metadata for the plugin (likely unused in this setup)
docusaurus.config.js Added SEGMENT_ANALYTICS_KEY to customFields and switched plugins
src/lib/segmentAnalytics.js & imports Removed old analytics helper and all its imports from code
package.json Removed the separate docusaurus-plugin-segment dependency
Comments suppressed due to low confidence (2)

src/plugins/segment/segment.ts:71

  • [nitpick] We should document why we pin to version 4.15.3 (e.g., matching our CDN or API compatibility) or make it configurable via customFields.
        analytics.SNIPPET_VERSION = "4.15.3";

src/plugins/segment/package.json:1

  • [nitpick] This package.json in the plugin folder isn’t referenced by the build and may cause confusion. Consider removing it or documenting its purpose.
{

Comment thread src/plugins/segment/index.ts

@bgravenorst bgravenorst 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.

lgtm.

@alexandratran alexandratran merged commit 5bf5207 into main Jun 25, 2025
18 checks passed
@alexandratran alexandratran deleted the sdk-react-fixes branch June 25, 2025 23:52
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.

3 participants