Skip to content

Commit

Permalink
fix: skip deep link event when url is missing (#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
liuyang1520 authored Oct 16, 2023
1 parent 90ef21c commit b8a4a87
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
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())
}
}

0 comments on commit b8a4a87

Please sign in to comment.