Commit 41522c8a authored by Tanmoy Mollik's avatar Tanmoy Mollik Committed by Chromium LUCI CQ

[Android] Add histograms for showing rate of AccountPickerBottomSheet

This cl adds two histograms for the AccountPickerBottomSheet
Signin.AccountConsistencyPromoAction.Shown.Count - logged every
time the bottom sheet is shown to the user. Records number of times
bottom sheet was shown previously.
Signin.AccountConsistencyPromoAction.SignedIn.Count - logged when
the user signs in using the bottom sheet. Records number of times bottom
sheet was shown previously.

A new shared preference is also introduced to keep track of how many
times the bottom sheet is shown.

Bug: 1153093
Change-Id: I6a0bcc37dddfc107cbc89516ad5d6161c781faba
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2574849Reviewed-by: default avatarEgor Pasko <pasko@chromium.org>
Reviewed-by: default avatarAlice Wang <aliceywang@chromium.org>
Reviewed-by: default avatarAlex Ilin <alexilin@chromium.org>
Commit-Queue: Tanmoy Mollik <triploblastic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#838014}
parent b12f642c
...@@ -238,7 +238,7 @@ public class RecordHistogram { ...@@ -238,7 +238,7 @@ public class RecordHistogram {
* @param sample sample to be recorded, expected to fall in range {@code [0, max)} * @param sample sample to be recorded, expected to fall in range {@code [0, max)}
* @param max the smallest value counted in the overflow bucket, shouldn't be larger than 100 * @param max the smallest value counted in the overflow bucket, shouldn't be larger than 100
*/ */
private static void recordExactLinearHistogram(String name, int sample, int max) { public static void recordExactLinearHistogram(String name, int sample, int max) {
// Range [0, 1) is counted in the underflow bucket. The first "real" bucket starts at 1. // Range [0, 1) is counted in the underflow bucket. The first "real" bucket starts at 1.
final int min = 1; final int min = 1;
// One extra is added for the overflow bucket. // One extra is added for the overflow bucket.
......
...@@ -14,6 +14,7 @@ import org.chromium.chrome.browser.feedback.HelpAndFeedbackLauncher; ...@@ -14,6 +14,7 @@ import org.chromium.chrome.browser.feedback.HelpAndFeedbackLauncher;
import org.chromium.chrome.browser.incognito.interstitial.IncognitoInterstitialCoordinator; import org.chromium.chrome.browser.incognito.interstitial.IncognitoInterstitialCoordinator;
import org.chromium.chrome.browser.incognito.interstitial.IncognitoInterstitialDelegate; import org.chromium.chrome.browser.incognito.interstitial.IncognitoInterstitialDelegate;
import org.chromium.chrome.browser.signin.services.SigninMetricsUtils; import org.chromium.chrome.browser.signin.services.SigninMetricsUtils;
import org.chromium.chrome.browser.signin.services.SigninPreferencesManager;
import org.chromium.chrome.browser.signin.ui.account_picker.AccountPickerDelegate; import org.chromium.chrome.browser.signin.ui.account_picker.AccountPickerDelegate;
import org.chromium.chrome.browser.tabmodel.TabCreator; import org.chromium.chrome.browser.tabmodel.TabCreator;
import org.chromium.chrome.browser.tabmodel.TabModel; import org.chromium.chrome.browser.tabmodel.TabModel;
...@@ -81,7 +82,10 @@ public class AccountPickerBottomSheetCoordinator { ...@@ -81,7 +82,10 @@ public class AccountPickerBottomSheetCoordinator {
BottomSheetController bottomSheetController, BottomSheetController bottomSheetController,
AccountPickerDelegate accountPickerDelegate, AccountPickerDelegate accountPickerDelegate,
IncognitoInterstitialDelegate incognitoInterstitialDelegate) { IncognitoInterstitialDelegate incognitoInterstitialDelegate) {
SigninPreferencesManager.getInstance().incrementAccountPickerBottomSheetShownCount();
SigninMetricsUtils.logAccountConsistencyPromoAction(AccountConsistencyPromoAction.SHOWN); SigninMetricsUtils.logAccountConsistencyPromoAction(AccountConsistencyPromoAction.SHOWN);
SigninMetricsUtils.logAccountConsistencyPromoShownCount(
"Signin.AccountConsistencyPromoAction.Shown.Count");
mAccountPickerBottomSheetMediator = new AccountPickerBottomSheetMediator( mAccountPickerBottomSheetMediator = new AccountPickerBottomSheetMediator(
activity, accountPickerDelegate, this::dismissBottomSheet); activity, accountPickerDelegate, this::dismissBottomSheet);
......
...@@ -222,6 +222,8 @@ class AccountPickerBottomSheetMediator implements AccountPickerCoordinator.Liste ...@@ -222,6 +222,8 @@ class AccountPickerBottomSheetMediator implements AccountPickerCoordinator.Liste
private void signIn() { private void signIn() {
mModel.set(AccountPickerBottomSheetProperties.VIEW_STATE, ViewState.SIGNIN_IN_PROGRESS); mModel.set(AccountPickerBottomSheetProperties.VIEW_STATE, ViewState.SIGNIN_IN_PROGRESS);
SigninMetricsUtils.logAccountConsistencyPromoShownCount(
"Signin.AccountConsistencyPromoAction.SignedIn.Count");
if (TextUtils.equals(mSelectedAccountName, mAddedAccountName)) { if (TextUtils.equals(mSelectedAccountName, mAddedAccountName)) {
SigninMetricsUtils.logAccountConsistencyPromoAction( SigninMetricsUtils.logAccountConsistencyPromoAction(
AccountConsistencyPromoAction.SIGNED_IN_WITH_ADDED_ACCOUNT); AccountConsistencyPromoAction.SIGNED_IN_WITH_ADDED_ACCOUNT);
......
...@@ -33,6 +33,7 @@ import androidx.test.espresso.ViewInteraction; ...@@ -33,6 +33,7 @@ import androidx.test.espresso.ViewInteraction;
import androidx.test.filters.MediumTest; import androidx.test.filters.MediumTest;
import org.hamcrest.Matcher; import org.hamcrest.Matcher;
import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.ClassRule; import org.junit.ClassRule;
...@@ -54,6 +55,8 @@ import org.chromium.chrome.browser.feedback.HelpAndFeedbackLauncher; ...@@ -54,6 +55,8 @@ import org.chromium.chrome.browser.feedback.HelpAndFeedbackLauncher;
import org.chromium.chrome.browser.flags.ChromeFeatureList; import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.flags.ChromeSwitches; import org.chromium.chrome.browser.flags.ChromeSwitches;
import org.chromium.chrome.browser.incognito.interstitial.IncognitoInterstitialDelegate; import org.chromium.chrome.browser.incognito.interstitial.IncognitoInterstitialDelegate;
import org.chromium.chrome.browser.preferences.ChromePreferenceKeys;
import org.chromium.chrome.browser.preferences.SharedPreferencesManager;
import org.chromium.chrome.browser.signin.account_picker.AccountPickerBottomSheetCoordinator; import org.chromium.chrome.browser.signin.account_picker.AccountPickerBottomSheetCoordinator;
import org.chromium.chrome.browser.signin.ui.account_picker.AccountPickerDelegate; import org.chromium.chrome.browser.signin.ui.account_picker.AccountPickerDelegate;
import org.chromium.chrome.browser.tabmodel.TabCreator; import org.chromium.chrome.browser.tabmodel.TabCreator;
...@@ -98,6 +101,8 @@ public class AccountPickerBottomSheetTest { ...@@ -98,6 +101,8 @@ public class AccountPickerBottomSheetTest {
/* accountName= */ "test.account2@gmail.com", /* avatar= */ null, /* accountName= */ "test.account2@gmail.com", /* avatar= */ null,
/* fullName= */ null, /* givenName= */ null); /* fullName= */ null, /* givenName= */ null);
private final int mShowCount = 1;
// Disable animations to reduce flakiness. // Disable animations to reduce flakiness.
@ClassRule @ClassRule
public static final DisableAnimationsTestRule sNoAnimationsRule = public static final DisableAnimationsTestRule sNoAnimationsRule =
...@@ -144,6 +149,14 @@ public class AccountPickerBottomSheetTest { ...@@ -144,6 +149,14 @@ public class AccountPickerBottomSheetTest {
when(mAccountPickerDelegateMock.isIncognitoModeEnabled()).thenReturn(true); when(mAccountPickerDelegateMock.isIncognitoModeEnabled()).thenReturn(true);
mAccountManagerTestRule.addAccount(PROFILE_DATA1); mAccountManagerTestRule.addAccount(PROFILE_DATA1);
mAccountManagerTestRule.addAccount(PROFILE_DATA2); mAccountManagerTestRule.addAccount(PROFILE_DATA2);
SharedPreferencesManager.getInstance().removeKey(
ChromePreferenceKeys.ACCOUNT_PICKER_BOTTOM_SHEET_SHOWN_COUNT);
}
@After
public void tearDown() {
SharedPreferencesManager.getInstance().removeKey(
ChromePreferenceKeys.ACCOUNT_PICKER_BOTTOM_SHEET_SHOWN_COUNT);
} }
@Test @Test
...@@ -151,9 +164,25 @@ public class AccountPickerBottomSheetTest { ...@@ -151,9 +164,25 @@ public class AccountPickerBottomSheetTest {
public void testCollapsedSheetWithAccount() { public void testCollapsedSheetWithAccount() {
MetricsUtils.HistogramDelta accountConsistencyHistogram = new HistogramDelta( MetricsUtils.HistogramDelta accountConsistencyHistogram = new HistogramDelta(
"Signin.AccountConsistencyPromoAction", AccountConsistencyPromoAction.SHOWN); "Signin.AccountConsistencyPromoAction", AccountConsistencyPromoAction.SHOWN);
MetricsUtils.HistogramDelta shownCountHistogram =
new HistogramDelta("Signin.AccountConsistencyPromoAction.Shown.Count", mShowCount);
buildAndShowCollapsedBottomSheet(); buildAndShowCollapsedBottomSheet();
checkCollapsedAccountList(PROFILE_DATA1); checkCollapsedAccountList(PROFILE_DATA1);
Assert.assertEquals(1, accountConsistencyHistogram.getDelta()); Assert.assertEquals(1, accountConsistencyHistogram.getDelta());
Assert.assertEquals(1, shownCountHistogram.getDelta());
}
@Test
@MediumTest
public void testPromoShownHistogramMaxCount() {
final int max = 100;
SharedPreferencesManager.getInstance().writeInt(
ChromePreferenceKeys.ACCOUNT_PICKER_BOTTOM_SHEET_SHOWN_COUNT, max + 5);
MetricsUtils.HistogramDelta shownCountHistogram =
new HistogramDelta("Signin.AccountConsistencyPromoAction.Shown.Count", max);
buildAndShowCollapsedBottomSheet();
checkCollapsedAccountList(PROFILE_DATA1);
Assert.assertEquals(1, shownCountHistogram.getDelta());
} }
@Test @Test
...@@ -352,9 +381,12 @@ public class AccountPickerBottomSheetTest { ...@@ -352,9 +381,12 @@ public class AccountPickerBottomSheetTest {
MetricsUtils.HistogramDelta accountConsistencyHistogram = MetricsUtils.HistogramDelta accountConsistencyHistogram =
new HistogramDelta("Signin.AccountConsistencyPromoAction", new HistogramDelta("Signin.AccountConsistencyPromoAction",
AccountConsistencyPromoAction.SIGNED_IN_WITH_DEFAULT_ACCOUNT); AccountConsistencyPromoAction.SIGNED_IN_WITH_DEFAULT_ACCOUNT);
MetricsUtils.HistogramDelta signedInCountHistogram = new HistogramDelta(
"Signin.AccountConsistencyPromoAction.SignedIn.Count", mShowCount);
buildAndShowCollapsedBottomSheet(); buildAndShowCollapsedBottomSheet();
clickContinueButtonAndCheckSignInInProgressSheet(); clickContinueButtonAndCheckSignInInProgressSheet();
Assert.assertEquals(1, accountConsistencyHistogram.getDelta()); Assert.assertEquals(1, accountConsistencyHistogram.getDelta());
Assert.assertEquals(1, signedInCountHistogram.getDelta());
} }
@Test @Test
...@@ -363,12 +395,15 @@ public class AccountPickerBottomSheetTest { ...@@ -363,12 +395,15 @@ public class AccountPickerBottomSheetTest {
MetricsUtils.HistogramDelta accountConsistencyHistogram = MetricsUtils.HistogramDelta accountConsistencyHistogram =
new HistogramDelta("Signin.AccountConsistencyPromoAction", new HistogramDelta("Signin.AccountConsistencyPromoAction",
AccountConsistencyPromoAction.SIGNED_IN_WITH_NON_DEFAULT_ACCOUNT); AccountConsistencyPromoAction.SIGNED_IN_WITH_NON_DEFAULT_ACCOUNT);
MetricsUtils.HistogramDelta signedInCountHistogram = new HistogramDelta(
"Signin.AccountConsistencyPromoAction.SignedIn.Count", mShowCount);
buildAndShowExpandedBottomSheet(); buildAndShowExpandedBottomSheet();
onView(withText(PROFILE_DATA2.getAccountEmail())).perform(click()); onView(withText(PROFILE_DATA2.getAccountEmail())).perform(click());
CriteriaHelper.pollUiThread(mCoordinator.getBottomSheetViewForTesting().findViewById( CriteriaHelper.pollUiThread(mCoordinator.getBottomSheetViewForTesting().findViewById(
R.id.account_picker_selected_account)::isShown); R.id.account_picker_selected_account)::isShown);
clickContinueButtonAndCheckSignInInProgressSheet(); clickContinueButtonAndCheckSignInInProgressSheet();
Assert.assertEquals(1, accountConsistencyHistogram.getDelta()); Assert.assertEquals(1, accountConsistencyHistogram.getDelta());
Assert.assertEquals(1, signedInCountHistogram.getDelta());
} }
@Test @Test
...@@ -383,6 +418,8 @@ public class AccountPickerBottomSheetTest { ...@@ -383,6 +418,8 @@ public class AccountPickerBottomSheetTest {
MetricsUtils.HistogramDelta signedInWithNonDefaultAccountHistogram = MetricsUtils.HistogramDelta signedInWithNonDefaultAccountHistogram =
new HistogramDelta("Signin.AccountConsistencyPromoAction", new HistogramDelta("Signin.AccountConsistencyPromoAction",
AccountConsistencyPromoAction.SIGNED_IN_WITH_NON_DEFAULT_ACCOUNT); AccountConsistencyPromoAction.SIGNED_IN_WITH_NON_DEFAULT_ACCOUNT);
MetricsUtils.HistogramDelta signedInCountHistogram = new HistogramDelta(
"Signin.AccountConsistencyPromoAction.SignedIn.Count", mShowCount);
buildAndShowExpandedBottomSheet(); buildAndShowExpandedBottomSheet();
onVisibleView(withText(R.string.signin_add_account_to_device)).perform(click()); onVisibleView(withText(R.string.signin_add_account_to_device)).perform(click());
verify(mAccountPickerDelegateMock).addAccount(callbackArgumentCaptor.capture()); verify(mAccountPickerDelegateMock).addAccount(callbackArgumentCaptor.capture());
...@@ -396,6 +433,7 @@ public class AccountPickerBottomSheetTest { ...@@ -396,6 +433,7 @@ public class AccountPickerBottomSheetTest {
Assert.assertEquals(1, addAccountHistogram.getDelta()); Assert.assertEquals(1, addAccountHistogram.getDelta());
Assert.assertEquals(1, signedInWithAddedAccountHistogram.getDelta()); Assert.assertEquals(1, signedInWithAddedAccountHistogram.getDelta());
Assert.assertEquals(0, signedInWithNonDefaultAccountHistogram.getDelta()); Assert.assertEquals(0, signedInWithNonDefaultAccountHistogram.getDelta());
Assert.assertEquals(1, signedInCountHistogram.getDelta());
} }
@Test @Test
......
...@@ -49,6 +49,9 @@ public final class ChromePreferenceKeys { ...@@ -49,6 +49,9 @@ public final class ChromePreferenceKeys {
*/ */
public static final String ACCESSIBILITY_TAB_SWITCHER = "accessibility_tab_switcher"; public static final String ACCESSIBILITY_TAB_SWITCHER = "accessibility_tab_switcher";
public static final String ACCOUNT_PICKER_BOTTOM_SHEET_SHOWN_COUNT =
"Chrome.AccountPickerBottomSheet.ShownCount";
/** The language code to override application language with. */ /** The language code to override application language with. */
public static final String APPLICATION_OVERRIDE_LANGUAGE = public static final String APPLICATION_OVERRIDE_LANGUAGE =
"Chrome.Language.ApplicationOverrideLanguage"; "Chrome.Language.ApplicationOverrideLanguage";
...@@ -813,6 +816,7 @@ public final class ChromePreferenceKeys { ...@@ -813,6 +816,7 @@ public final class ChromePreferenceKeys {
static List<String> getKeysInUse() { static List<String> getKeysInUse() {
// clang-format off // clang-format off
return Arrays.asList( return Arrays.asList(
ACCOUNT_PICKER_BOTTOM_SHEET_SHOWN_COUNT,
ASSISTANT_LAST_VERSION, ASSISTANT_LAST_VERSION,
ASSISTANT_VOICE_SEARCH_ENABLED, ASSISTANT_VOICE_SEARCH_ENABLED,
ASSISTANT_VOICE_SEARCH_SUPPORTED, ASSISTANT_VOICE_SEARCH_SUPPORTED,
......
...@@ -33,6 +33,15 @@ public class SigninMetricsUtils { ...@@ -33,6 +33,15 @@ public class SigninMetricsUtils {
promoAction, AccountConsistencyPromoAction.MAX); promoAction, AccountConsistencyPromoAction.MAX);
} }
/**
* Logs AccountPickerBottomSheet shown count histograms.
*/
public static void logAccountConsistencyPromoShownCount(String histogram) {
RecordHistogram.recordExactLinearHistogram(histogram,
SigninPreferencesManager.getInstance().getAccountPickerBottomSheetShownCount(),
100);
}
@VisibleForTesting @VisibleForTesting
@NativeMethods @NativeMethods
public interface Natives { public interface Natives {
......
...@@ -188,4 +188,18 @@ public class SigninPreferencesManager { ...@@ -188,4 +188,18 @@ public class SigninPreferencesManager {
public String getLegacySyncAccountEmail() { public String getLegacySyncAccountEmail() {
return mManager.readString(ChromePreferenceKeys.SIGNIN_LEGACY_SYNC_ACCOUNT_EMAIL, null); return mManager.readString(ChromePreferenceKeys.SIGNIN_LEGACY_SYNC_ACCOUNT_EMAIL, null);
} }
/**
* Increments the shown count for the account picker bottom sheet.
*/
public void incrementAccountPickerBottomSheetShownCount() {
mManager.incrementInt(ChromePreferenceKeys.ACCOUNT_PICKER_BOTTOM_SHEET_SHOWN_COUNT);
}
/**
* Returns the number of times account picker bottom sheet has already been shown.
*/
public int getAccountPickerBottomSheetShownCount() {
return mManager.readInt(ChromePreferenceKeys.ACCOUNT_PICKER_BOTTOM_SHEET_SHOWN_COUNT);
}
} }
...@@ -40,6 +40,27 @@ reviews. Googlers can read more about this at go/gwsq-gerrit. ...@@ -40,6 +40,27 @@ reviews. Googlers can read more about this at go/gwsq-gerrit.
</summary> </summary>
</histogram> </histogram>
<histogram name="Signin.AccountConsistencyPromoAction.Shown.Count"
units="counts" expires_after="2021-08-31">
<owner>aliceywang@chromium.org</owner>
<owner>triploblastic@chromium.org</owner>
<summary>
Every time the account picker bottom sheet is shown as part of the web
sign-in flow this histogram records the number of times bottom sheet was
shown (Android only).
</summary>
</histogram>
<histogram name="Signin.AccountConsistencyPromoAction.SignedIn.Count"
units="counts" expires_after="2021-08-31">
<owner>aliceywang@chromium.org</owner>
<owner>triploblastic@chromium.org</owner>
<summary>
This histogram records the number of times the account picker bottom sheet
was shown before the user signed-in through the bottom sheet (Android only).
</summary>
</histogram>
<histogram name="Signin.AccountEquality" enum="SigninAccountEquality" <histogram name="Signin.AccountEquality" enum="SigninAccountEquality"
expires_after="2021-03-06"> expires_after="2021-03-06">
<owner>droger@chromium.org</owner> <owner>droger@chromium.org</owner>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment