React-tracking is a declarative tracking library developed by The New York Times that enables React applications to implement analytics and event logging in a component-centric manner. The library provides multiple integration patterns to accommodate different development styles and React versions, including higher-order components, decorators, and React Hooks, making it flexible for both class-based and functional component architectures.
The core functionality allows developers to compartmentalize tracking concerns within individual components rather than spreading tracking logic across an entire application. This architectural approach prevents tracking concerns from leaking into unrelated parts of the codebase and maintains cleaner separation of concerns. The library supports both declarative and imperative APIs, giving developers expressive options for how they implement tracking in their applications. Importantly, react-tracking is analytics platform agnostic, meaning it can work with any backend analytics service by allowing developers to customize the dispatch behavior through configuration options.
The library provides the @track() decorator for class components and methods, the track() higher-order component wrapper for functional components, and the useTracking() hook for modern React applications. Each approach exposes a tracking prop or hook return value containing methods like trackEvent() and getTrackingData(). When using hooks, developers also receive a Track component that wraps returned markup to pass contextual data to child components. The tracking data can be specified as either static objects or functions that compute data based on runtime values, supporting advanced scenarios where tracking information depends on component state or props.
Configuration options allow fine-grained control over tracking behavior. The dispatch option lets developers override the default behavior of pushing data to window.dataLayer, which is optimized for Google Tag Manager but can be customized for other analytics platforms or environments like React Native where the window object is unavailable. The dispatchOnMount option enables automatic tracking when components mount, useful for page-level tracking events, and can be either a boolean or a function that processes context data before dispatch. The process option provides top-level filtering logic to selectively dispatch events based on component tracking data, such as automatically dispatching pageview events for components with a page property.
The library handles asynchronous methods transparently, automatically dispatching tracking data after promises resolve or reject. It also supports deepmerge functionality for combining tracking context data across component hierarchies, with customizable merge options available.
According to GitGenius activity tracking, the repository shows relatively slow issue and pull request response latency, with a median response time of approximately 2039 hours and a mean of 1597.5 hours across tracked items. The most active contributors identified include alexdelgado and vishnu-sreenivasan, each with two recorded events, and HafizMuhammad-Saad with one event. The repository shares contributor overlap with mui/material-ui, indicating some cross-pollination between these projects. The library is classified across multiple domains including web analytics, user behavior tracking, data collection, event logging, performance monitoring, and frontend development tools, reflecting its broad applicability to React-based analytics implementations.