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

For #1857: Adds telemetry for QR scanner #2524

Merged
merged 1 commit into from May 17, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
48 changes: 47 additions & 1 deletion app/metrics.yaml
Expand Up @@ -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"
Expand Up @@ -22,6 +22,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),
Expand Down Expand Up @@ -158,6 +159,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
Expand Down
Expand Up @@ -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(
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/java/org/mozilla/fenix/search/SearchFragment.kt
Expand Up @@ -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(
Expand All @@ -121,20 +122,22 @@ 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,
newTab = sessionId == null,
from = BrowserDirection.FromSearch
)
dialog.dismiss()
// TODO add metrics
}
create()
}.show()
requireComponents.analytics.metrics.track(Event.QRScannerPromptDisplayed)
}
}),
owner = this,
Expand All @@ -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)
}

Expand Down