-
Notifications
You must be signed in to change notification settings - Fork 893
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 feature & metrics #22195
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
#include "brave/components/misc_metrics/general_browser_usage.h" | ||
|
||
#include "base/metrics/histogram_macros.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" | ||
|
@@ -24,16 +25,31 @@ constexpr int kProfileCountBuckets[] = {0, 1, 2, 3, 5}; | |
|
||
} // namespace | ||
|
||
GeneralBrowserUsage::GeneralBrowserUsage(PrefService* local_state) { | ||
GeneralBrowserUsage::GeneralBrowserUsage(PrefService* local_state, | ||
bool day_zero_experiment_enabled, | ||
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_enabled) { | ||
local_state->SetBoolean(kMiscMetricsDayZeroAtInstall, true); | ||
} | ||
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->RegisterBooleanPref(kMiscMetricsDayZeroAtInstall, false); | ||
} | ||
|
||
void GeneralBrowserUsage::ReportWeeklyUse() { | ||
|
@@ -42,6 +58,20 @@ 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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @DJAndries this condition is to just keep the histogram putting users into 0-30 day buckets and anyone outside of this range, gets returned to the previous function, right? e.g. negative or >=31 will not be included. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, that's right. users outside of the 0-30 day range will not report either metric. |
||
return; | ||
} | ||
const char* histogram_name = | ||
local_state_->GetBoolean(kMiscMetricsDayZeroAtInstall) | ||
? kDayZeroOnInstallTime | ||
: kDayZeroOffInstallTime; | ||
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, | ||
|
@@ -56,6 +86,9 @@ void GeneralBrowserUsage::SetUpUpdateTimer() { | |
|
||
void GeneralBrowserUsage::Update() { | ||
ReportWeeklyUse(); | ||
#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_WIN) | ||
ReportInstallTime(); | ||
#endif // BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_WIN) | ||
|
||
SetUpUpdateTimer(); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DJAndries the
BRAVE_DAY_ZERO_EXPERIMENT
variable is the same variable cross platforms and as a replacement for the previous Android-specific one?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, correct