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

fix: skip deep link event when url is missing #150

Merged
merged 1 commit into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -91,14 +91,16 @@ class DefaultEventUtils(private val amplitude: Amplitude) {
val intent = activity.intent
intent?.let {
val referrer = getReferrer(activity)?.toString()
val url = it.data?.toString()
amplitude.track(
EventTypes.DEEP_LINK_OPENED,
mapOf(
EventProperties.LINK_URL to url,
EventProperties.LINK_REFERRER to referrer,
),
)
it.data?.let { uri ->
val url = uri.toString()
amplitude.track(
EventTypes.DEEP_LINK_OPENED,
mapOf(
EventProperties.LINK_URL to url,
EventProperties.LINK_REFERRER to referrer,
),
)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -496,4 +496,30 @@ class AndroidLifecyclePluginTest {
verify(exactly = 0) { mockedPlugin.track(capture(tracks)) }
Assertions.assertEquals(0, tracks.count())
}

@Test
fun `test deep link opened event is not tracked when URL is missing`() = runTest {
setDispatcher(testScheduler)
configuration.defaultTracking.deepLinks = true
amplitude.add(androidLifecyclePlugin)

val mockedPlugin = spyk(StubPlugin())
amplitude.add(mockedPlugin)
amplitude.isBuilt.await()

val mockedIntent = mockk<Intent>()
every { mockedIntent.data } returns null
val mockedActivity = mockk<Activity>()
every { mockedActivity.intent } returns mockedIntent
every { mockedActivity.referrer } returns Uri.parse("android-app://com.android.unit-test")
val mockedBundle = mockk<Bundle>()
androidLifecyclePlugin.onActivityCreated(mockedActivity, mockedBundle)

advanceUntilIdle()
Thread.sleep(100)

val tracks = mutableListOf<BaseEvent>()
verify(exactly = 0) { mockedPlugin.track(capture(tracks)) }
Assertions.assertEquals(0, tracks.count())
}
}