Create your own Realtime Analytics App using Firestore in Android

dependencies {
// Import the BoM for the Firebase platform
implementation platform('com.google.firebase:firebase-bom:26.1.0')

// Declare the dependency for the Cloud Firestore library
// When using the BoM, you don't specify versions in Firebase library dependencies
implementation 'com.google.firebase:firebase-firestore-ktx'
}
fun trackEvent(screenName: String, eventName: String) {
Firebase.firestore
.collection("Track")
.document(screenName)
.update(eventName, FieldValue.increment(1))
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

Common.trackEvent("Screens", "MainScreen")
}
Firebase.firestore
.collection("Track").document("Screens")
.addSnapshotListener { snapshot, e ->
if (snapshot != null && snapshot.exists()) {
tvMainScreen.text = snapshot.data!! ["MainScreen"].toString()
} else {
tvMainScreen.text = null
}

}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store