Skip to content

Tech Documentation

Internal technical documentation for the OneTrack engineering team. This section covers architecture, implementation details, and design decisions.

Architecture Overview

OneTrack is a comprehensive frontend tracking library with a modular architecture:

lib/
├── scriptLoading/       # Initialization & caching
├── eventDataGeneration/ # 50+ platform integrations
├── tracking/            # Click, form, input tracking
├── ruleEngine/          # Configurable event processing
├── thirdPartyConnections/ # Meta, TikTok, Google, etc.
├── serverConnection/    # Event dispatch & ASL
├── data/                # Storage & validation
└── compliance/          # Consent management

Full Architecture Overview →

Rule Engine

The Rule Engine is a core component enabling runtime behavior modification:

DocumentDescription
ArchitectureDirectory structure & processing pipeline
Core ProcessingRuleEngine class & workspace isolation
TriggersTriggerMatcher & background monitors
ConditionsConditionEvaluator & operators
VariablesVariableResolver & path resolution
Debug SystemPostMessage broadcasting
PerformanceO(1) indexing & optimizations

Key Design Decisions

Workspace Isolation

Events are deep-cloned per workspace to prevent cross-workspace contamination:

typescript
// core/ruleEngine.ts:329
const workspaceEventClone = deepClone(event);

O(1) Trigger Matching

TriggerMatcher uses Map-based indexing for constant-time lookup regardless of rule count:

typescript
// triggers/TriggerMatcher.ts:25-83
private eventTypeIndex: Map<string, Set<Rule>> = new Map();

Infinite Loop Prevention

Recursion depth is tracked and limited to prevent circular rule execution:

typescript
// core/ruleEngine.ts:127-128
private static readonly MAX_RECURSION_DEPTH = 10;

Quick Reference

Entry Points

typescript
import {
  initializeRuleEngine,
  processEventThroughRules,
  enableRuleEngineDebug
} from '@onetrack/ruleEngine';

// Initialize
initializeRuleEngine();

// Process event
const processedEvents = processEventThroughRules(event);

// Enable debug
enableRuleEngineDebug();

Key Files

FilePurposeLines
core/ruleEngine.tsMain processing1349
interface.tsType definitions506
triggers/TriggerMatcher.tsO(1) matching~150
conditions/conditionEvaluator.tsCondition logic~800
variables/variableResolver.tsVariable resolution~300

Development

Build Commands

bash
npm run build          # Production build
npm run build:debug    # Debug build (console.log preserved)
npm run test           # Run tests

Testing

Tests are in lib/ruleEngine/tests/unit/ with 40+ test files covering:

  • Trigger matching
  • Condition evaluation
  • Action execution
  • Variable resolution
  • Background monitors

Contributing

When modifying the Rule Engine:

  1. Read the relevant documentation first
  2. Follow existing patterns
  3. Add tests for new functionality
  4. Update documentation if needed
  5. Run the full test suite before committing