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

feat: add screen name to elementInteractions properties for autocapture #209

Merged
merged 34 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
37441da
feat: add autocapture options and deprecate default tracking
PouriaAmini Jul 29, 2024
4468d00
feat: track target hierarchy
PouriaAmini Jul 29, 2024
fb901d7
fix: fix lint
PouriaAmini Jul 29, 2024
aadbaea
fix: fix a bug that occurs when default tracking options are set afte…
PouriaAmini Jul 29, 2024
124663d
fix: refactor default tracking deprecation
PouriaAmini Jul 29, 2024
575644a
fix: handle changes to defaultTrackingOptions after being assigned to…
PouriaAmini Jul 29, 2024
8ea95b0
fix: fix lint
PouriaAmini Jul 29, 2024
7250b42
fix: attach autocapture option to defaultTracking to monitor changes …
PouriaAmini Jul 30, 2024
a6f7c0a
fix: remove redundant code
PouriaAmini Jul 30, 2024
cc50336
refactor: refactor code to reduce object creation
PouriaAmini Jul 30, 2024
0978329
feat: set autocapture configs as a mutable set of options
PouriaAmini Jul 30, 2024
b502a60
fix: fix lint
PouriaAmini Jul 30, 2024
1f4caae
refactor: refactor to use simple remove and add instead of augmented …
PouriaAmini Jul 30, 2024
3f597ec
refactor: remove redundant code
PouriaAmini Jul 30, 2024
2bbd76d
feat: add experimental annotation to element interactions option
PouriaAmini Aug 2, 2024
8da3669
fix: fix failing test
PouriaAmini Aug 2, 2024
6ac78b3
fix: fix failing test
PouriaAmini Aug 2, 2024
1438159
fix: fix failing test
PouriaAmini Aug 2, 2024
b4c0998
feat: make autocapture options immutable and discard changes to defau…
PouriaAmini Aug 2, 2024
afad034
fix: fix lint
PouriaAmini Aug 2, 2024
fc3ac6f
test: add test for deprecated parameter.
PouriaAmini Aug 2, 2024
735f6b6
Revert "fix: fix lint"
PouriaAmini Aug 3, 2024
fcbba64
feat: make changes to defaultTracking and trackingSessionEvents effec…
PouriaAmini Aug 4, 2024
a381099
fix: add a secondary constructor for Configuration to deprecate defau…
PouriaAmini Aug 5, 2024
dec1f4c
fix: fix the bug when a new DefaultTrackingOptions is passed to the C…
PouriaAmini Aug 6, 2024
4ea32ce
test: add test for deprecation logic
PouriaAmini Aug 6, 2024
b278f21
test: add test for deprecation logic
PouriaAmini Aug 6, 2024
7d174a9
fix: changes to the default tracking options replace the recent autoc…
PouriaAmini Aug 7, 2024
8551ef0
fix: fix lint
PouriaAmini Aug 7, 2024
dd9a434
feat: add screen name to elementInteractions autocapture properties
PouriaAmini Aug 7, 2024
3f987a6
test: fix test
PouriaAmini Aug 7, 2024
c9b106b
Merge branch 'main' into screen-name
PouriaAmini Aug 7, 2024
9ba5a4e
fix: add exception error message
PouriaAmini Aug 7, 2024
876c3ff
style: fix error message style
PouriaAmini Aug 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import androidx.annotation.VisibleForTesting
import com.amplitude.android.internal.ViewHierarchyScanner.findTarget
import com.amplitude.android.internal.ViewTarget
import com.amplitude.android.internal.locators.ViewTargetLocator
import com.amplitude.android.utilities.DefaultEventUtils.Companion.screenName
import com.amplitude.android.utilities.DefaultEventUtils.EventProperties.ACTION
import com.amplitude.android.utilities.DefaultEventUtils.EventProperties.HIERARCHY
import com.amplitude.android.utilities.DefaultEventUtils.EventProperties.SCREEN_NAME
import com.amplitude.android.utilities.DefaultEventUtils.EventProperties.TARGET_CLASS
import com.amplitude.android.utilities.DefaultEventUtils.EventProperties.TARGET_RESOURCE
import com.amplitude.android.utilities.DefaultEventUtils.EventProperties.TARGET_SOURCE
Expand Down Expand Up @@ -55,6 +57,12 @@ class AutocaptureGestureListener(
.split(" ")
.joinToString(" ") { it.replaceFirstChar { c -> c.uppercase() } },
HIERARCHY to target.hierarchy,
SCREEN_NAME to try {
activityRef.get()?.screenName
} catch (e: Exception) {
logger.error("Error getting screen name: $e")
null
}
).let { track(ELEMENT_INTERACTED, it) }

return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,19 +119,12 @@ class DefaultEventUtils(private val amplitude: Amplitude) {

fun trackScreenViewedEvent(activity: Activity) {
try {
val packageManager = activity.packageManager
val info =
packageManager?.getActivityInfo(
activity.componentName,
PackageManager.GET_META_DATA,
amplitude.track(
EventTypes.SCREEN_VIEWED,
mapOf(
EventProperties.SCREEN_NAME to activity.screenName
)
/* 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) {
Expand Down Expand Up @@ -162,6 +155,25 @@ class DefaultEventUtils(private val amplitude: Amplitude) {
} ?: amplitude.logger.error("Failed to stop user interaction event tracking: Activity window is null")
}

companion object {
internal val Activity.screenName: String?
@Throws(PackageManager.NameNotFoundException::class, Exception::class)
get() {
val packageManager = packageManager
val info =
packageManager?.getActivityInfo(
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
*/
return info?.loadLabel(packageManager)?.toString() ?: info?.name
}
}

private fun getReferrer(activity: Activity): Uri? {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
return activity.referrer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ class AutocaptureGestureListenerClickTest {
"[Amplitude] Target Tag" to null,
"[Amplitude] Target Source" to "Android View",
"[Amplitude] Hierarchy" to "View",
"[Amplitude] Screen Name" to null,
),
)
}
Expand Down