Skip to content

Conversation

abretonc7s
Copy link
Collaborator

@abretonc7s abretonc7s commented Apr 15, 2025

Description

Overview

This PR introduces a new dedicated package @metamask/analytics-client to encapsulate analytics functionality that was previously scattered across multiple packages. It also refactors related types into a new @metamask/sdk-types package to promote consistency and code reuse.

Depends on #1259

Key Changes

  • Created new @metamask/analytics-client package that centralizes analytics handling logic
  • Introduced new @metamask/sdk-types package with shared types like OriginatorInfo and TrackingEvents
  • Migrated analytics functions from sdk-communication-layer to the dedicated package
  • Updated imports across the codebase to use the new packages
  • Improved test coverage with proper cleanup of mocked globals
  • Enhanced Jest configuration with module name mappings for better test integration
  • Updated build configurations and dependencies to support new package structure

Implementation Details

  • Types Consolidation: Moved shared types (TrackingEvents, OriginatorInfo) to a dedicated types package
  • Code Reuse: Eliminated duplicate analytics handling logic across packages
  • Modern TypeScript Patterns: Using type exports rather than interfaces for better compatibility
  • Better Testing: Added proper cleanup of global mocks in tests to prevent interference between test cases
  • Dependency Management: Updated project configs to reflect the new dependencies between packages

Breaking Changes

This refactoring introduces some breaking changes for internal package consumers:

  • Applications importing analytics functions directly from sdk-communication-layer will need to update imports to use @metamask/analytics-client
  • Types like TrackingEvents and OriginatorInfo should now be imported from @metamask/sdk-types

Migration Guide

  1. Replace imports of SendAnalytics and AnalyticsProps from @metamask/sdk-communication-layer with imports from @metamask/analytics-client
  2. Replace imports of TrackingEvents and OriginatorInfo from @metamask/sdk-communication-layer with imports from @metamask/sdk-types
  3. If your code used commLayer in analytics events, this field has been removed as it's now handled internally

Testing Completed

  • Verified the new analytics client works correctly with existing code
  • Ensured Jest tests pass with the updated module structure
  • Tested package building and resolved circular dependencies
  • Validated proper type exports and imports across packages

Review Checklist

  • Verify analytics events are still being sent correctly
  • Check for any missed imports that need updating
  • Ensure all tests pass in CI
  • Validate building of all affected packages
  • Update documentation to reflect new package structure

@abretonc7s abretonc7s force-pushed the ab/analytics-client branch from f99c6f0 to 29f6f9c Compare April 15, 2025 12:59
@abretonc7s abretonc7s changed the title Ab/analytics client feat(analytics): introduce modular architecture for analytics with dedicated client and server packages Apr 15, 2025
@abretonc7s abretonc7s force-pushed the ab/analytics-client branch from 390e52b to 5ecfb0b Compare April 15, 2025 13:06
@abretonc7s abretonc7s marked this pull request as ready for review April 15, 2025 13:07
@abretonc7s abretonc7s requested a review from a team as a code owner April 15, 2025 13:07
@abretonc7s abretonc7s changed the title feat(analytics): introduce modular architecture for analytics with dedicated client and server packages feat(analytics): introduce @metamask/analytics-client package and consolidate tracking types Apr 15, 2025
@abretonc7s abretonc7s force-pushed the ab/analytics-client branch 2 times, most recently from 21a849c to 73e7ef5 Compare April 16, 2025 03:30
@ecp4224 ecp4224 mentioned this pull request Apr 17, 2025
3 tasks
Copy link

codecov bot commented Apr 18, 2025

Codecov Report

Attention: Patch coverage is 80.30303% with 13 lines in your changes missing coverage. Please review.

Project coverage is 74.00%. Comparing base (768e716) to head (10f23b7).

Files with missing lines Patch % Lines
...tion/EventListeners/handleClientsConnectedEvent.ts 50.00% 4 Missing ⚠️
...rvice/ConnectionManager/handleJoinChannelResult.ts 40.00% 3 Missing ⚠️
...emoteCommunication/ConnectionManager/disconnect.ts 66.66% 1 Missing ⚠️
...teCommunication/ConnectionManager/rejectChannel.ts 66.66% 1 Missing ⚠️
...ketService/EventListeners/handleChannelRejected.ts 66.66% 1 Missing ⚠️
...ices/SocketService/EventListeners/handleMessage.ts 66.66% 1 Missing ⚠️
...SocketService/MessageHandlers/handleSendMessage.ts 66.66% 1 Missing ⚠️
...s/MetaMaskSDK/InitializerManager/setupAnalytics.ts 87.50% 1 Missing ⚠️
Additional details and impacted files
@@                   Coverage Diff                   @@
##           redis-consolidation    #1263      +/-   ##
=======================================================
+ Coverage                73.73%   74.00%   +0.27%     
=======================================================
  Files                      182      181       -1     
  Lines                     4355     4301      -54     
  Branches                  1067     1061       -6     
=======================================================
- Hits                      3211     3183      -28     
+ Misses                    1144     1118      -26     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

…lytics handling

- Created a new package `@metamask/analytics-client` to encapsulate analytics functionality.
- Added TypeScript types for analytics events and originator information in `@metamask/sdk-types`.
- Updated various SDK packages to utilize the new analytics client, enhancing modularity and maintainability.
- Refactored existing analytics code to leverage the new package, ensuring consistent event tracking across the SDK.
- Updated package dependencies and configurations to support the new structure.
- Updated Jest configuration to include module name mappings for analytics and SDK types.
- Refactored test files to utilize the new `@metamask/analytics-client` package for analytics handling.
- Improved global mock setup for `navigator` and `window` properties in tests to ensure proper environment simulation.
- Added cleanup logic in tests to restore original global properties after each test execution.
- Enhanced test cases for `PlatformManager` and `isOldIOS` to ensure accurate platform detection and behavior.
- Disabled analytics in the SDK configuration for development.
- Added 'build' and 'wwww' to the ESLint ignore patterns for better project structure.
- Updated .gitignore to include 'wwww' for cleaner build management.
- Added a new README.md file in the sdk-types package for documentation.
@abretonc7s abretonc7s force-pushed the ab/analytics-client branch from 035fd99 to 4d800d3 Compare April 21, 2025 09:40
Copy link

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.

2 participants