Important Update ❤️

The project is now available on GitHub, and on a Maven Repository

Tightly Coupled Code

Baking analytics into Android apps has always been a monstrous process for me, but that’s only because I’ve been approaching it incorrectly. In my latest app, Wakey, I’ve implemented a few analytics events across the different screens and services using Fabric’s Answers SDK. The different SDK functions were scattered across the app’s different screens — which meant this:

If I wanted to remove or replace Fabric’s library, I would have to go through each and every Activity / Fragment / Service, and edit them one-by-one. The same goes for adding an additional analytics service — I would have to go over each event and duplicate it in some way.

I’ve had both CustomEvent calls and ContentView calls scattered across the app’s different screens, which looked something like this:

// Pre-Decoupling Code - inside Android Activity // event trigger

Answers.getInstance().logCustom(CustomEvent("alarm_snoozed")) // content view trigger

Answers.getInstance().logContentView(ContentViewEvent().putContentName("alarm_screen"))

Instead, I was hoping for a loosely-coupled implementation, which would look more like this:

// Desired Code // event trigger

analytics.trackEvent(AlarmActionSnoozeEvent()); // content view trigger

analytics.trackContentView(AlarmActivityContentView())