Created
April 13, 2019 19:24
-
-
Save renanboni/d8b676fe9231f02b38923b3769729d87 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FirebaseTracker @Inject constructor( | |
private val context: Context, | |
private val eventsStreamProvider: EventsStreamProvider, | |
private val mapper: FirebaseMapper | |
) { | |
private val compositeDisposable = CompositeDisposable() | |
init { | |
subscribeToEvents() | |
} | |
private fun subscribeToEvents() { | |
compositeDisposable.add( | |
eventsStreamProvider | |
.eventStream | |
.map{ mapper.mapFrom(it) } | |
.subscribe({ | |
sendEvent(it) | |
}, { | |
logError(it.localizedMessage) | |
}) | |
) | |
} | |
private fun logError(err: String) { | |
// do something here, crashlytics or whatever | |
Log.i("FirebaseTracker::error", err) | |
} | |
private fun sendEvent(e: FirebaseEvent) { | |
FirebaseAnalytics.getInstance(context).logEvent(e.name, e.params) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment