A modular approach for integrating an analytics platform (like Mixpanel) into your iOS app - Mixpanel

mixpanel.com
6 min read
standard
Mixpanel is the gold standard for iOS app analytics. And the best way to see how is to try it in your app. Now, I know what you're thinking. Integrating new frameworks can be work, not to mention risky for introducing bugs (especially if you're already invested in some other analytics tool like Google Analytics).
Mixpanel is the gold standard for iOS app analytics. And the best way to see how is to try it in your app.

Now, I know what you're thinking. Integrating new frameworks can be work, not to mention risky for introducing bugs (especially if you're already invested in some other analytics tool like Google Analytics).

The good news is, through the power of modular integrations in Swift, it's not difficult to optimize your app's architecture to virtually eliminate the disruptions that can come with this kind of experimentation. And that makes it possible to get into all the benefits of a sophisticated platform like Mixpanel with little technical risk—even if for only a trial run and/or to use it alongside other tools like GA.

Here's how you (or your app developer team) can do it.

As a matter of principle, abstract-away your dependencies

Whether you're talking about analytics platforms or persistence frameworks, it's generally a good idea to keep the tentacles of third-party dependencies out of your core product code.

But this is especially true when it comes to tracking user events for analytics purposes. If you're not careful, your view controllers (and SwiftUI views) will be littered with calls to code you have no direct control over. And if you ever have to remove that code, or swap it with some other dependency, you've got yourself a risk-introducing extravaganza!

But what if it was easy to swap analytics platforms or use multiple at the same time—without so much as touching any of the code that drives your features?

Use services to hide analytics frameworks

A service layer is a way of defining app-specific interfaces for logically related chunks of functionality that are often dependent on external APIs or third-party frameworks.

For example, "analytics" is a chunk of functionality relevant to all apps interested in growth, so it makes sense that we encapsulate our analytics-related functionality in a service called AnalyticsService .

/// A service that…
Read full article