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

General enums in Ampli #383

Closed
kataRebuy opened this issue Jul 28, 2023 · 1 comment
Closed

General enums in Ampli #383

kataRebuy opened this issue Jul 28, 2023 · 1 comment
Assignees

Comments

@kataRebuy
Copy link

Summary

Currently, in Amplitude Data, every event has a separate enum class when generating the Ampli.kt file, even though it is configured as the same event property on amplitude.

Motivations

For example, using the same ScreenName enum for all the events so if I track something from a screen I wouldn't have to use 10 different enums for 10 separate events.

@justin-fiedler justin-fiedler self-assigned this Jul 28, 2023
@justin-fiedler
Copy link
Contributor

Hi @kataRebuy thanks for choosing Amplitude and using Ampli!

Unfortunately creating shared enums is not as straight forward as it seems. It is possible for multiple events to have Properties with the same names but different values. We decided to avoid conflicts by nesting each Enum in it's parent Event. The hope was that it is easy to know what value you need for a given Event by using it's nested enums, even if it is verbose.

We could likely consolidate by checking for shared schema's and creating shared Enums for those. However I can imagine that leading to other issues such as having to support both shared and nested enums. I think this could make it confusing to know which Enum is needed for each Event.

Would love to hear your feedback.

Thanks!

class EventWithEnumTypes private constructor(
    eventProperties: Map<String, Any?>?,
    options: EventOptions? = null
) : Event<EventWithEnumTypes>("Event With Enum Types", eventProperties, options, ::EventWithEnumTypes) {
    constructor(requiredEnum: RequiredEnum) : this(mapOf(
        "required enum" to requiredEnum.value
    ), null as EventOptions?)

    enum class RequiredEnum(val value: String) {
        REQUIRED_ENUM_1("required enum 1"),
        REQUIRED_ENUM_2("required enum 2")
    }
}

class Event2WithEnumTypes private constructor(
    eventProperties: Map<String, Any?>?,
    options: EventOptions? = null
) : Event<Event2WithEnumTypes>("Event2 With Enum Types", eventProperties, options, ::Event2WithEnumTypes) {
    constructor(requiredEnum: RequiredEnum) : this(mapOf(
        "required enum" to requiredEnum.value
    ), null as EventOptions?)

    enum class RequiredEnum(val value: String) {
        ENUM_1("enum 1"),
        ENUM_2("enum 2")
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants