Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "day zero" experiment daily retention P3A metric to 1.64.x #22920

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion android/java/org/chromium/base/BraveFeatureList.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ public abstract class BraveFeatureList {
public static final String AI_CHAT = "AIChat";
public static final String BRAVE_SHOW_STRICT_FINGERPRINTING_MODE =
"BraveShowStrictFingerprintingMode";
public static final String BRAVE_ZERO_DAY_FLAG_ANDROID = "BraveZeroDayFlagAndroid";
public static final String BRAVE_DAY_ZERO_EXPERIMENT = "BraveDayZeroExperiment";
public static final String BRAVE_FALLBACK_DOH_PROVIDER = "BraveFallbackDoHProvider";
}
10 changes: 0 additions & 10 deletions browser/about_flags.cc
Original file line number Diff line number Diff line change
Expand Up @@ -362,18 +362,9 @@
kOsAndroid, \
FEATURE_VALUE_TYPE(safe_browsing::features::kBraveAndroidSafeBrowsing), \
})
#define BRAVE_ZERO_DAY_FLAG_ANDROID \
EXPAND_FEATURE_ENTRIES({ \
"brave-zero-day-flag-android", \
"ZeroDayFlag flag for product test", \
"This flag will be set through griffin to perform product testing", \
kOsAndroid, \
FEATURE_VALUE_TYPE(preferences::features::kBraveZeroDayFlagAndroid), \
})
#else
#define BRAVE_BACKGROUND_VIDEO_PLAYBACK_ANDROID
#define BRAVE_SAFE_BROWSING_ANDROID
#define BRAVE_ZERO_DAY_FLAG_ANDROID
#endif // BUILDFLAG(IS_ANDROID)

#if !BUILDFLAG(IS_ANDROID)
Expand Down Expand Up @@ -975,7 +966,6 @@
BRAVE_COMMANDS_FEATURE_ENTRIES \
BRAVE_BACKGROUND_VIDEO_PLAYBACK_ANDROID \
BRAVE_SAFE_BROWSING_ANDROID \
BRAVE_ZERO_DAY_FLAG_ANDROID \
BRAVE_CHANGE_ACTIVE_TAB_ON_SCROLL_EVENT_FEATURE_ENTRIES \
BRAVE_TABS_FEATURE_ENTRIES \
BRAVE_AI_CHAT \
Expand Down
4 changes: 0 additions & 4 deletions browser/android/preferences/features.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,5 @@ BASE_FEATURE(kBraveBackgroundVideoPlayback,
"BraveBackgroundVideoPlayback",
base::FEATURE_DISABLED_BY_DEFAULT);

BASE_FEATURE(kBraveZeroDayFlagAndroid,
"BraveZeroDayFlagAndroid",
base::FEATURE_DISABLED_BY_DEFAULT);

} // namespace features
} // namespace preferences
1 change: 0 additions & 1 deletion browser/android/preferences/features.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ namespace preferences {
namespace features {

BASE_DECLARE_FEATURE(kBraveBackgroundVideoPlayback);
BASE_DECLARE_FEATURE(kBraveZeroDayFlagAndroid);

} // namespace features
} // namespace preferences
Expand Down
13 changes: 13 additions & 0 deletions browser/brave_browser_features.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* You can obtain one at https://mozilla.org/MPL/2.0/. */

#include "brave/browser/brave_browser_features.h"

#include "build/build_config.h"

namespace features {
Expand Down Expand Up @@ -35,4 +36,16 @@ BASE_FEATURE(kBraveWebViewRoundedCorners,
"brave-web-view-rounded-corners",
base::FEATURE_DISABLED_BY_DEFAULT);

// Enable "day zero" experiment modifications, for potential user
// retention improvements.
BASE_FEATURE(kBraveDayZeroExperiment,
"BraveDayZeroExperiment",
base::FEATURE_DISABLED_BY_DEFAULT);

// The variant of the "day zero" experiment. i.e. A, B, C, D, etc.
const base::FeatureParam<std::string> kBraveDayZeroExperimentVariant{
&kBraveDayZeroExperiment,
/*name=*/"variant",
/*default_value=*/""};

} // namespace features
7 changes: 6 additions & 1 deletion browser/brave_browser_features.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,20 @@
#ifndef BRAVE_BROWSER_BRAVE_BROWSER_FEATURES_H_
#define BRAVE_BROWSER_BRAVE_BROWSER_FEATURES_H_

#include <string>

#include "base/feature_list.h"
#include "base/metrics/field_trial_params.h"

namespace features {

BASE_DECLARE_FEATURE(kBraveCleanupSessionCookiesOnSessionRestore);
BASE_DECLARE_FEATURE(kBraveCopyCleanLinkByDefault);
BASE_DECLARE_FEATURE(kBraveOverrideDownloadDangerLevel);
BASE_DECLARE_FEATURE(kBraveWebViewRoundedCorners);
BASE_DECLARE_FEATURE(kBraveZeroDayFlagAndroid);

BASE_DECLARE_FEATURE(kBraveDayZeroExperiment);
extern const base::FeatureParam<std::string> kBraveDayZeroExperimentVariant;

} // namespace features

Expand Down
11 changes: 10 additions & 1 deletion browser/brave_stats/brave_stats_updater.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
#include "base/command_line.h"
#include "base/metrics/histogram_macros.h"
#include "base/system/sys_info.h"
#include "brave/browser/brave_browser_features.h"
#include "brave/browser/brave_stats/brave_stats_updater_params.h"
#include "brave/browser/brave_stats/buildflags.h"
#include "brave/browser/brave_stats/first_run_util.h"
#include "brave/browser/brave_stats/switches.h"
#include "brave/common/brave_channel_info.h"
#include "brave/components/brave_ads/core/public/prefs/pref_names.h"
Expand All @@ -26,6 +28,7 @@
#include "brave/components/rpill/common/rpill.h"
#include "brave/components/version_info/version_info.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/first_run/first_run.h"
#include "chrome/browser/net/system_network_context_manager.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/common/channel_info.h"
Expand Down Expand Up @@ -106,8 +109,14 @@ BraveStatsUpdater::BraveStatsUpdater(PrefService* pref_service,
usage_server_ = BUILDFLAG(BRAVE_USAGE_SERVER);
}

std::optional<std::string> day_zero_variant;
if (base::FeatureList::IsEnabled(features::kBraveDayZeroExperiment)) {
day_zero_variant = features::kBraveDayZeroExperimentVariant.Get();
}
general_browser_usage_p3a_ =
std::make_unique<misc_metrics::GeneralBrowserUsage>(pref_service);
std::make_unique<misc_metrics::GeneralBrowserUsage>(
pref_service, day_zero_variant, first_run::IsChromeFirstRun(),
GetFirstRunTime(pref_service));

if (profile_manager != nullptr) {
g_browser_process->profile_manager()->AddObserver(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
&brave_wallet::features::kNativeBraveWalletFeature, \
&playlist::features::kPlaylist, \
&preferences::features::kBraveBackgroundVideoPlayback, \
&preferences::features::kBraveZeroDayFlagAndroid, \
&request_otr::features::kBraveRequestOTRTab, \
&safe_browsing::features::kBraveAndroidSafeBrowsing, \
&speedreader::kSpeedreaderFeature, \
Expand Down
43 changes: 42 additions & 1 deletion components/misc_metrics/general_browser_usage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
#include "brave/components/misc_metrics/general_browser_usage.h"

#include "base/metrics/histogram_macros.h"
#include "base/strings/strcat.h"
#include "base/strings/string_util.h"
#include "base/time/time.h"
#include "brave/components/misc_metrics/pref_names.h"
#include "brave/components/p3a_utils/bucket.h"
#include "brave/components/time_period_storage/iso_weekly_storage.h"
Expand All @@ -24,16 +27,33 @@ constexpr int kProfileCountBuckets[] = {0, 1, 2, 3, 5};

} // namespace

GeneralBrowserUsage::GeneralBrowserUsage(PrefService* local_state) {
GeneralBrowserUsage::GeneralBrowserUsage(
PrefService* local_state,
std::optional<std::string> day_zero_experiment_variant,
bool is_first_run,
base::Time first_run_time)
: local_state_(local_state), first_run_time_(first_run_time) {
usage_storage_ = std::make_unique<ISOWeeklyStorage>(
local_state, kMiscMetricsBrowserUsageList);

if (is_first_run) {
if (day_zero_experiment_variant) {
local_state->SetString(kMiscMetricsDayZeroVariantAtInstall,
*day_zero_experiment_variant);
}
if (first_run_time.is_null()) {
first_run_time_ = base::Time::Now();
}
}

Update();
}

GeneralBrowserUsage::~GeneralBrowserUsage() = default;

void GeneralBrowserUsage::RegisterPrefs(PrefRegistrySimple* registry) {
registry->RegisterListPref(kMiscMetricsBrowserUsageList);
registry->RegisterStringPref(kMiscMetricsDayZeroVariantAtInstall, {});
}

void GeneralBrowserUsage::ReportWeeklyUse() {
Expand All @@ -42,6 +62,24 @@ void GeneralBrowserUsage::ReportWeeklyUse() {
usage_storage_->GetLastISOWeekSum(), 8);
}

#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_WIN)
void GeneralBrowserUsage::ReportInstallTime() {
int days_since_install = (base::Time::Now() - first_run_time_).InDays();
if (days_since_install < 0 || days_since_install > 30) {
return;
}
std::string day_zero_variant =
local_state_->GetString(kMiscMetricsDayZeroVariantAtInstall);
if (day_zero_variant.empty()) {
return;
}
std::string histogram_name = base::StrCat(
{kDayZeroInstallTimePrefix, base::ToUpperASCII(day_zero_variant),
kDayZeroInstallTimeSuffix});
base::UmaHistogramExactLinear(histogram_name, days_since_install, 31);
}
#endif // BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_WIN)

void GeneralBrowserUsage::ReportProfileCount(size_t count) {
#if !BUILDFLAG(IS_ANDROID)
p3a_utils::RecordToHistogramBucket(kProfileCountHistogramName,
Expand All @@ -56,6 +94,9 @@ void GeneralBrowserUsage::SetUpUpdateTimer() {

void GeneralBrowserUsage::Update() {
ReportWeeklyUse();
#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_WIN)
ReportInstallTime();
#endif // BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_WIN)

SetUpUpdateTimer();
}
Expand Down
18 changes: 17 additions & 1 deletion components/misc_metrics/general_browser_usage.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
#define BRAVE_COMPONENTS_MISC_METRICS_GENERAL_BROWSER_USAGE_H_

#include <memory>
#include <optional>
#include <string>

#include "base/memory/raw_ptr.h"
#include "base/timer/wall_clock_timer.h"

class PrefRegistrySimple;
Expand All @@ -19,9 +22,17 @@ namespace misc_metrics {
inline constexpr char kWeeklyUseHistogramName[] = "Brave.Core.WeeklyUsage";
inline constexpr char kProfileCountHistogramName[] = "Brave.Core.ProfileCount";

#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_WIN)
inline constexpr char kDayZeroInstallTimePrefix[] = "Brave.DayZero.";
inline constexpr char kDayZeroInstallTimeSuffix[] = ".InstallTime";
#endif // BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_WIN)

class GeneralBrowserUsage {
public:
explicit GeneralBrowserUsage(PrefService* local_state);
GeneralBrowserUsage(PrefService* local_state,
std::optional<std::string> day_zero_experiment_variant,
bool is_first_run,
base::Time first_run_time);
~GeneralBrowserUsage();

GeneralBrowserUsage(const GeneralBrowserUsage&) = delete;
Expand All @@ -33,11 +44,16 @@ class GeneralBrowserUsage {

private:
void ReportWeeklyUse();
#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_WIN)
void ReportInstallTime();
#endif // BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_WIN)

void SetUpUpdateTimer();

void Update();

raw_ptr<PrefService> local_state_;
base::Time first_run_time_;
std::unique_ptr<ISOWeeklyStorage> usage_storage_;

base::WallClockTimer report_timer_;
Expand Down
67 changes: 64 additions & 3 deletions components/misc_metrics/general_browser_usage_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* You can obtain one at https://mozilla.org/MPL/2.0/. */

#include <memory>
#include <optional>
#include <string>

#include "base/test/metrics/histogram_tester.h"
#include "base/time/time.h"
Expand All @@ -14,6 +16,11 @@

namespace misc_metrics {

#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_WIN)
constexpr char kDayZeroAInstallTime[] = "Brave.DayZero.A.InstallTime";
constexpr char kDayZeroBInstallTime[] = "Brave.DayZero.B.InstallTime";
#endif // BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_WIN)

class GeneralBrowserUsageUnitTest : public testing::Test {
public:
GeneralBrowserUsageUnitTest()
Expand All @@ -33,19 +40,25 @@ class GeneralBrowserUsageUnitTest : public testing::Test {
days_until_monday = 1;
}
task_environment_.AdvanceClock(base::Days(days_until_monday));

general_browser_usage_ =
std::make_unique<GeneralBrowserUsage>(&local_state_);
}

protected:
void SetUpUsage(std::optional<std::string> day_zero_variant,
bool is_first_run,
base::Time first_run_time) {
general_browser_usage_ = std::make_unique<GeneralBrowserUsage>(
&local_state_, day_zero_variant, is_first_run, first_run_time);
}

content::BrowserTaskEnvironment task_environment_;
TestingPrefServiceSimple local_state_;
base::HistogramTester histogram_tester_;
std::unique_ptr<GeneralBrowserUsage> general_browser_usage_;
};

TEST_F(GeneralBrowserUsageUnitTest, WeeklyUsage) {
SetUpUsage({}, true, base::Time::Now());

histogram_tester_.ExpectUniqueSample(kWeeklyUseHistogramName, 0, 1);

task_environment_.FastForwardBy(base::Days(1));
Expand All @@ -61,6 +74,8 @@ TEST_F(GeneralBrowserUsageUnitTest, WeeklyUsage) {

#if !BUILDFLAG(IS_ANDROID)
TEST_F(GeneralBrowserUsageUnitTest, ProfileCount) {
SetUpUsage({}, true, base::Time::Now());

histogram_tester_.ExpectTotalCount(kProfileCountHistogramName, 0);

general_browser_usage_->ReportProfileCount(1);
Expand All @@ -73,4 +88,50 @@ TEST_F(GeneralBrowserUsageUnitTest, ProfileCount) {
}
#endif // !BUILDFLAG(IS_ANDROID)

#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_WIN)
TEST_F(GeneralBrowserUsageUnitTest, InstallTimeB) {
base::Time install_time = base::Time::Now();
SetUpUsage("B", true, install_time);

histogram_tester_.ExpectUniqueSample(kDayZeroBInstallTime, 0, 1);

task_environment_.FastForwardBy(base::Days(15));

histogram_tester_.ExpectBucketCount(kDayZeroBInstallTime, 15, 1);
histogram_tester_.ExpectTotalCount(kDayZeroAInstallTime, 0);

SetUpUsage("A", false, install_time);
// Ensure histogram name does not change if "day zero" is enabled
// after install; we only want to report the "day zero on" metric
// if it was enabled at install time.
histogram_tester_.ExpectBucketCount(kDayZeroBInstallTime, 15, 2);
histogram_tester_.ExpectTotalCount(kDayZeroAInstallTime, 0);

task_environment_.FastForwardBy(base::Days(15));
histogram_tester_.ExpectBucketCount(kDayZeroBInstallTime, 30, 1);

// Ensure there are no more reports past 30 days
task_environment_.FastForwardBy(base::Days(5));

histogram_tester_.ExpectTotalCount(kDayZeroBInstallTime, 32);
histogram_tester_.ExpectTotalCount(kDayZeroAInstallTime, 0);
}

TEST_F(GeneralBrowserUsageUnitTest, InstallTimeA) {
base::Time install_time = base::Time::Now();
SetUpUsage("A", true, install_time);

histogram_tester_.ExpectUniqueSample(kDayZeroAInstallTime, 0, 1);

task_environment_.FastForwardBy(base::Days(15));

histogram_tester_.ExpectBucketCount(kDayZeroAInstallTime, 15, 1);
histogram_tester_.ExpectTotalCount(kDayZeroBInstallTime, 0);

SetUpUsage("B", false, install_time);
histogram_tester_.ExpectBucketCount(kDayZeroAInstallTime, 15, 2);
histogram_tester_.ExpectTotalCount(kDayZeroBInstallTime, 0);
}
#endif // BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_WIN)

} // namespace misc_metrics
3 changes: 3 additions & 0 deletions components/misc_metrics/pref_names.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ inline constexpr char kMiscMetricsNewTabLocationBarEntriesStorage[] =
"brave.misc_metrics.new_tab_location_bar_entries_storage";
inline constexpr char kMiscMetricsTotalLocationBarEntriesStorage[] =
"brave.misc_metrics.total_location_bar_entries_storage";

inline constexpr char kMiscMetricsDayZeroVariantAtInstall[] =
"brave.misc_metrics.day_zero_variant_at_install";
} // namespace misc_metrics

#endif // BRAVE_COMPONENTS_MISC_METRICS_PREF_NAMES_H_
Loading
Loading