Last active
January 18, 2021 21:05
-
-
Save amsterdatech/852f033e73744ba693391fa6e3358639 to your computer and use it in GitHub Desktop.
Analytics interface
This file contains hidden or 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
interface Analytics { | |
fun track(setup: EventBuilder.() -> Unit = {}) | |
} | |
class AnalyticsImpl(private val trackers: MutableList<Tracker>) : Analytics { | |
init { | |
trackers.forEach { | |
if(it.isAnalyticsEnable()){ | |
it.start() | |
} | |
} | |
} | |
override fun track(setup: EventBuilder.() -> Unit) { | |
val eventBuilder = EventBuilder() | |
eventBuilder.setup() | |
val event = eventBuilder.build() | |
event?.let { event -> | |
if (event is EventTrack) { | |
trackers.forEach { tracker: Tracker -> | |
tracker.trackEvent(event) | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment