Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement custom events #1116

Open
abhaysood opened this issue Aug 26, 2024 · 0 comments · May be fixed by #1142
Open

Implement custom events #1116

abhaysood opened this issue Aug 26, 2024 · 0 comments · May be fixed by #1142
Assignees
Labels
android android related

Comments

@abhaysood
Copy link
Contributor

abhaysood commented Aug 26, 2024

Summary

Feature context: #851

Public API

The main consideration for the public API to be exposed for tracking custom events is that the types of attribute values need to be constrained to the following Kotlin types: String, Int, Double, Boolean and Long and the public API should only allow adding these types only.

val attributes = buildAttributes {
  put("sample-key-1", 123)
  put("sample-key-2", 123.45)
  put("sample-key-3", "sample-value")
  put("sample-key-4", true)
  put("sample-key-5", 123L)
}
Measure.trackEvent("custom-event", attributes)

This can be achieved by leveraging inline value classes in Kotlin which can provide type safety and performance benefits without the overhead of creating separate objects for each attribute value. Inline value classes allow us to wrap primitive types with additional type information at compile time, while still using the underlying primitive type at runtime.

For example, to represent an AttributeValue that can only have a string the following sealed interface can be used with the inline value class:

@Serializable(with = AttributeValueSerializer::class)
sealed interface AttributeValue {
    val value: Any
}

@Serializable
@JvmInline
value class StringAttr(override val value: String) : AttributeValue
@abhaysood abhaysood self-assigned this Aug 26, 2024
@abhaysood abhaysood converted this from a draft issue Aug 26, 2024
@abhaysood abhaysood added feature new features android android related labels Aug 26, 2024
@abhaysood abhaysood removed the feature new features label Aug 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
android android related
Projects
Status: In Progress
Development

Successfully merging a pull request may close this issue.

1 participant