How snowplow/snowplow-javascript-tracker works
Main Components
• Monorepo Structure managed by Rush – At the highest level, note that this is a monorepo with a “rush.json” file and various common configurations (found in the “common” directory). This organizes multiple packages into a cohesive development and build environment.
• Core Libraries:
– “libraries/browser-tracker-core” and “libraries/tracker-core” represent the fundamental functionalities (such as event creation, payload building, emitting, and state management) shared by the trackers.
• Tracker Packages:
– “trackers/browser-tracker”, “trackers/javascript-tracker”, “trackers/node-tracker”, and “trackers/react-native-tracker” are the project’s different implementations for various platforms.
– These components wrap the core libraries and add platform-specific logic.
• Plugins:
– The “plugins” directory contains many browser plugins (like ad tracking, button click tracking, enhanced-ecommerce, error tracking, etc.). Each plugin module extends the native tracking functionality.
– They integrate with the tracker packages and core libraries to add extra event context or functionality.
• API Documentation:
– The “api-docs” directory contains the documentation system (built likely with Docusaurus); it is instrumental in explaining API usage, but is not part of runtime execution.
• Supporting Scripts and Configuration:
– The “common” directory includes scripts (like auto-installers, git hooks, and build tools), rush configuration files, and version/packaging policies.
– Other configuration files (e.g., .eslintrc.js, .prettierrc, Rollup configurations in many packages) indicate standardized build and style practices.
Relationships and Interactions
• The plugins “hook” into the trackers, meaning that they are dynamically loaded or registered—show these as interfacing between the tracker packages and the core functionality.
• Although not shown as an HTTP layer, add an external “Snowplow Collector/Endpoint” component that receives events; the emitter sends data to this external service.
Architectural Patterns and Design Principles
• Modularity: The design splits functionalities into trackers, shared libraries, and plugins, following separation of concerns. Each package is independent yet interacts via well-defined interfaces.
• Extensibility: The plugins architecture allows additional tracking behaviors to be mixed into the tracker’s data collection workflow.
• Monorepo Management: Use of Rush, a common configuration folder in “common”, and shared dependencies ensures consistency across packages.
• Cross-platform Support: With distinct trackers for browser, Node.js, React Native, etc., emphasize the pattern of platform-specific adaptations built on top of common core services.