Building a Lightweight Client-Side Analytics Data Collection SDK
Design and implement a browser-side analytics SDK (similar to Google Analytics or Segment) that can be embedded into any webpage. It should: (1) expose a simple API like track(eventName, properties) and identify(userId, traits); (2) batch collected events internally and flush them to a server endpoint either on a timer interval or when the batch size exceeds a threshold; (3) persist unsent events in localStorage so they survive page refreshes; (4) handle network failures with retry logic; (5) support a plugin architecture where custom processors can be added. Focus on the data pipeline design, batching strategy, and fault tolerance.