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(android): remove deprecated navigation event #1665

Merged
merged 1 commit into from
Dec 26, 2024
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
3 changes: 0 additions & 3 deletions android/measure/api/measure.api
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ public final class sh/measure/android/Measure {
public final fun trackEvent (Ljava/lang/String;Ljava/util/Map;Ljava/lang/Long;)V
public static synthetic fun trackEvent$default (Lsh/measure/android/Measure;Ljava/lang/String;Ljava/util/Map;Ljava/lang/Long;ILjava/lang/Object;)V
public static final fun trackHandledException (Ljava/lang/Throwable;)V
public static final fun trackNavigation (Ljava/lang/String;)V
public static final fun trackNavigation (Ljava/lang/String;Ljava/lang/String;)V
public static synthetic fun trackNavigation$default (Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)V
public static final fun trackScreenView (Ljava/lang/String;)V
}

Expand Down
37 changes: 0 additions & 37 deletions android/measure/src/main/java/sh/measure/android/Measure.kt
Original file line number Diff line number Diff line change
Expand Up @@ -120,43 +120,6 @@ object Measure {
}
}

/**
* Track a navigation event.
*
* Navigation events are important to understand user journey in the app. Measure SDK
* automatically collects navigation events from
* [Jetpack Navigation library](https://developer.android.com/jetpack/androidx/releases/navigation)
* along with Activity and Fragment lifecycle events. But if your app uses a custom navigation
* system, you can use this method to track navigation events to have more context when
* debugging issues.
*
* For more details on the automatically collected events, check the documentation.
*
* It is recommended to use consistent naming conventions for screen names and namespacing
* them with relevant context to make it easier to understand the user journey on the Measure
* Dashboard.
*
* Example usage:
*
* ```kotlin
* Measure.trackNavigation("Home", "Login")
* ```
*
* @param to The name of the destination screen or location.
* @param from The name of the source screen or location. Null by default.
*/
@JvmStatic
@JvmOverloads
@Deprecated(
message = "This method will be removed in the next version, use trackScreenView instead",
replaceWith = ReplaceWith("Measure.trackScreenView(screenName)"),
)
fun trackNavigation(to: String, from: String? = null) {
if (isInitialized.get()) {
measure.trackNavigation(to, from)
}
}

/**
* Call when a screen is viewed by the user.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,6 @@ internal class MeasureInternal(measureInitializer: MeasureInitializer) : AppLife
userAttributeProcessor.clearUserId()
}

@Deprecated("Use trackScreenView instead")
fun trackNavigation(to: String, from: String?) {
userTriggeredEventCollector.trackNavigation(to, from)
}

fun trackScreenView(screenName: String) {
userTriggeredEventCollector.trackScreenView(screenName)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ internal object EventType {
const val MEMORY_USAGE: String = "memory_usage"
const val TRIM_MEMORY: String = "trim_memory"
const val CPU_USAGE: String = "cpu_usage"

@Deprecated("This event type is deprecated and will be removed in the next version. Use SCREEN_VIEW instead.")
const val NAVIGATION: String = "navigation"
const val SCREEN_VIEW: String = "screen_view"
const val CUSTOM: String = "custom"
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package sh.measure.android.events

import sh.measure.android.exceptions.ExceptionFactory
import sh.measure.android.navigation.NavigationData
import sh.measure.android.navigation.ScreenViewData
import sh.measure.android.utils.ProcessInfoProvider
import sh.measure.android.utils.TimeProvider
import java.util.concurrent.atomic.AtomicBoolean

internal interface UserTriggeredEventCollector {
@Deprecated("Use trackScreenView instead")
fun trackNavigation(to: String, from: String?)
fun trackHandledException(throwable: Throwable)
fun trackScreenView(screenName: String)
fun register()
Expand All @@ -31,22 +28,6 @@ internal class UserTriggeredEventCollectorImpl(
enabled.compareAndSet(true, false)
}

@Deprecated("Use trackScreenView instead")
override fun trackNavigation(to: String, from: String?) {
if (!enabled.get()) {
return
}
signalProcessor.trackUserTriggered(
data = NavigationData(
to = to,
from = from,
source = null,
),
timestamp = timeProvider.now(),
type = EventType.NAVIGATION,
)
}

override fun trackHandledException(throwable: Throwable) {
if (!enabled.get()) {
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import sh.measure.android.gestures.ScrollData
import sh.measure.android.lifecycle.ActivityLifecycleData
import sh.measure.android.lifecycle.ApplicationLifecycleData
import sh.measure.android.lifecycle.FragmentLifecycleData
import sh.measure.android.navigation.NavigationData
import sh.measure.android.navigation.ScreenViewData
import sh.measure.android.networkchange.NetworkChangeData
import sh.measure.android.okhttp.HttpData
Expand Down Expand Up @@ -149,10 +148,6 @@ internal fun <T> Event<T>.serializeDataToString(): String {
json.encodeToString(CpuUsageData.serializer(), data as CpuUsageData)
}

EventType.NAVIGATION -> {
json.encodeToString(NavigationData.serializer(), data as NavigationData)
}

EventType.CUSTOM -> {
json.encodeToString(CustomEventData.serializer(), data as CustomEventData)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,9 +388,9 @@ internal class SignalProcessorTest {

@Test
fun `given a user triggered event, then stores the event`() {
val data = TestData.getNavigationData()
val data = TestData.getScreenViewData()
val timestamp = 1710746412L
val eventType = EventType.NAVIGATION
val eventType = EventType.SCREEN_VIEW
val expectedEvent = data.toEvent(
type = eventType,
timestamp = timestamp.iso8601Timestamp(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import org.mockito.kotlin.verify
import sh.measure.android.exceptions.ExceptionData
import sh.measure.android.fakes.FakeProcessInfoProvider
import sh.measure.android.fakes.TestData
import sh.measure.android.navigation.NavigationData
import sh.measure.android.navigation.ScreenViewData
import sh.measure.android.utils.AndroidTimeProvider
import sh.measure.android.utils.ProcessInfoProvider
import sh.measure.android.utils.TestClock
Expand All @@ -25,18 +25,13 @@ class UserTriggeredEventCollectorImplTest {
)

@Test
fun `tracks navigation event`() {
val from = "from"
val to = "to"
fun `tracks screen view event`() {
val screenName = "screen-name"
userTriggeredEventCollector.register()
userTriggeredEventCollector.trackNavigation(to, from)
userTriggeredEventCollector.trackScreenView(screenName)
verify(signalProcessor).trackUserTriggered(
data = NavigationData(
source = null,
from = from,
to = to,
),
type = EventType.NAVIGATION,
data = ScreenViewData(name = screenName),
type = EventType.SCREEN_VIEW,
timestamp = timeProvider.now(),
)
}
Expand All @@ -58,8 +53,6 @@ class UserTriggeredEventCollectorImplTest {
@Test
fun `disables collection un unregistered`() {
val exception = Exception()
val data = TestData.getExceptionData(handled = true, exception = exception)

userTriggeredEventCollector.unregister()
userTriggeredEventCollector.trackHandledException(exception)
verify(signalProcessor, never()).trackUserTriggered(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import sh.measure.android.lifecycle.ApplicationLifecycleData
import sh.measure.android.lifecycle.FragmentLifecycleData
import sh.measure.android.lifecycle.FragmentLifecycleType
import sh.measure.android.logger.Logger
import sh.measure.android.navigation.NavigationData
import sh.measure.android.navigation.ScreenViewData
import sh.measure.android.networkchange.NetworkChangeData
import sh.measure.android.networkchange.NetworkGeneration
Expand Down Expand Up @@ -281,14 +280,6 @@ internal object TestData {
return TrimMemoryData(level)
}

fun getNavigationData(
source: String? = "source",
to: String = "profile",
from: String = "home",
): NavigationData {
return NavigationData(source = source, from = from, to = to)
}

fun getCpuUsageData(
numCores: Int = 4,
clockSpeed: Long = 10,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,6 @@ class EventExtensionsKtTest {
val cpuUsageEvent = TestData.getCpuUsageData().toEvent(type = EventType.CPU_USAGE)
assert(cpuUsageEvent.serializeDataToString().isNotEmpty())

val navigationEvent = TestData.getNavigationData().toEvent(type = EventType.NAVIGATION)
assert(navigationEvent.serializeDataToString().isNotEmpty())

val screenViewEvent = TestData.getScreenViewData().toEvent(type = EventType.SCREEN_VIEW)
assert(screenViewEvent.serializeDataToString().isNotEmpty())
}
Expand Down
2 changes: 1 addition & 1 deletion docs/android/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* [Getting started](#getting-started)
* [Custom events](#custom-events)
* [Handled exceptions](#handled-exceptions)
* [Navigation](#navigation)
* [Screen view](#screen-view)
* [Features](#features)
* [Performance Impact](#performance-impact)
* [Benchmarks](#benchmarks)
Expand Down
4 changes: 4 additions & 0 deletions docs/api/sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,10 @@ Use the `trim_memory` type for a trim memory event raised by Android.

Use the `navigation` type for navigation events.

> ![IMPORTANT]
> This event is no longer tracked and will be removed in future versions.
> Android SDK removed support for this event from v0.9.0 onwards.

| Field | Type | Optional | Description |
| ------ | ------ | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| source | string | Yes | Adds context on how the event was collected. Null if not set.<br/>Example: `androidx_navigation` if the event was collected from `androidx.navigation` library. |
Expand Down
Loading