From d0de4c496d303ab155e3eeb9654cfc5d75337d63 Mon Sep 17 00:00:00 2001 From: Alexander Sapountzis Date: Mon, 16 Feb 2026 15:39:37 -0500 Subject: [PATCH 1/4] docs: Add AGENTS.md --- AGENTS.md | 572 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 572 insertions(+) create mode 100644 AGENTS.md diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 000000000..20f6b78a1 --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,572 @@ +# mParticle Web SDK - Agent Instructions + +This file provides guidance for AI coding agents working with the mParticle Web SDK codebase. + +--- + + + + + + +## About mParticle SDKs + +mParticle is a Customer Data Platform that collects, validates, and forwards event data to analytics and marketing integrations. The SDK is responsible for: + +- **Event Collection**: Capturing user interactions, commerce events, and custom events +- **Identity Management**: Managing user identity across sessions and platforms +- **Event Forwarding**: Routing events to configured integrations (kits/forwarders) +- **Data Validation**: Enforcing data quality through data plans +- **Consent Management**: Handling user consent preferences (GDPR, CCPA) +- **Session Management**: Tracking user sessions and engagement +- **Batch Upload**: Efficiently uploading events to mParticle servers + +### Glossary of Terms + +- **MPID (mParticle ID)**: Unique identifier for a user across sessions and devices +- **Kit/Forwarder**: Third-party integration (e.g., Google Analytics, Braze) that receives events from the SDK +- **Data Plan**: Validation schema that defines expected events and their attributes +- **Workspace**: A customer's mParticle environment (identified by API key) +- **Batch**: Collection of events grouped together for efficient server upload +- **Identity Request**: API call to identify, login, logout, or modify a user's identity +- **Session**: Period of user activity with automatic timeout (typically 30 minutes) +- **Consent State**: User's privacy preferences (GDPR, CCPA) that control data collection and forwarding +- **User Attributes**: Key-value pairs describing user properties (e.g., email, age, preferences) +- **Custom Events**: Application-specific events defined by the developer +- **Commerce Events**: Predefined events for e-commerce tracking (purchases, product views, etc.) +- **Event Type**: Category of event (Navigation, Location, Transaction, UserContent, UserPreference, Social, Other) + +## General Development Guidelines + +### Before Making Changes + +1. **Read First, Modify Later**: Always read relevant files before proposing changes. Use the Read tool to understand existing code, patterns, and conventions. +2. **Understand the Architecture**: Review the instance-based architecture and module structure before adding features. Check `ARCHITECTURE.md` if available for architectural diagrams and design patterns. +3. **Review Contributing Guidelines**: Check `CONTRIBUTING.md` for repository-specific contribution guidelines, workflow, and standards. +4. **Check Existing Tests**: Look at test files for usage examples and to understand expected behavior. +5. **Review Constants**: Check the constants file(s) for standard values, messages, and configuration options. + +### Code Quality Standards + +- **Security First**: Prevent injection vulnerabilities (XSS, command injection, etc.) +- **Avoid Over-Engineering**: Only make changes that are directly requested or clearly necessary +- **No Premature Abstractions**: Don't create helpers or utilities for one-time operations +- **Keep It Simple**: Three similar lines of code is better than a premature abstraction +- **No Unnecessary Features**: Don't add error handling for scenarios that can't happen +- **Trust Internal Code**: Only validate at system boundaries (user input, external APIs) + +### Testing Requirements + +- Run the full test suite before committing +- Add tests for new features or bug fixes +- Test both success and error cases +- Use existing test patterns as examples +- Ensure tests pass in all supported environments + +### Git Commit Standards + +This repository uses **Conventional Commits** for semantic versioning: + +``` +[optional scope]: + +[optional body] + +[optional footer] +``` + +**Commit Types:** +- `feat` → Triggers minor version bump (new feature) +- `fix` → Triggers patch version bump (bug fix) +- `docs` → Documentation changes +- `test` → Adding or updating tests +- `refactor` → Code refactoring without behavior changes +- `perf` → Performance improvements +- `style` → Code style changes (formatting, etc.) +- `chore` → Maintenance tasks +- `ci` → CI/CD changes +- `build` → Build system changes +- `revert` → Reverting previous commits + +**Breaking Changes:** +``` +feat: new API for identity management + +BREAKING CHANGE: Identity.login() now requires a callback parameter +``` + +**Examples:** +``` +feat: add consent state filtering for forwarders +fix: prevent duplicate events in batch upload +docs: update API reference for eCommerce methods +test: add cross-browser tests for identity API +``` + +### Pull Request Guidelines + +- Create PRs against the `master` branch +- Ensure all CI checks pass +- Include test coverage for changes +- Reference any related issues +- Follow the commit message format throughout the branch + +## Common API Patterns + +### Core Modules + +All SDKs should provide these core modules: + +1. **Identity**: User identification, login, logout, modify +2. **Events**: Event logging with custom attributes +3. **eCommerce**: Commerce event tracking (purchases, product views, etc.) +4. **Consent**: User consent state management +5. **Session**: Session lifecycle management +6. **Configuration**: SDK configuration and feature flags + +### Data Flow Architecture + +``` +Event Logged → Validation → Consent Check → Kit Forwarding → Batch Upload + ↓ ↓ ↓ ↓ + Data Plan Consent State Active Kits API Client +``` + +### Configuration Cascade + +``` +Initial Config (provided by developer) + ↓ +SDK Config (normalized and validated) + ↓ +Server Config (merged from mParticle servers) + ↓ +Feature Flags & Kit Configs (runtime) +``` + +--- + + + + + +## Web SDK Architecture + +### Tech Stack + +- **Languages**: TypeScript and JavaScript +- **Build Tool**: Rollup with multiple output formats: + - IIFE (Immediately Invoked Function Expression) for browser `