2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-03 23:15:31 +00:00

[fenix] Bug 1814231 - revert growth data removal from github https://github.com/mozilla-mobile/fenix/pull/28429

This commit is contained in:
MatthewTighe 2023-01-31 12:22:43 -08:00 committed by mergify[bot]
parent cac4d8b1d8
commit 45598b5408
8 changed files with 120 additions and 0 deletions

View File

@ -36,5 +36,15 @@ sealed class Event {
* Event recording that usage time has reached a threshold.
*/
object UsageThreshold : GrowthData("m66prt")
/**
* Event recording the first time Firefox has been resumed in a 24 hour period.
*/
object FirstAppOpenForDay : GrowthData("41hl22")
/**
* Event recording the first time a URI is loaded in Firefox in a 24 hour period.
*/
object FirstUriLoadForDay : GrowthData("ja86ek")
}
}

View File

@ -27,6 +27,7 @@ class MetricsMiddleware(
private fun handleAction(action: AppAction) = when (action) {
is AppAction.ResumedMetricsAction -> {
metrics.track(Event.GrowthData.SetAsDefault)
metrics.track(Event.GrowthData.FirstAppOpenForDay)
metrics.track(Event.GrowthData.FirstWeekSeriesActivity)
metrics.track(Event.GrowthData.UsageThreshold)
}

View File

@ -81,6 +81,16 @@ internal class DefaultMetricsStorage(
!settings.usageTimeGrowthSent &&
settings.usageTimeGrowthData > usageThresholdMillis
}
Event.GrowthData.FirstAppOpenForDay -> {
currentTime.afterFirstDay() &&
currentTime.duringFirstMonth() &&
settings.resumeGrowthLastSent.hasBeenMoreThanDaySince()
}
Event.GrowthData.FirstUriLoadForDay -> {
currentTime.afterFirstDay() &&
currentTime.duringFirstMonth() &&
settings.uriLoadGrowthLastSent.hasBeenMoreThanDaySince()
}
}
}
@ -98,6 +108,12 @@ internal class DefaultMetricsStorage(
Event.GrowthData.UsageThreshold -> {
settings.usageTimeGrowthSent = true
}
Event.GrowthData.FirstAppOpenForDay -> {
settings.resumeGrowthLastSent = System.currentTimeMillis()
}
Event.GrowthData.FirstUriLoadForDay -> {
settings.uriLoadGrowthLastSent = System.currentTimeMillis()
}
}
}
@ -154,6 +170,10 @@ internal class DefaultMetricsStorage(
calendar.timeInMillis = this
}
private fun Long.hasBeenMoreThanDaySince() = System.currentTimeMillis() - this > dayMillis
private fun Long.afterFirstDay() = this > getInstalledTime() + dayMillis
private fun Long.duringFirstDay() = this < getInstalledTime() + dayMillis
private fun Long.duringFirstWeek() = this < getInstalledTime() + fullWeekMillis

View File

@ -24,6 +24,7 @@ import mozilla.telemetry.glean.private.NoExtras
import org.mozilla.fenix.Config
import org.mozilla.fenix.GleanMetrics.Events
import org.mozilla.fenix.GleanMetrics.Metrics
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.components.metrics.MetricController
import org.mozilla.fenix.utils.Settings
import org.mozilla.fenix.GleanMetrics.EngineTab as EngineMetrics
@ -70,6 +71,9 @@ class TelemetryMiddleware(
}
return
}
is EngineAction.LoadUrlAction -> {
metrics.track(Event.GrowthData.FirstUriLoadForDay)
}
else -> {
// no-op
}

View File

@ -1567,4 +1567,14 @@ class Settings(private val appContext: Context) : PreferencesHolder {
key = appContext.getPreferenceKey(R.string.pref_key_growth_usage_time_sent),
default = false,
)
var resumeGrowthLastSent by longPreference(
key = appContext.getPreferenceKey(R.string.pref_key_growth_resume_last_sent),
default = 0,
)
var uriLoadGrowthLastSent by longPreference(
key = appContext.getPreferenceKey(R.string.pref_key_growth_uri_load_last_sent),
default = 0,
)
}

View File

@ -324,6 +324,8 @@
<string name="pref_key_growth_ad_click_sent" translatable="false">pref_key_growth_ad_click_sent</string>
<string name="pref_key_growth_usage_time" translatable="false">pref_key_growth_usage_time</string>
<string name="pref_key_growth_usage_time_sent" translatable="false">pref_key_growth_usage_time_sent</string>
<string name="pref_key_growth_resume_last_sent" translatable="false">pref_key_growth_last_resumed</string>
<string name="pref_key_growth_uri_load_last_sent" translatable="false">pref_key_growth_uri_load_last_sent</string>
<!-- Notification Pre Permission Prompt -->
<string name="pref_key_notification_pre_permission_prompt_enabled">pref_key_notification_pre_permission_prompt_enabled</string>

View File

@ -318,6 +318,70 @@ class DefaultMetricsStorageTest {
assertTrue(slot.captured < stopTime - startTime)
}
@Test
fun `GIVEN that it has been less than 24 hours since last resumed sent WHEN checked for sending THEN will not be sent`() = runTest(dispatcher) {
val currentTime = System.currentTimeMillis()
every { settings.resumeGrowthLastSent } returns currentTime
val result = storage.shouldTrack(Event.GrowthData.FirstAppOpenForDay)
assertFalse(result)
}
@Test
fun `GIVEN that it has been more than 24 hours since last resumed sent WHEN checked for sending THEN will be sent`() = runTest(dispatcher) {
val currentTime = System.currentTimeMillis()
installTime = currentTime - (dayMillis + 1)
every { settings.resumeGrowthLastSent } returns currentTime - 1000 * 60 * 60 * 24 * 2
val result = storage.shouldTrack(Event.GrowthData.FirstAppOpenForDay)
assertTrue(result)
}
@Test
fun `WHEN last resumed state updated THEN settings updated accordingly`() = runTest(dispatcher) {
val updateSlot = slot<Long>()
every { settings.resumeGrowthLastSent } returns 0
every { settings.resumeGrowthLastSent = capture(updateSlot) } returns Unit
storage.updateSentState(Event.GrowthData.FirstAppOpenForDay)
assertTrue(updateSlot.captured > 0)
}
@Test
fun `GIVEN that it has been less than 24 hours since uri load sent WHEN checked for sending THEN will not be sent`() = runTest(dispatcher) {
val currentTime = System.currentTimeMillis()
every { settings.uriLoadGrowthLastSent } returns currentTime
val result = storage.shouldTrack(Event.GrowthData.FirstUriLoadForDay)
assertFalse(result)
}
@Test
fun `GIVEN that it has been more than 24 hours since uri load sent WHEN checked for sending THEN will be sent`() = runTest(dispatcher) {
val currentTime = System.currentTimeMillis()
installTime = currentTime - (dayMillis + 1)
every { settings.uriLoadGrowthLastSent } returns currentTime - 1000 * 60 * 60 * 24 * 2
val result = storage.shouldTrack(Event.GrowthData.FirstUriLoadForDay)
assertTrue(result)
}
@Test
fun `WHEN uri load updated THEN settings updated accordingly`() = runTest(dispatcher) {
val updateSlot = slot<Long>()
every { settings.uriLoadGrowthLastSent } returns 0
every { settings.uriLoadGrowthLastSent = capture(updateSlot) } returns Unit
storage.updateSentState(Event.GrowthData.FirstUriLoadForDay)
assertTrue(updateSlot.captured > 0)
}
private fun Calendar.copy() = clone() as Calendar
private fun Calendar.createNextDay() = copy().apply {
add(Calendar.DAY_OF_MONTH, 1)

View File

@ -6,6 +6,7 @@ package org.mozilla.fenix.telemetry
import androidx.test.core.app.ApplicationProvider
import io.mockk.mockk
import io.mockk.verify
import mozilla.components.browser.state.action.ContentAction
import mozilla.components.browser.state.action.EngineAction
import mozilla.components.browser.state.action.TabListAction
@ -32,6 +33,7 @@ import org.junit.Test
import org.junit.runner.RunWith
import org.mozilla.fenix.GleanMetrics.Events
import org.mozilla.fenix.GleanMetrics.Metrics
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.components.metrics.MetricController
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
import org.mozilla.fenix.utils.Settings
@ -365,6 +367,13 @@ class TelemetryMiddlewareTest {
assertNotNull(Events.formDataFailure.testGetValue())
}
@Test
fun `WHEN uri loaded to engine THEN matching event is sent to metrics`() {
store.dispatch(EngineAction.LoadUrlAction("", "")).joinBlocking()
verify { metrics.track(Event.GrowthData.FirstUriLoadForDay) }
}
}
internal class FakeClock : Clock.Delegate {