Loading...
Home
  • Tech Blogs
  • Videos
  • Conferences
    • Droidcon News
    • Upcoming Conferences
    • Become a Partner
    • Past Events
    • Keep Me Informed
    • Diversity Scholarships
  • Community
    • droidcon Team
    • How to Hold a Droidcon
  • Android Careers
Sign In

Global CSS

 

Android Kotlin Analytics Made Simple!

 

 
William Gouvea
Published: January 25, 2021
Tweet
Share
 

 

Goals

  • Add & remove analytics services quickly
  • Add & remove events quickly
  • Able to integrate quickly into any project

 

Analytics Market

Increasingly, organizations have stringent requirements from the time data is generated, to the time actionable insights are delivered to the users. Therefore, data needs to be collected, stored, processed, and analyzed within relatively short windows — ranging from daily to real-time.

Do you know who your users are? What motivates them to buy? What will make them uninstall your app? Growing your audience requires having the tools and process to answer these questions.

 

Top 5 data trends that shaped mobile app marketing in 2020

Shani Rosenfelder 'The coronavirus pandemic' is the first set of words in AppsFlyer's 4th annual top 5 trends of the…

www.appsflyer.com

 

onurakpolat/awesome-analytics

A curated list of awesome analytics platforms, resources and other awesomeness. Inspired by awesome-bigdata. Your…

github.com

 

First, we can define Analytics.kt interface which has only one method, a track that receives EventBuilder.()-> but what it means?

 

 

Note that the class AnalyticsImpl doesn’t need to receive Android context, only a list of Tracker objects.

 

Simple Tracker interface

 

How to init your analytics inside Android Application class

 

There are a couple of ways to make Analytics a singleton, and it’ll rely on how big is your project and the DI mechanism.

 

DI With Koin

 

 

 

DI Using Singleton Pattern

 

Kotlin singletons with argument

object has its limits

bladecoder.medium.com

 

How to create a singleton class in Kotlin?

In Android App, for an object which is required to be created only once and use everywhere, we use the Singleton…

blog.mindorks.com

 

Is noteworthy that we can use the same strategy of hiding the implementation behind an interface (Facade) and compose different behaviors like:

  • HTTP Dispatcher with OkHttp or Retrofit or Ktor
  • Crash Report with Crashlytics or BugSnag or AppCenter)

 

 

Simple CrashReporter interface which implements Tracker as well

 

  • Logging(Firebase,New Relic, ELK, Snowplow)

 

Remote logging with Timber and Firebase Realtime Database.

Building Timber tree for tracking logs remotely & realtime.

developer.android.com

 

 

AndroidLogTracker which does logging to Logcat console using Android Log

 

Generic Unique Api Key

Note the use of UUID.randomUUID() , I’ve shared a couple of ideas regarding that subject here , please checkout and give your feedback

 

Sealed Classes and Hierarchies

Events as simple data classes and sealed class hierarchy is a good fit once the same approach drives MVVM in regular Android apps

 

Trackable interface, Event sealed class with EventTrack/CrashTrack children and EventName using StringDef constants

 

Lambda With Receivers / Builders Kotlin / Apply/ Extensions

 

Builder class using @DslAnnotation and a couple of syntax sugars

 

Sample usage inside your project

 

Conclusion

The complete solution is pretty much a couple of tiny files, that you can check out here.

After adding a few simple Kotlin files, when you need to remove or add “yet another manager tracking tool” you just need to add the dependency to build.gradle file and create a class that implements Tracker and implements it accordingly to the tracker documentation.

 

Like the library? see my profile and give me a clap on medium and a star on GitHub. :)

https://www.linkedin.com/in/williamgouvea/

Last but not least, Comments/Suggestions are welcome as always. Keep learning and keep sharing.

References

  • https://github.com/sofakingforever/solid-kotlin-analytics
  • https://github.com/amsterdatech/snitch
  • https://proandroiddev.com/basic-android-app-analytics-in-60min-cdd1ac04356b
  • https://medium.com/@Actine/organize-your-analytics-code-be9e5ff91543
  • https://medium.com/wantedly-engineering/better-analytics-in-android-with-annotation-processing-and-kotlinpoet-bffca3f24c37
  • https://medium.com/@nadavfima/how-to-build-better-analytics-with-kotlin-60ab50ce25ac
  • https://proandroiddev.com/anatomy-of-analytics-from-google-e107fff107ab
  • https://movile.blog/automatizando-a-geracao-de-eventos-de-analytics/

 

 

 

Tags: Android, Analytics, Architecture, AndroidDev, Android App Development

 

View original article at: 


 

Originally published: January 09, 2021

Android News
Our Engineering Roadmap
Our Engineering Roadmap

By Mark Ng

We just completed our engineering road map for our Android apps at Australia Post. Each year we get together and try to decide on what we are going to do from an engineering perspective for the next 12 months. Each team gets to decide on what should be done now, what they want to complete by the end of the year and whats on the horizon for next year.

By ProAndroidDev -
Android News
Android Activity Lifecycle considered harmful
Android Activity Lifecycle considered harmful

By Eric Silverberg

The Android activity lifecycle is one of the first architectural concepts learned by a new Android developer. Ask any Android dev and they’ll likely all have seen this handy diagram from Google: 

By ProAndroidDev -
Android News
Our Safe Approach to Android Jetpack Navigation in a Multi-Modular App
Our Safe Approach to Android Jetpack Navigation in a Multi-Modular App

By Alejandro Weichandt

It has been a year since we started working on the Android version of the mobile app at Sync. During that year, we faced more than once that moment when we had to choose which path to follow on an Architectural decision. This story is about Navigation.

By ProAndroidDev -
Android News
Custom KotlinX Serializers
Custom KotlinX Serializers

By Jobin Lawrance

Let’s say we have a third-party class that we are using as a type in one of our data class that we want to be serialized, then we have to write a custom serializable for @Serializable to work.

 

By ProAndroidDev -
droidcon News

Tech Showcases,

Developer Resources &

Partners

/portal/rest/jcr/repository/collaboration/Groups/spaces/droidcon_hq/Documents/public/home-details/EmployerBrandingHeader
EmployerBrandingHeader
https://jobs.droidcon.com/
/portal/rest/jcr/repository/collaboration/Groups/spaces/droidcon_hq/Documents/public/employerbranding/jobs-droidcon/jobs.droidcon.com
jobs.droidcon.com

Latest Android Jobs

http://www.kotlinweekly.net/
/portal/rest/jcr/repository/collaboration/Groups/spaces/droidcon_hq/Documents/public/employerbranding/kotlin-weekly/Kotlin Weekly
Kotlin Weekly

Your weekly dose of Kotlin

https://proandroiddev.com/
/portal/rest/jcr/repository/collaboration/Groups/spaces/droidcon_hq/Documents/public/employerbranding/pad/ProAndroidDev
ProAndroidDev

Android Tech Blogs, Case Studies and Step-by-Step Coding

/detail?content-id=/repository/collaboration/Groups/spaces/droidcon_hq/Documents/public/employerbranding/Zalando/Zalando
/portal/rest/jcr/repository/collaboration/Groups/spaces/droidcon_hq/Documents/public/employerbranding/Zalando/Zalando
Zalando

Meet one of Berlin's top employers

/detail?content-id=/repository/collaboration/Groups/spaces/droidcon_hq/Documents/public/employerbranding/Academy for App Success/Academy for App Success
/portal/rest/jcr/repository/collaboration/Groups/spaces/droidcon_hq/Documents/public/employerbranding/Academy for App Success/Academy for App Success
Academy for App Success

Google Play resources tailored for the global droidcon community

Follow us

Team droidcon

Get in touch with us

Write us an Email

 

 

Quicklinks

> Code of Conduct

> Terms and Conditions

> How to hold a conference

> FAQs

> Imprint

Droidcon is a registered trademark of Mobile Seasons GmbH Copyright © 2020. All rights reserved.

powered by Breakpoint One