Created
February 24, 2025 16:26
-
-
Save kimji1/2e3b464a7e4222feedbbe6007f13d6b3 to your computer and use it in GitHub Desktop.
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
@JvmName("trackForEventType") | |
fun track( | |
eventType: AnalyticsEventType, | |
properties: Map<String, String>? = null | |
) { | |
eventType.loggerTypes.forEach { logger -> | |
when (logger) { | |
AnalyticsLoggerType.Amplitude -> AmplitudeManager.track(eventType, properties) | |
AnalyticsLoggerType.Airbridge -> AirbridgeManager.track(eventType, properties) | |
} | |
} | |
} | |
@JvmName("trackForPlainText") | |
fun track( | |
actionType: String, | |
eventName: String, | |
properties: Map<String, String>?, | |
analyticsLoggerTypes: List<AnalyticsLoggerType> | |
) { | |
val propertyMap = buildMap { | |
put(ACTION, actionType) | |
properties?.let { putAll(it) } | |
} | |
analyticsLoggerTypes.forEach { logger -> | |
when (logger) { | |
AnalyticsLoggerType.Amplitude -> AmplitudeManager.track(eventName, propertyMap) | |
AnalyticsLoggerType.Airbridge -> AirbridgeManager.track(eventName, propertyMap) | |
} | |
} | |
} | |
@Composable | |
fun TrackPageView( | |
eventType: AnalyticsEventType, | |
properties: Map<String, String>? = null | |
) { | |
LaunchedEffect(Unit) { | |
track(eventType, properties) | |
} | |
} | |
@JvmName("trackWithReceiver") | |
fun AnalyticsEventType.track( | |
properties: Map<String, String>? = null, | |
) { | |
track(eventType = this, properties = properties) | |
} |
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
enum class AnalyticsEventType( | |
val actionType: ActionType? = null, | |
val loggerTypes: List<AnalyticsLoggerType> = LoggerTypes.all | |
) { | |
// events ... | |
private object LoggerTypes { | |
val all = AnalyticsLoggerType.entries.toList() | |
val amplitude = listOf(Amplitude) | |
} | |
} |
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
enum class AnalyticsLoggerType { | |
Amplitude, | |
Airbridge, | |
// add others | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment