Skip to content

Commit

Permalink
For mozilla-mobile#1242: Adds telemetry for error pages
Browse files Browse the repository at this point in the history
  • Loading branch information
sblatz committed May 15, 2019
1 parent a739d5a commit 22cc0f8
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
19 changes: 17 additions & 2 deletions app/metrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,6 @@ quick_action_sheet:
data_reviews:
- https://github.com/mozilla-mobile/fenix/pull/1362#issuecomment-479668466
notification_emails:

- fenix-core@mozilla.com
expires: "2020-03-01"
share_tapped:
Expand Down Expand Up @@ -633,4 +632,20 @@ 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"

error_page:
visited_error:
type: event
description: >
A user encountered an error page
extra_keys:
error_type:
description: "The error type of the error page encountered"
bugs:
- 1242
data_reviews:
- https://github.com/mozilla-mobile/fenix/pull/2491#issuecomment-492414486
notification_emails:
- fenix-core@mozilla.com
expires: "2020-03-01"
3 changes: 2 additions & 1 deletion app/src/main/java/org/mozilla/fenix/AppRequestInterceptor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import mozilla.components.browser.errorpages.ErrorPages
import mozilla.components.browser.errorpages.ErrorType
import mozilla.components.concept.engine.EngineSession
import mozilla.components.concept.engine.request.RequestInterceptor
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.exceptions.ExceptionDomains
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.utils.Settings
Expand Down Expand Up @@ -45,11 +46,11 @@ class AppRequestInterceptor(private val context: Context) : RequestInterceptor {
errorType: ErrorType,
uri: String?
): RequestInterceptor.ErrorResponse? {

val riskLevel = getRiskLevel(errorType)
val htmlResource = getPageForRiskLevel(riskLevel)
val cssResource = getStyleForRiskLevel(riskLevel)

context.components.analytics.metrics.track(Event.ErrorPageVisited(errorType))
return RequestInterceptor.ErrorResponse(
ErrorPages
.createErrorPage(context, errorType, uri = uri, htmlResource = htmlResource, cssResource = cssResource)
Expand Down
Original file line number Diff line number Diff line change
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.ErrorPage

private class EventWrapper<T : Enum<T>>(
private val recorder: ((Map<T, String>?) -> Unit),
Expand Down Expand Up @@ -158,6 +159,10 @@ private val Event.wrapper
is Event.UriOpened -> EventWrapper<NoExtraKeys>(
{ Events.totalUriCount.add(1) }
)
is Event.ErrorPageVisited -> EventWrapper(
{ ErrorPage.visitedError },
{ ErrorPage.visitedErrorKeys.valueOf(it) }
)

// Don't track other events with Glean
else -> null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package org.mozilla.fenix.components.metrics

import android.content.Context
import mozilla.components.browser.errorpages.ErrorType
import mozilla.components.browser.search.SearchEngine
import mozilla.components.support.base.Component
import mozilla.components.support.base.facts.Fact
Expand Down Expand Up @@ -99,6 +100,11 @@ sealed class Event {
}

// Interaction Events
data class ErrorPageVisited(val errorType: ErrorType) : Event() {
override val extras: Map<String, String>?
get() = mapOf("errorType" to errorType.name)
}

data class SearchBarTapped(val source: Source) : Event() {
enum class Source { HOME, BROWSER }
override val extras: Map<String, String>?
Expand Down

0 comments on commit 22cc0f8

Please sign in to comment.