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

trackScreenViewedEvent would return the application label for most situation #145

Open
zhchen-wish opened this issue Aug 24, 2023 · 1 comment
Labels
question Further information is requested

Comments

@zhchen-wish
Copy link

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

@zhchen-wish zhchen-wish added the question Further information is requested label Aug 24, 2023
@liuyang1520
Copy link
Collaborator

Thanks for the feedback! I agree we can probably adjust the order to be activity label > activity name (> application label). @amplitude/dx what do you think?

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

No branches or pull requests

2 participants