1
0
Fork 0

For #1857: Adds telemetry for QR scanner

master
Sawyer Blatz 2019-05-15 10:01:26 -07:00 committed by Jeff Boek
parent 732b255ce5
commit 9e50b55340
4 changed files with 69 additions and 2 deletions

View File

@ -633,4 +633,50 @@ activation:
- https://github.com/mozilla-mobile/fenix/pull/1707#issuecomment-486972209
notification_emails:
- fenix-core@mozilla.com
expires: "2019-10-01"
expires: "2019-10-01"
qr_scanner:
opened:
type: event
description: >
A user opened the QR scanner
bugs:
- 1857
data_reviews:
- https://github.com/mozilla-mobile/fenix/pull/2524#issuecomment-492739967
notification_emails:
- fenix-core@mozilla.com
expires: "2020-03-01"
prompt_displayed:
type: event
description: >
A user scanned a QR code, causing a confirmation prompt to display asking if they want to navigate to the page
bugs:
- 1857
data_reviews:
- https://github.com/mozilla-mobile/fenix/pull/2524#issuecomment-492739967
notification_emails:
- fenix-core@mozilla.com
expires: "2020-03-01"
navigation_allowed:
type: event
description: >
A user tapped "allow" on the prompt, directing the user to the website scanned
bugs:
- 1857
data_reviews:
- https://github.com/mozilla-mobile/fenix/pull/2524#issuecomment-492739967
notification_emails:
- fenix-core@mozilla.com
expires: "2020-03-01"
navigation_denied:
type: event
description: >
A user tapped "deny" on the prompt, putting the user back to the scanning view
bugs:
- 1857
data_reviews:
- https://github.com/mozilla-mobile/fenix/pull/2524#issuecomment-492739967
notification_emails:
- fenix-core@mozilla.com
expires: "2020-03-01"

View File

@ -23,6 +23,7 @@ import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.runBlocking
import org.mozilla.fenix.GleanMetrics.QrScanner
private class EventWrapper<T : Enum<T>>(
private val recorder: ((Map<T, String>?) -> Unit),
@ -159,6 +160,18 @@ private val Event.wrapper
is Event.UriOpened -> EventWrapper<NoExtraKeys>(
{ Events.totalUriCount.add(1) }
)
is Event.QRScannerOpened -> EventWrapper<NoExtraKeys>(
{ QrScanner.opened.record(it) }
)
is Event.QRScannerPromptDisplayed -> EventWrapper<NoExtraKeys>(
{ QrScanner.promptDisplayed.record(it) }
)
is Event.QRScannerNavigationAllowed -> EventWrapper<NoExtraKeys>(
{ QrScanner.navigationAllowed.record(it) }
)
is Event.QRScannerNavigationDenied -> EventWrapper<NoExtraKeys>(
{ QrScanner.navigationDenied.record(it) }
)
// Don't track other events with Glean
else -> null

View File

@ -74,6 +74,10 @@ sealed class Event {
object CustomTabsActionTapped : Event()
object CustomTabsMenuOpened : Event()
object UriOpened : Event()
object QRScannerOpened : Event()
object QRScannerPromptDisplayed : Event()
object QRScannerNavigationAllowed : Event()
object QRScannerNavigationDenied : Event()
data class PreferenceToggled(val preferenceKey: String, val enabled: Boolean, val context: Context) : Event() {
private val switchPreferenceTelemetryAllowList = listOf(

View File

@ -110,6 +110,7 @@ class SearchFragment : Fragment(), BackHandler {
requestPermissions(permissions, REQUEST_CODE_CAMERA_PERMISSIONS)
},
onScanResult = { result ->
search_scan_button.isChecked = false
activity?.let {
AlertDialog.Builder(it).apply {
val spannable = resources.getSpannable(
@ -121,9 +122,11 @@ class SearchFragment : Fragment(), BackHandler {
)
setMessage(spannable)
setNegativeButton("DENY") { dialog: DialogInterface, _ ->
requireComponents.analytics.metrics.track(Event.QRScannerNavigationDenied)
dialog.cancel()
}
setPositiveButton("ALLOW") { dialog: DialogInterface, _ ->
requireComponents.analytics.metrics.track(Event.QRScannerNavigationAllowed)
(activity as HomeActivity)
.openToBrowserAndLoad(
searchTermOrURL = result,
@ -131,10 +134,10 @@ class SearchFragment : Fragment(), BackHandler {
from = BrowserDirection.FromSearch
)
dialog.dismiss()
// TODO add metrics
}
create()
}.show()
requireComponents.analytics.metrics.track(Event.QRScannerPromptDisplayed)
}
}),
owner = this,
@ -143,6 +146,7 @@ class SearchFragment : Fragment(), BackHandler {
view.search_scan_button.setOnClickListener {
getManagedEmitter<SearchChange>().onNext(SearchChange.ToolbarClearedFocus)
requireComponents.analytics.metrics.track(Event.QRScannerOpened)
qrFeature.get()?.scan(R.id.container)
}