Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Commit 143a88a

Browse files
authored
Tabs and FxA Telemetry (#2327)
1 parent f567fff commit 143a88a

File tree

12 files changed

+270
-10
lines changed

12 files changed

+270
-10
lines changed

app/metrics.yaml

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,147 @@ searches:
8383
8484
8585
expires: "2020-05-01"
86+
87+
tabs:
88+
opened:
89+
type: labeled_counter
90+
description: >
91+
Number of tabs opened during a session
92+
send_in_pings:
93+
- session_end
94+
labels:
95+
- context_menu
96+
- tabs_dialog
97+
- bookmarks
98+
- history
99+
- fxa_login
100+
- received
101+
- pre_existing
102+
- browser
103+
bugs:
104+
- https://github.com/MozillaReality/FirefoxReality/issues/1609
105+
data_reviews:
106+
- https://github.com/MozillaReality/FirefoxReality/pull/2327#issuecomment-559103837
107+
notification_emails:
108+
109+
110+
expires: "2020-05-01"
111+
112+
activated:
113+
type: counter
114+
description: >
115+
Number of tabs activated during a session
116+
send_in_pings:
117+
- session_end
118+
bugs:
119+
- https://github.com/MozillaReality/FirefoxReality/issues/1609
120+
data_reviews:
121+
- https://github.com/MozillaReality/FirefoxReality/pull/2327#issuecomment-559103837
122+
notification_emails:
123+
124+
125+
expires: "2020-05-01"
126+
127+
firefox_account:
128+
sign_in:
129+
type: event
130+
description: >
131+
The user starts the sign in flow
132+
bugs:
133+
- https://github.com/MozillaReality/FirefoxReality/issues/1610
134+
data_reviews:
135+
- https://github.com/MozillaReality/FirefoxReality/pull/2327#issuecomment-559103837
136+
notification_emails:
137+
138+
139+
expires: "2020-05-01"
140+
141+
sign_in_result:
142+
type: event
143+
description: >
144+
The user finishes the sign in flow
145+
extra_keys:
146+
state:
147+
description: "The result of the sign in flow. True in case of success, false in case of error"
148+
bugs:
149+
- https://github.com/MozillaReality/FirefoxReality/issues/1610
150+
data_reviews:
151+
- https://github.com/MozillaReality/FirefoxReality/pull/2327#issuecomment-559103837
152+
notification_emails:
153+
154+
155+
expires: "2020-05-01"
156+
157+
sign_out:
158+
type: event
159+
description: >
160+
A user pressed the sign out button on the sync account page and was successfully signed out of FxA
161+
bugs:
162+
- https://github.com/MozillaReality/FirefoxReality/issues/1610
163+
data_reviews:
164+
- https://github.com/MozillaReality/FirefoxReality/pull/2327#issuecomment-559103837
165+
notification_emails:
166+
167+
168+
expires: "2020-05-01"
169+
170+
bookmarks_sync_status:
171+
type: boolean
172+
lifetime: application
173+
description: >
174+
Bookmarks sync engine status. True means that the bookmarks sync status is enabled, false otherwise.
175+
bugs:
176+
- https://github.com/MozillaReality/FirefoxReality/issues/1610
177+
data_reviews:
178+
- https://github.com/MozillaReality/FirefoxReality/pull/2327#issuecomment-559103837
179+
notification_emails:
180+
181+
182+
expires: "2020-05-01"
183+
184+
history_sync_status:
185+
type: boolean
186+
lifetime: application
187+
description: >
188+
History sync engine status. True means that the history sync status is enabled, false otherwise.
189+
bugs:
190+
- https://github.com/MozillaReality/FirefoxReality/issues/1610
191+
data_reviews:
192+
- https://github.com/MozillaReality/FirefoxReality/pull/2327#issuecomment-559103837
193+
notification_emails:
194+
195+
196+
expires: "2020-05-01"
197+
198+
tab_sent:
199+
type: counter
200+
description: >
201+
Number of tabs successfully sent per day
202+
bugs:
203+
- https://github.com/MozillaReality/FirefoxReality/issues/1610
204+
data_reviews:
205+
- https://github.com/MozillaReality/FirefoxReality/pull/2327#issuecomment-559103837
206+
notification_emails:
207+
208+
209+
expires: "2020-05-01"
210+
211+
received_tab:
212+
type: labeled_counter
213+
description: >
214+
Number of received tabs per day
215+
labels:
216+
- desktop
217+
- mobile
218+
- tablet
219+
- tv
220+
- vr
221+
- unknown
222+
bugs:
223+
- https://github.com/MozillaReality/FirefoxReality/issues/1610
224+
data_reviews:
225+
- https://github.com/MozillaReality/FirefoxReality/pull/2327#issuecomment-559103837
226+
notification_emails:
227+
228+
229+
expires: "2020-05-01"

app/src/common/shared/org/mozilla/vrbrowser/browser/Accounts.kt

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import mozilla.components.service.fxa.sync.getLastSynced
2626
import org.mozilla.vrbrowser.R
2727
import org.mozilla.vrbrowser.VRBrowserApplication
2828
import org.mozilla.vrbrowser.utils.BitmapCache
29+
import org.mozilla.vrbrowser.telemetry.GleanMetricsService
2930
import org.mozilla.vrbrowser.utils.SystemUtils
3031
import org.mozilla.vrbrowser.utils.ViewUtils
3132
import java.net.URL
@@ -119,6 +120,10 @@ class Accounts constructor(val context: Context) {
119120
override fun onAuthenticated(account: OAuthAccount, authType: AuthType) {
120121
Log.d(LOGTAG, "The user has been successfully logged in")
121122

123+
if (authType !== AuthType.Existing) {
124+
GleanMetricsService.FxA.signInResult(true)
125+
}
126+
122127
accountStatus = AccountStatus.SIGNED_IN
123128

124129
// Enable syncing after signing in
@@ -144,6 +149,8 @@ class Accounts constructor(val context: Context) {
144149
override fun onAuthenticationProblems() {
145150
Log.d(LOGTAG, "There was a problem authenticating the user")
146151

152+
GleanMetricsService.FxA.signInResult(false)
153+
147154
accountStatus = AccountStatus.NEEDS_RECONNECT
148155
accountListeners.toMutableList().forEach {
149156
Handler(Looper.getMainLooper()).post {
@@ -272,6 +279,7 @@ class Accounts constructor(val context: Context) {
272279
}
273280

274281
fun authUrlAsync(): CompletableFuture<String?>? {
282+
GleanMetricsService.FxA.signIn()
275283
return CoroutineScope(Dispatchers.Main).future {
276284
services.accountManager.beginAuthenticationAsync().await()
277285
}
@@ -303,10 +311,15 @@ class Accounts constructor(val context: Context) {
303311
}
304312

305313
fun setSyncStatus(engine: SyncEngine, value: Boolean) {
306-
307314
when(engine) {
308-
SyncEngine.Bookmarks -> SettingsStore.getInstance(context).isBookmarksSyncEnabled = value
309-
SyncEngine.History -> SettingsStore.getInstance(context).isHistorySyncEnabled = value
315+
SyncEngine.Bookmarks -> {
316+
GleanMetricsService.FxA.bookmarksSyncStatus(value)
317+
SettingsStore.getInstance(context).isBookmarksSyncEnabled = value
318+
}
319+
SyncEngine.History -> {
320+
GleanMetricsService.FxA.historySyncStatus(value)
321+
SettingsStore.getInstance(context).isHistorySyncEnabled = value
322+
}
310323
}
311324

312325
syncStorage.setStatus(engine, value)
@@ -316,7 +329,9 @@ class Accounts constructor(val context: Context) {
316329
return services.accountManager.accountProfile()
317330
}
318331

319-
fun logoutAsync(): CompletableFuture<Unit?> {
332+
fun logoutAsync(): CompletableFuture<Unit?>? {
333+
GleanMetricsService.FxA.signOut()
334+
320335
otherDevices = emptyList()
321336
return CoroutineScope(Dispatchers.Main).future {
322337
services.accountManager.logoutAsync().await()
@@ -351,10 +366,10 @@ class Accounts constructor(val context: Context) {
351366
targetDevices.contains(it)
352367
}
353368

354-
targets?.forEach {
369+
targets?.forEach { it ->
355370
constellation.sendEventToDeviceAsync(
356371
it.id, DeviceEventOutgoing.SendTab(title, url)
357-
).await()
372+
).await().also { if (it) GleanMetricsService.FxA.sentTab() }
358373
}
359374
}
360375
}

app/src/common/shared/org/mozilla/vrbrowser/browser/Services.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import org.mozilla.vrbrowser.browser.engine.EngineProvider
3232
import org.mozilla.vrbrowser.browser.engine.GeckoViewFetchClient
3333
import org.mozilla.vrbrowser.browser.engine.SessionStore
3434
import org.mozilla.vrbrowser.utils.SystemUtils
35+
import org.mozilla.vrbrowser.telemetry.GleanMetricsService
3536

3637

3738
class Services(val context: Context, places: Places): GeckoSession.NavigationDelegate {
@@ -85,7 +86,10 @@ class Services(val context: Context, places: Places): GeckoSession.NavigationDel
8586
Logger(logTag).info("Received ${events.size} device event(s)")
8687
val filteredEvents = events.filterIsInstance(DeviceEvent.TabReceived::class.java)
8788
if (filteredEvents.isNotEmpty()) {
88-
val tabs = filteredEvents.map { event -> event.entries }.flatten()
89+
filteredEvents.map { event -> event.from?.deviceType?.let { GleanMetricsService.FxA.receivedTab(it) } }
90+
val tabs = filteredEvents.map {
91+
event -> event.entries
92+
}.flatten()
8993
tabReceivedDelegate?.onTabsReceived(tabs)
9094
}
9195
}

app/src/common/shared/org/mozilla/vrbrowser/telemetry/GleanMetricsService.java

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,25 @@
33
import android.content.Context;
44
import android.util.Log;
55

6+
import androidx.annotation.NonNull;
67
import androidx.annotation.UiThread;
78

9+
import org.mozilla.vrbrowser.BuildConfig;
10+
import org.mozilla.vrbrowser.GleanMetrics.Distribution;
11+
import org.mozilla.vrbrowser.GleanMetrics.FirefoxAccount;
812
import org.mozilla.vrbrowser.GleanMetrics.Pings;
913
import org.mozilla.vrbrowser.GleanMetrics.Searches;
1014
import org.mozilla.vrbrowser.GleanMetrics.Url;
1115
import org.mozilla.vrbrowser.browser.SettingsStore;
1216
import org.mozilla.vrbrowser.search.SearchEngineWrapper;
1317
import org.mozilla.vrbrowser.utils.DeviceType;
1418
import org.mozilla.vrbrowser.utils.SystemUtils;
15-
import org.mozilla.vrbrowser.BuildConfig;
16-
import org.mozilla.vrbrowser.GleanMetrics.Distribution;
1719
import org.mozilla.vrbrowser.utils.UrlUtils;
1820

1921
import java.net.URI;
22+
import java.util.HashMap;
2023
import java.util.HashSet;
24+
import java.util.Map;
2125

2226
import mozilla.components.service.glean.Glean;
2327
import mozilla.components.service.glean.config.Configuration;
@@ -149,4 +153,59 @@ private static String getDefaultSearchEngineIdentifierForTelemetry() {
149153
private static void setStartupMetrics() {
150154
Distribution.INSTANCE.getChannelName().set(DeviceType.isOculusBuild() ? "oculusvr" : BuildConfig.FLAVOR_platform);
151155
}
156+
157+
public static class FxA {
158+
159+
public static void signIn() {
160+
FirefoxAccount.INSTANCE.getSignIn().record();
161+
}
162+
163+
public static void signInResult(boolean status) {
164+
Map<FirefoxAccount.signInResultKeys, String> map = new HashMap<>();
165+
map.put(FirefoxAccount.signInResultKeys.state, String.valueOf(status));
166+
FirefoxAccount.INSTANCE.getSignInResult().record(map);
167+
}
168+
169+
public static void signOut() {
170+
FirefoxAccount.INSTANCE.getSignOut().record();
171+
}
172+
173+
public static void bookmarksSyncStatus(boolean status) {
174+
FirefoxAccount.INSTANCE.getBookmarksSyncStatus().set(status);
175+
}
176+
177+
public static void historySyncStatus(boolean status) {
178+
FirefoxAccount.INSTANCE.getHistorySyncStatus().set(status);
179+
}
180+
181+
public static void sentTab() {
182+
FirefoxAccount.INSTANCE.getTabSent().add();
183+
}
184+
185+
public static void receivedTab(@NonNull mozilla.components.concept.sync.DeviceType source) {
186+
FirefoxAccount.INSTANCE.getReceivedTab().get(source.name()).add();
187+
}
188+
}
189+
190+
public static class Tabs {
191+
192+
public enum TabSource {
193+
CONTEXT_MENU, // Tab opened from the browsers long click context menu
194+
TABS_DIALOG, // Tab opened from the tabs dialog
195+
BOOKMARKS, // Tab opened from the bookmarks panel
196+
HISTORY, // Tab opened from the history panel
197+
FXA_LOGIN, // Tab opened by the FxA login flow
198+
RECEIVED, // Tab opened by FxA when a tab is received
199+
PRE_EXISTING, // Tab opened as a result of restoring the last session
200+
BROWSER // Tab opened by the browser as a result of a new window open
201+
}
202+
203+
public static void openedCounter(@NonNull TabSource source) {
204+
org.mozilla.vrbrowser.GleanMetrics.Tabs.INSTANCE.getOpened().get(source.name()).add();
205+
}
206+
207+
public static void activatedEvent() {
208+
org.mozilla.vrbrowser.GleanMetrics.Tabs.INSTANCE.getActivated().add();
209+
}
210+
}
152211
}

app/src/common/shared/org/mozilla/vrbrowser/ui/views/BookmarksView.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.mozilla.vrbrowser.browser.engine.Session;
3131
import org.mozilla.vrbrowser.browser.engine.SessionStore;
3232
import org.mozilla.vrbrowser.databinding.BookmarksBinding;
33+
import org.mozilla.vrbrowser.telemetry.GleanMetricsService;
3334
import org.mozilla.vrbrowser.ui.adapters.Bookmark;
3435
import org.mozilla.vrbrowser.ui.adapters.BookmarkAdapter;
3536
import org.mozilla.vrbrowser.ui.adapters.CustomLinearLayoutManager;
@@ -230,6 +231,7 @@ public void onFxALogin(@NonNull View view) {
230231
WidgetManagerDelegate widgetManager = ((VRBrowserActivity) getContext());
231232
widgetManager.openNewTabForeground(url);
232233
widgetManager.getFocusedWindow().getSession().setUaMode(GeckoSessionSettings.USER_AGENT_MODE_MOBILE);
234+
GleanMetricsService.Tabs.openedCounter(GleanMetricsService.Tabs.TabSource.FXA_LOGIN);
233235

234236
mBookmarksViewListeners.forEach((listener) -> listener.onFxALogin(view));
235237
}

app/src/common/shared/org/mozilla/vrbrowser/ui/views/HistoryView.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.mozilla.vrbrowser.browser.engine.Session;
3131
import org.mozilla.vrbrowser.browser.engine.SessionStore;
3232
import org.mozilla.vrbrowser.databinding.HistoryBinding;
33+
import org.mozilla.vrbrowser.telemetry.GleanMetricsService;
3334
import org.mozilla.vrbrowser.ui.adapters.HistoryAdapter;
3435
import org.mozilla.vrbrowser.ui.callbacks.HistoryCallback;
3536
import org.mozilla.vrbrowser.ui.callbacks.HistoryItemCallback;
@@ -225,6 +226,7 @@ public void onFxALogin(@NonNull View view) {
225226
WidgetManagerDelegate widgetManager = ((VRBrowserActivity) getContext());
226227
widgetManager.openNewTabForeground(url);
227228
widgetManager.getFocusedWindow().getSession().setUaMode(GeckoSessionSettings.USER_AGENT_MODE_MOBILE);
229+
GleanMetricsService.Tabs.openedCounter(GleanMetricsService.Tabs.TabSource.FXA_LOGIN);
228230

229231
mHistoryViewListeners.forEach((listener) -> listener.onFxALogin(view));
230232
}

app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/WindowWidget.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,6 +1122,8 @@ public void onStackSession(Session aSession) {
11221122
SessionStore.get().setActiveSession(aSession);
11231123
current.captureBackgroundBitmap(getWindowWidth(), getWindowHeight()).thenAccept(aVoid -> current.setActive(false));
11241124
mWidgetManager.getTray().showTabAddedNotification();
1125+
1126+
GleanMetricsService.Tabs.openedCounter(GleanMetricsService.Tabs.TabSource.BROWSER);
11251127
}
11261128

11271129
@Override
@@ -1379,6 +1381,11 @@ public void onOpenInNewWindowClick(LibraryMenuWidget.LibraryContextMenuItem item
13791381
@Override
13801382
public void onOpenInNewTabClick(LibraryMenuWidget.LibraryContextMenuItem item) {
13811383
mWidgetManager.openNewTabForeground(item.getUrl());
1384+
if (item.getType() == LibraryMenuWidget.LibraryItemType.HISTORY) {
1385+
GleanMetricsService.Tabs.openedCounter(GleanMetricsService.Tabs.TabSource.HISTORY);
1386+
} else if (item.getType() == LibraryMenuWidget.LibraryItemType.BOOKMARKS) {
1387+
GleanMetricsService.Tabs.openedCounter(GleanMetricsService.Tabs.TabSource.BOOKMARKS);
1388+
}
13821389
hideContextMenus();
13831390
}
13841391

0 commit comments

Comments
 (0)