iOS Data Tracking with CoreData
Article Summary
Emre Havan from Freeletics ditched third-party analytics SDKs and built a custom tracking system using CoreData. The result? Full control over batching, performance, and data flow without external dependencies.
Most iOS apps rely on Firebase or Mixpanel for event tracking, but Freeletics took a different path. This deep dive walks through their production implementation of a custom tracking infrastructure using CoreData, complete with storage, batching, and network layers that handle offline scenarios and thread safety.
Key Takeaways
- Three-layer architecture: storage (CoreData), batcher (coordination), and sender (network)
- Background context with performAndWait ensures thread-safe database operations across queues
- Batch size threshold (20 events) balances real-time tracking with network efficiency
- Protected data checks prevent crashes when device is locked or encrypted
- Custom queue detection avoids main thread violations when checking UIApplication state
Critical Insight
Building custom analytics with CoreData gives you complete control over batching logic, offline persistence, and performance without third-party SDK overhead.