Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
Merge branch 'master' of github.com:mozilla-mobile/fenix into fix-rea…
Browse files Browse the repository at this point in the history
…der-telem
  • Loading branch information
boek committed Aug 1, 2019
2 parents fd29fa1 + 2e7a618 commit 9ff12e0
Show file tree
Hide file tree
Showing 14 changed files with 118 additions and 21 deletions.
41 changes: 40 additions & 1 deletion app/metrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1051,4 +1051,43 @@ collections:
- https://github.com/mozilla-mobile/fenix/pull/3935
notification_emails:
- fenix-core@mozilla.com
expires: "2020-03-01"
expires: "2020-03-01"
add_tab_button:
type: event
description: >
A user tapped the "add tab" button in the three dot menu of collections
bugs:
- 969
data_reviews:
- https://github.com/mozilla-mobile/fenix/pull/4358
notification_emails:
- fenix-core@mozilla.com
expires: "2020-03-01"
long_press:
type: event
description: >
A user long pressed on a tab, triggering the collection creation screen
bugs:
- 969
data_reviews:
- https://github.com/mozilla-mobile/fenix/pull/4358
notification_emails:
- fenix-core@mozilla.com
expires: "2020-03-01"
save_button:
type: event
description: >
A user pressed the "save to collection" button on either the home or browser screen, triggering the
collection creation screen to open (tab_select_opened)
bugs:
- 969
data_reviews:
- https://github.com/mozilla-mobile/fenix/pull/4358
notification_emails:
- fenix-core@mozilla.com
expires: "2020-03-01"
extra_keys:
from_screen:
description: >
A string representing the screen from which the user pressed the save button.
Either `browser` or `home`
2 changes: 1 addition & 1 deletion app/src/main/java/org/mozilla/fenix/HomeActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ open class HomeActivity : AppCompatActivity(), ShareFragment.TabsSharedCallback
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

components.utils.publicSuffixList.prefetch()
components.publicSuffixList.prefetch()
setupThemeAndBrowsingMode()

setContentView(R.layout.activity_home)
Expand Down
10 changes: 3 additions & 7 deletions app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,10 @@ class BrowserFragment : Fragment(), BackHandler {
)

quickActionSheetView = QuickActionSheetView(view.nestedScrollQuickAction, browserInteractor)
}

browserToolbarView.view.setOnSiteSecurityClickedListener {
showQuickSettingsDialog()
browserToolbarView.view.setOnSiteSecurityClickedListener {
showQuickSettingsDialog()
}
}

contextMenuFeature.set(
Expand Down Expand Up @@ -421,10 +421,6 @@ class BrowserFragment : Fragment(), BackHandler {
view = view)
}

browserToolbarView.view.setOnSiteSecurityClickedListener {
showQuickSettingsDialog()
}

consumeFrom(browserStore) {
quickActionSheetView.update(it)
browserToolbarView.update(it)
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/org/mozilla/fenix/components/Components.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package org.mozilla.fenix.components

import android.content.Context
import mozilla.components.lib.publicsuffixlist.PublicSuffixList
import org.mozilla.fenix.test.Mockable

/**
Expand All @@ -21,4 +22,5 @@ class Components(private val context: Context) {
val useCases by lazy { UseCases(context, core.sessionManager, core.engine.settings, search.searchEngineManager) }
val utils by lazy { Utilities(context, core.sessionManager, useCases.sessionUseCases, useCases.searchUseCases) }
val analytics by lazy { Analytics(context) }
val publicSuffixList by lazy { PublicSuffixList(context) }
}
3 changes: 0 additions & 3 deletions app/src/main/java/org/mozilla/fenix/components/Utilities.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import mozilla.components.feature.customtabs.CustomTabIntentProcessor
import mozilla.components.feature.intent.TabIntentProcessor
import mozilla.components.feature.search.SearchUseCases
import mozilla.components.feature.session.SessionUseCases
import mozilla.components.lib.publicsuffixlist.PublicSuffixList
import org.mozilla.fenix.test.Mockable

/**
Expand Down Expand Up @@ -38,6 +37,4 @@ class Utilities(
val customTabIntentProcessor by lazy {
CustomTabIntentProcessor(sessionManager, sessionUseCases.loadUrl, context.resources)
}

val publicSuffixList by lazy { PublicSuffixList(context) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -266,12 +266,19 @@ private val Event.wrapper
is Event.ReaderModeOpened -> EventWrapper<NoExtraKeys>(
{ ReaderMode.opened.record(it) }
)
is Event.ReaderModeClosed -> EventWrapper<NoExtraKeys>(
{ ReaderMode.closed.record(it) }
)
is Event.ReaderModeAppearanceOpened -> EventWrapper<NoExtraKeys>(
{ ReaderMode.appearance.record(it) }
)
is Event.CollectionTabLongPressed -> EventWrapper<NoExtraKeys>(
{ Collections.longPress.record(it) }
)
is Event.CollectionSaveButtonPressed -> EventWrapper(
{ Collections.saveButton.record(it) },
{ Collections.saveButtonKeys.valueOf(it) }
)
is Event.CollectionAddTabPressed -> EventWrapper<NoExtraKeys>(
{ Collections.addTabButton.record(it) }
)

// Don't track other events with Glean
else -> null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ sealed class Event {
object CollectionShared : Event()
object CollectionRemoved : Event()
object CollectionTabSelectOpened : Event()
object CollectionTabLongPressed : Event()
object CollectionAddTabPressed : Event()

data class PreferenceToggled(val preferenceKey: String, val enabled: Boolean, val context: Context) : Event() {
private val switchPreferenceTelemetryAllowList = listOf(
Expand All @@ -131,6 +133,11 @@ sealed class Event {
}

// Interaction Events
data class CollectionSaveButtonPressed(val fromScreen: String) : Event() {
override val extras: Map<String, String>?
get() = mapOf("from_screen" to fromScreen)
}

data class CollectionSaved(val tabsOpenCount: Int, val tabsSelectedCount: Int) : Event() {
override val extras: Map<String, String>?
get() = mapOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ class DefaultBrowserToolbarController(
BrowsingModeManager.Mode.Normal
}
ToolbarMenu.Item.SaveToCollection -> {
context.components.analytics.metrics
.track(Event.CollectionSaveButtonPressed(TELEMETRY_BROWSER_IDENITIFIER))
currentSession.let {
val tab = it.toTab(context)
viewModel.tabs = listOf(tab)
Expand Down Expand Up @@ -184,4 +186,8 @@ class DefaultBrowserToolbarController(

context.components.analytics.metrics.track(Event.BrowserMenuItemTapped(eventItem))
}

companion object {
private const val TELEMETRY_BROWSER_IDENITIFIER = "browser"
}
}
2 changes: 1 addition & 1 deletion app/src/main/java/org/mozilla/fenix/ext/String.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fun String.urlToTrimmedHost(context: Context): String {
return try {
val host = toUri().hostWithoutCommonPrefixes ?: return this
runBlocking {
context.components.utils.publicSuffixList.stripPublicSuffix(host).await()
context.components.publicSuffixList.stripPublicSuffix(host).await()
}
} catch (e: MalformedURLException) {
this
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ class HomeFragment : Fragment(), AccountObserver {
createDeleteCollectionPrompt(action.collection)
}
is CollectionAction.AddTab -> {
requireComponents.analytics.metrics.track(Event.CollectionAddTabPressed)
showCollectionCreationFragment(
selectedTabCollection = action.collection,
step = SaveCollectionStep.SelectTabs
Expand Down Expand Up @@ -841,6 +842,7 @@ class HomeFragment : Fragment(), AccountObserver {
private const val FADE_ANIM_DURATION = 150L
private const val ANIM_SNACKBAR_DELAY = 100L
private const val ACCESSIBILITY_FOCUS_DELAY = 2000L
private const val TELEMETRY_HOME_IDENITIFIER = "home"
private const val SHARED_TRANSITION_MS = 200L
private const val TAB_ITEM_TRANSITION_NAME = "tab_item"
private const val toolbarPaddingDp = 12f
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import androidx.recyclerview.widget.RecyclerView
import io.reactivex.Observer
import kotlinx.android.synthetic.main.save_tab_group_button.view.*
import org.mozilla.fenix.R
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.home.sessioncontrol.SessionControlAction
import org.mozilla.fenix.home.sessioncontrol.TabAction
import org.mozilla.fenix.home.sessioncontrol.onNext
Expand All @@ -20,11 +22,15 @@ class SaveTabGroupViewHolder(

init {
view.save_tab_group_button.setOnClickListener {
view.context.components.analytics.metrics
.track(Event.CollectionSaveButtonPressed(TELEMETRY_HOME_IDENITIFIER))

actionEmitter.onNext(TabAction.SaveTabGroup(selectedTabSessionId = null))
}
}

companion object {
const val TELEMETRY_HOME_IDENITIFIER = "home"
const val LAYOUT_ID = R.layout.save_tab_group_button
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import mozilla.components.browser.menu.BrowserMenuBuilder
import mozilla.components.browser.menu.item.SimpleBrowserMenuItem
import mozilla.components.support.ktx.android.util.dpToFloat
import org.mozilla.fenix.R
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.increaseTapArea
import org.mozilla.fenix.ext.loadIntoView
Expand Down Expand Up @@ -48,6 +49,7 @@ class TabViewHolder(
}

item_tab.setOnLongClickListener {
view.context.components.analytics.metrics.track(Event.CollectionTabLongPressed)
actionEmitter.onNext(TabAction.SaveTabGroup(tab?.sessionId!!))
true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,11 @@ class BrowserInteractorTest {
every { context.metrics } returns metrics
every { context.components.core.sessionManager.selectedSession } returns session
every { session.readerMode } returns false
every { metrics.track(Event.QuickActionSheetReadTapped) } just Runs
every { metrics.track(Event.QuickActionSheetOpened) } just Runs

interactor.onQuickActionSheetReadPressed()

verify { metrics.track(Event.QuickActionSheetReadTapped) }
verify { metrics.track(Event.QuickActionSheetOpened) }
verify { readerModeController.showReaderView() }
}

Expand All @@ -209,11 +209,11 @@ class BrowserInteractorTest {
every { context.metrics } returns metrics
every { context.components.core.sessionManager.selectedSession } returns session
every { session.readerMode } returns true
every { metrics.track(Event.QuickActionSheetReadTapped) } just Runs
every { metrics.track(Event.QuickActionSheetClosed) } just Runs

interactor.onQuickActionSheetReadPressed()

verify { metrics.track(Event.QuickActionSheetReadTapped) }
verify { metrics.track(Event.QuickActionSheetClosed) }
verify { readerModeController.hideReaderView() }
}

Expand All @@ -240,8 +240,12 @@ class BrowserInteractorTest {
@Test
fun onQuickActionSheetAppearancePressed() {
val context: Context = mockk()
val metrics: MetricController = mockk()
val readerModeController: ReaderModeController = mockk(relaxed = true)

every { context.metrics } returns metrics
every { metrics.track(Event.ReaderModeAppearanceOpened) } just Runs

val interactor = BrowserInteractor(
context,
mockk(),
Expand All @@ -253,6 +257,9 @@ class BrowserInteractorTest {

interactor.onQuickActionSheetAppearancePressed()

verify { readerModeController.showControls() }
verify {
metrics.track(Event.ReaderModeAppearanceOpened)
readerModeController.showControls()
}
}
}
26 changes: 26 additions & 0 deletions docs/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,32 @@ tabs_selected: The number of tabs added to the collection
<td></td>
<td>2020-03-01</td>
</tr>
<tr>
<td>add_tab_button</td>
<td>event</td>
<td> A user tapped the "add tab" button in the three dot menu of collections</td>
<td><a href="https://github.com/mozilla-mobile/fenix/pull/4358">link</a></td>
<td></td>
<td>2020-03-01</td>
</tr>
<tr>
<td>long_press</td>
<td>event</td>
<td> A user long pressed on a tab, triggering the collection creation screen</td>
<td><a href="https://github.com/mozilla-mobile/fenix/pull/4358">link</a></td>
<td></td>
<td>2020-03-01</td>
</tr>
<tr>
<td>save_button</td>
<td>event</td>
<td>A user pressed the "save to collection" button on either the home or browser screen, triggering the
collection creation screen to open (tab_select_opened)</td>
<td><a href="https://github.com/mozilla-mobile/fenix/pull/3935">link</a></td>
<td>from_screen: A string representing the screen from which the user pressed the save button. Either `browser` or `home`
</td>
<td>2020-03-01</td>
</tr>
</table>
</pre>

Expand Down

0 comments on commit 9ff12e0

Please sign in to comment.