Skip to content

trackScreenViewedEvent would return the application label for most situation #145

@zhchen-wish

Description

@zhchen-wish

Summary

fun trackScreenViewedEvent(activity: Activity) {
        try {
            val packageManager = activity.packageManager
            val info = packageManager?.getActivityInfo(
                activity.componentName,
                PackageManager.GET_META_DATA,
            )
            /* Get the label metadata in following order
              1. activity label
              2. if 1 is missing, fallback to parent application label
              3. if 2 is missing, use the activity name
             */
            val activityLabel = info?.loadLabel(packageManager)?.toString() ?: info?.name
            amplitude.track(EventTypes.SCREEN_VIEWED, mapOf(EventProperties.SCREEN_NAME to activityLabel))
        } catch (e: PackageManager.NameNotFoundException) {
            amplitude.logger.error("Failed to get activity info: $e")
        } catch (e: Exception) {
            amplitude.logger.error("Failed to track screen viewed event: $e")
        }
    }

Most of our activity has not set a label and our application has a label.
Then it would fallback to parent application label, and never goes to #3 to return a activity name.
Which means all the [Amplitude] Screen Viewed event can not tell the difference of which screen the user is viewing.

Do we have a plan to use the activity name as fallback when there is no activity label?
We can use the info?labelRes == 0 to find whether #1 is matched, instead of info?.loadLabel

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions