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

Commit

Permalink
Tabs and FxA Telemetry (#2327)
Browse files Browse the repository at this point in the history
  • Loading branch information
keianhzo authored Nov 27, 2019
1 parent f567fff commit 143a88a
Show file tree
Hide file tree
Showing 12 changed files with 270 additions and 10 deletions.
144 changes: 144 additions & 0 deletions app/metrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,147 @@ searches:
- fxr-telemetry@mozilla.com
- dmu@mozilla.com
expires: "2020-05-01"

tabs:
opened:
type: labeled_counter
description: >
Number of tabs opened during a session
send_in_pings:
- session_end
labels:
- context_menu
- tabs_dialog
- bookmarks
- history
- fxa_login
- received
- pre_existing
- browser
bugs:
- https://github.com/MozillaReality/FirefoxReality/issues/1609
data_reviews:
- https://github.com/MozillaReality/FirefoxReality/pull/2327#issuecomment-559103837
notification_emails:
- fxr-telemetry@mozilla.com
- manmartin@mozilla.com
expires: "2020-05-01"

activated:
type: counter
description: >
Number of tabs activated during a session
send_in_pings:
- session_end
bugs:
- https://github.com/MozillaReality/FirefoxReality/issues/1609
data_reviews:
- https://github.com/MozillaReality/FirefoxReality/pull/2327#issuecomment-559103837
notification_emails:
- fxr-telemetry@mozilla.com
- manmartin@mozilla.com
expires: "2020-05-01"

firefox_account:
sign_in:
type: event
description: >
The user starts the sign in flow
bugs:
- https://github.com/MozillaReality/FirefoxReality/issues/1610
data_reviews:
- https://github.com/MozillaReality/FirefoxReality/pull/2327#issuecomment-559103837
notification_emails:
- fxr-telemetry@mozilla.com
- manmartin@mozilla.com
expires: "2020-05-01"

sign_in_result:
type: event
description: >
The user finishes the sign in flow
extra_keys:
state:
description: "The result of the sign in flow. True in case of success, false in case of error"
bugs:
- https://github.com/MozillaReality/FirefoxReality/issues/1610
data_reviews:
- https://github.com/MozillaReality/FirefoxReality/pull/2327#issuecomment-559103837
notification_emails:
- fxr-telemetry@mozilla.com
- manmartin@mozilla.com
expires: "2020-05-01"

sign_out:
type: event
description: >
A user pressed the sign out button on the sync account page and was successfully signed out of FxA
bugs:
- https://github.com/MozillaReality/FirefoxReality/issues/1610
data_reviews:
- https://github.com/MozillaReality/FirefoxReality/pull/2327#issuecomment-559103837
notification_emails:
- fxr-telemetry@mozilla.com
- manmartin@mozilla.com
expires: "2020-05-01"

bookmarks_sync_status:
type: boolean
lifetime: application
description: >
Bookmarks sync engine status. True means that the bookmarks sync status is enabled, false otherwise.
bugs:
- https://github.com/MozillaReality/FirefoxReality/issues/1610
data_reviews:
- https://github.com/MozillaReality/FirefoxReality/pull/2327#issuecomment-559103837
notification_emails:
- fxr-telemetry@mozilla.com
- manmartin@mozilla.com
expires: "2020-05-01"

history_sync_status:
type: boolean
lifetime: application
description: >
History sync engine status. True means that the history sync status is enabled, false otherwise.
bugs:
- https://github.com/MozillaReality/FirefoxReality/issues/1610
data_reviews:
- https://github.com/MozillaReality/FirefoxReality/pull/2327#issuecomment-559103837
notification_emails:
- fxr-telemetry@mozilla.com
- manmartin@mozilla.com
expires: "2020-05-01"

tab_sent:
type: counter
description: >
Number of tabs successfully sent per day
bugs:
- https://github.com/MozillaReality/FirefoxReality/issues/1610
data_reviews:
- https://github.com/MozillaReality/FirefoxReality/pull/2327#issuecomment-559103837
notification_emails:
- fxr-telemetry@mozilla.com
- manmartin@mozilla.com
expires: "2020-05-01"

received_tab:
type: labeled_counter
description: >
Number of received tabs per day
labels:
- desktop
- mobile
- tablet
- tv
- vr
- unknown
bugs:
- https://github.com/MozillaReality/FirefoxReality/issues/1610
data_reviews:
- https://github.com/MozillaReality/FirefoxReality/pull/2327#issuecomment-559103837
notification_emails:
- fxr-telemetry@mozilla.com
- manmartin@mozilla.com
expires: "2020-05-01"
27 changes: 21 additions & 6 deletions app/src/common/shared/org/mozilla/vrbrowser/browser/Accounts.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import mozilla.components.service.fxa.sync.getLastSynced
import org.mozilla.vrbrowser.R
import org.mozilla.vrbrowser.VRBrowserApplication
import org.mozilla.vrbrowser.utils.BitmapCache
import org.mozilla.vrbrowser.telemetry.GleanMetricsService
import org.mozilla.vrbrowser.utils.SystemUtils
import org.mozilla.vrbrowser.utils.ViewUtils
import java.net.URL
Expand Down Expand Up @@ -119,6 +120,10 @@ class Accounts constructor(val context: Context) {
override fun onAuthenticated(account: OAuthAccount, authType: AuthType) {
Log.d(LOGTAG, "The user has been successfully logged in")

if (authType !== AuthType.Existing) {
GleanMetricsService.FxA.signInResult(true)
}

accountStatus = AccountStatus.SIGNED_IN

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

GleanMetricsService.FxA.signInResult(false)

accountStatus = AccountStatus.NEEDS_RECONNECT
accountListeners.toMutableList().forEach {
Handler(Looper.getMainLooper()).post {
Expand Down Expand Up @@ -272,6 +279,7 @@ class Accounts constructor(val context: Context) {
}

fun authUrlAsync(): CompletableFuture<String?>? {
GleanMetricsService.FxA.signIn()
return CoroutineScope(Dispatchers.Main).future {
services.accountManager.beginAuthenticationAsync().await()
}
Expand Down Expand Up @@ -303,10 +311,15 @@ class Accounts constructor(val context: Context) {
}

fun setSyncStatus(engine: SyncEngine, value: Boolean) {

when(engine) {
SyncEngine.Bookmarks -> SettingsStore.getInstance(context).isBookmarksSyncEnabled = value
SyncEngine.History -> SettingsStore.getInstance(context).isHistorySyncEnabled = value
SyncEngine.Bookmarks -> {
GleanMetricsService.FxA.bookmarksSyncStatus(value)
SettingsStore.getInstance(context).isBookmarksSyncEnabled = value
}
SyncEngine.History -> {
GleanMetricsService.FxA.historySyncStatus(value)
SettingsStore.getInstance(context).isHistorySyncEnabled = value
}
}

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

fun logoutAsync(): CompletableFuture<Unit?> {
fun logoutAsync(): CompletableFuture<Unit?>? {
GleanMetricsService.FxA.signOut()

otherDevices = emptyList()
return CoroutineScope(Dispatchers.Main).future {
services.accountManager.logoutAsync().await()
Expand Down Expand Up @@ -351,10 +366,10 @@ class Accounts constructor(val context: Context) {
targetDevices.contains(it)
}

targets?.forEach {
targets?.forEach { it ->
constellation.sendEventToDeviceAsync(
it.id, DeviceEventOutgoing.SendTab(title, url)
).await()
).await().also { if (it) GleanMetricsService.FxA.sentTab() }
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import org.mozilla.vrbrowser.browser.engine.EngineProvider
import org.mozilla.vrbrowser.browser.engine.GeckoViewFetchClient
import org.mozilla.vrbrowser.browser.engine.SessionStore
import org.mozilla.vrbrowser.utils.SystemUtils
import org.mozilla.vrbrowser.telemetry.GleanMetricsService


class Services(val context: Context, places: Places): GeckoSession.NavigationDelegate {
Expand Down Expand Up @@ -85,7 +86,10 @@ class Services(val context: Context, places: Places): GeckoSession.NavigationDel
Logger(logTag).info("Received ${events.size} device event(s)")
val filteredEvents = events.filterIsInstance(DeviceEvent.TabReceived::class.java)
if (filteredEvents.isNotEmpty()) {
val tabs = filteredEvents.map { event -> event.entries }.flatten()
filteredEvents.map { event -> event.from?.deviceType?.let { GleanMetricsService.FxA.receivedTab(it) } }
val tabs = filteredEvents.map {
event -> event.entries
}.flatten()
tabReceivedDelegate?.onTabsReceived(tabs)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,25 @@
import android.content.Context;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.annotation.UiThread;

import org.mozilla.vrbrowser.BuildConfig;
import org.mozilla.vrbrowser.GleanMetrics.Distribution;
import org.mozilla.vrbrowser.GleanMetrics.FirefoxAccount;
import org.mozilla.vrbrowser.GleanMetrics.Pings;
import org.mozilla.vrbrowser.GleanMetrics.Searches;
import org.mozilla.vrbrowser.GleanMetrics.Url;
import org.mozilla.vrbrowser.browser.SettingsStore;
import org.mozilla.vrbrowser.search.SearchEngineWrapper;
import org.mozilla.vrbrowser.utils.DeviceType;
import org.mozilla.vrbrowser.utils.SystemUtils;
import org.mozilla.vrbrowser.BuildConfig;
import org.mozilla.vrbrowser.GleanMetrics.Distribution;
import org.mozilla.vrbrowser.utils.UrlUtils;

import java.net.URI;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;

import mozilla.components.service.glean.Glean;
import mozilla.components.service.glean.config.Configuration;
Expand Down Expand Up @@ -149,4 +153,59 @@ private static String getDefaultSearchEngineIdentifierForTelemetry() {
private static void setStartupMetrics() {
Distribution.INSTANCE.getChannelName().set(DeviceType.isOculusBuild() ? "oculusvr" : BuildConfig.FLAVOR_platform);
}

public static class FxA {

public static void signIn() {
FirefoxAccount.INSTANCE.getSignIn().record();
}

public static void signInResult(boolean status) {
Map<FirefoxAccount.signInResultKeys, String> map = new HashMap<>();
map.put(FirefoxAccount.signInResultKeys.state, String.valueOf(status));
FirefoxAccount.INSTANCE.getSignInResult().record(map);
}

public static void signOut() {
FirefoxAccount.INSTANCE.getSignOut().record();
}

public static void bookmarksSyncStatus(boolean status) {
FirefoxAccount.INSTANCE.getBookmarksSyncStatus().set(status);
}

public static void historySyncStatus(boolean status) {
FirefoxAccount.INSTANCE.getHistorySyncStatus().set(status);
}

public static void sentTab() {
FirefoxAccount.INSTANCE.getTabSent().add();
}

public static void receivedTab(@NonNull mozilla.components.concept.sync.DeviceType source) {
FirefoxAccount.INSTANCE.getReceivedTab().get(source.name()).add();
}
}

public static class Tabs {

public enum TabSource {
CONTEXT_MENU, // Tab opened from the browsers long click context menu
TABS_DIALOG, // Tab opened from the tabs dialog
BOOKMARKS, // Tab opened from the bookmarks panel
HISTORY, // Tab opened from the history panel
FXA_LOGIN, // Tab opened by the FxA login flow
RECEIVED, // Tab opened by FxA when a tab is received
PRE_EXISTING, // Tab opened as a result of restoring the last session
BROWSER // Tab opened by the browser as a result of a new window open
}

public static void openedCounter(@NonNull TabSource source) {
org.mozilla.vrbrowser.GleanMetrics.Tabs.INSTANCE.getOpened().get(source.name()).add();
}

public static void activatedEvent() {
org.mozilla.vrbrowser.GleanMetrics.Tabs.INSTANCE.getActivated().add();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.mozilla.vrbrowser.browser.engine.Session;
import org.mozilla.vrbrowser.browser.engine.SessionStore;
import org.mozilla.vrbrowser.databinding.BookmarksBinding;
import org.mozilla.vrbrowser.telemetry.GleanMetricsService;
import org.mozilla.vrbrowser.ui.adapters.Bookmark;
import org.mozilla.vrbrowser.ui.adapters.BookmarkAdapter;
import org.mozilla.vrbrowser.ui.adapters.CustomLinearLayoutManager;
Expand Down Expand Up @@ -230,6 +231,7 @@ public void onFxALogin(@NonNull View view) {
WidgetManagerDelegate widgetManager = ((VRBrowserActivity) getContext());
widgetManager.openNewTabForeground(url);
widgetManager.getFocusedWindow().getSession().setUaMode(GeckoSessionSettings.USER_AGENT_MODE_MOBILE);
GleanMetricsService.Tabs.openedCounter(GleanMetricsService.Tabs.TabSource.FXA_LOGIN);

mBookmarksViewListeners.forEach((listener) -> listener.onFxALogin(view));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.mozilla.vrbrowser.browser.engine.Session;
import org.mozilla.vrbrowser.browser.engine.SessionStore;
import org.mozilla.vrbrowser.databinding.HistoryBinding;
import org.mozilla.vrbrowser.telemetry.GleanMetricsService;
import org.mozilla.vrbrowser.ui.adapters.HistoryAdapter;
import org.mozilla.vrbrowser.ui.callbacks.HistoryCallback;
import org.mozilla.vrbrowser.ui.callbacks.HistoryItemCallback;
Expand Down Expand Up @@ -225,6 +226,7 @@ public void onFxALogin(@NonNull View view) {
WidgetManagerDelegate widgetManager = ((VRBrowserActivity) getContext());
widgetManager.openNewTabForeground(url);
widgetManager.getFocusedWindow().getSession().setUaMode(GeckoSessionSettings.USER_AGENT_MODE_MOBILE);
GleanMetricsService.Tabs.openedCounter(GleanMetricsService.Tabs.TabSource.FXA_LOGIN);

mHistoryViewListeners.forEach((listener) -> listener.onFxALogin(view));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1122,6 +1122,8 @@ public void onStackSession(Session aSession) {
SessionStore.get().setActiveSession(aSession);
current.captureBackgroundBitmap(getWindowWidth(), getWindowHeight()).thenAccept(aVoid -> current.setActive(false));
mWidgetManager.getTray().showTabAddedNotification();

GleanMetricsService.Tabs.openedCounter(GleanMetricsService.Tabs.TabSource.BROWSER);
}

@Override
Expand Down Expand Up @@ -1379,6 +1381,11 @@ public void onOpenInNewWindowClick(LibraryMenuWidget.LibraryContextMenuItem item
@Override
public void onOpenInNewTabClick(LibraryMenuWidget.LibraryContextMenuItem item) {
mWidgetManager.openNewTabForeground(item.getUrl());
if (item.getType() == LibraryMenuWidget.LibraryItemType.HISTORY) {
GleanMetricsService.Tabs.openedCounter(GleanMetricsService.Tabs.TabSource.HISTORY);
} else if (item.getType() == LibraryMenuWidget.LibraryItemType.BOOKMARKS) {
GleanMetricsService.Tabs.openedCounter(GleanMetricsService.Tabs.TabSource.BOOKMARKS);
}
hideContextMenus();
}

Expand Down
Loading

0 comments on commit 143a88a

Please sign in to comment.