summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcalamity <calamity@chromium.org>2016-01-21 16:56:23 -0800
committerCommit bot <commit-bot@chromium.org>2016-01-22 00:57:59 +0000
commit95751ede1a71689177eacfaf8832f964d0feb77b (patch)
tree2ea58d4442746c94a473c902c182678d5213a734
parent9ab09c75b951aaea30e5e675a7e53693e8563eb2 (diff)
downloadchromium_src-95751ede1a71689177eacfaf8832f964d0feb77b.zip
chromium_src-95751ede1a71689177eacfaf8832f964d0feb77b.tar.gz
chromium_src-95751ede1a71689177eacfaf8832f964d0feb77b.tar.bz2
Provide extra engagement for the first input event of a day.
This CL adds extra engagement on the first user input event of each day for each site. BUG=464234 Review URL: https://codereview.chromium.org/1586533002 Cr-Commit-Position: refs/heads/master@{#370856}
-rw-r--r--chrome/browser/engagement/site_engagement_helper_unittest.cc25
-rw-r--r--chrome/browser/engagement/site_engagement_metrics.h1
-rw-r--r--chrome/browser/engagement/site_engagement_service.cc22
-rw-r--r--chrome/browser/engagement/site_engagement_service.h12
-rw-r--r--chrome/browser/engagement/site_engagement_service_unittest.cc84
5 files changed, 131 insertions, 13 deletions
diff --git a/chrome/browser/engagement/site_engagement_helper_unittest.cc b/chrome/browser/engagement/site_engagement_helper_unittest.cc
index c8058ac..4ad1676 100644
--- a/chrome/browser/engagement/site_engagement_helper_unittest.cc
+++ b/chrome/browser/engagement/site_engagement_helper_unittest.cc
@@ -20,6 +20,11 @@
class SiteEngagementHelperTest : public ChromeRenderViewHostTestHarness {
public:
+ void SetUp() override {
+ ChromeRenderViewHostTestHarness::SetUp();
+ SiteEngagementScore::DisableFirstDailyEngagementBonusForTesting();
+ }
+
SiteEngagementHelper* GetHelper(content::WebContents* web_contents) {
SiteEngagementHelper::CreateForWebContents(web_contents);
SiteEngagementHelper* helper =
@@ -296,9 +301,12 @@ TEST_F(SiteEngagementHelperTest, MixedInputEngagementAccumulation) {
EXPECT_DOUBLE_EQ(0.5, service->GetScore(url1));
EXPECT_EQ(0, service->GetScore(url2));
histograms.ExpectTotalCount(SiteEngagementMetrics::kEngagementTypeHistogram,
- 1);
+ 2);
histograms.ExpectBucketCount(SiteEngagementMetrics::kEngagementTypeHistogram,
SiteEngagementMetrics::ENGAGEMENT_NAVIGATION, 1);
+ histograms.ExpectBucketCount(
+ SiteEngagementMetrics::kEngagementTypeHistogram,
+ SiteEngagementMetrics::ENGAGEMENT_FIRST_DAILY_ENGAGEMENT, 1);
HandleUserInputAndRestartTracking(helper, blink::WebInputEvent::RawKeyDown);
HandleUserInputAndRestartTracking(helper,
@@ -311,7 +319,7 @@ TEST_F(SiteEngagementHelperTest, MixedInputEngagementAccumulation) {
EXPECT_DOUBLE_EQ(0.75, service->GetScore(url1));
EXPECT_EQ(0, service->GetScore(url2));
histograms.ExpectTotalCount(SiteEngagementMetrics::kEngagementTypeHistogram,
- 6);
+ 7);
histograms.ExpectBucketCount(SiteEngagementMetrics::kEngagementTypeHistogram,
SiteEngagementMetrics::ENGAGEMENT_NAVIGATION, 1);
histograms.ExpectBucketCount(SiteEngagementMetrics::kEngagementTypeHistogram,
@@ -321,6 +329,9 @@ TEST_F(SiteEngagementHelperTest, MixedInputEngagementAccumulation) {
histograms.ExpectBucketCount(SiteEngagementMetrics::kEngagementTypeHistogram,
SiteEngagementMetrics::ENGAGEMENT_TOUCH_GESTURE,
2);
+ histograms.ExpectBucketCount(
+ SiteEngagementMetrics::kEngagementTypeHistogram,
+ SiteEngagementMetrics::ENGAGEMENT_FIRST_DAILY_ENGAGEMENT, 1);
HandleUserInputAndRestartTracking(helper, blink::WebInputEvent::MouseWheel);
HandleUserInputAndRestartTracking(helper, blink::WebInputEvent::MouseDown);
@@ -332,7 +343,7 @@ TEST_F(SiteEngagementHelperTest, MixedInputEngagementAccumulation) {
EXPECT_DOUBLE_EQ(0.93, service->GetScore(url1));
EXPECT_EQ(0, service->GetScore(url2));
histograms.ExpectTotalCount(SiteEngagementMetrics::kEngagementTypeHistogram,
- 11);
+ 12);
histograms.ExpectBucketCount(SiteEngagementMetrics::kEngagementTypeHistogram,
SiteEngagementMetrics::ENGAGEMENT_MOUSE, 2);
histograms.ExpectBucketCount(SiteEngagementMetrics::kEngagementTypeHistogram,
@@ -346,6 +357,9 @@ TEST_F(SiteEngagementHelperTest, MixedInputEngagementAccumulation) {
histograms.ExpectBucketCount(SiteEngagementMetrics::kEngagementTypeHistogram,
SiteEngagementMetrics::ENGAGEMENT_MEDIA_HIDDEN,
1);
+ histograms.ExpectBucketCount(
+ SiteEngagementMetrics::kEngagementTypeHistogram,
+ SiteEngagementMetrics::ENGAGEMENT_FIRST_DAILY_ENGAGEMENT, 1);
Navigate(url2);
TrackingStarted(helper);
@@ -362,7 +376,7 @@ TEST_F(SiteEngagementHelperTest, MixedInputEngagementAccumulation) {
EXPECT_DOUBLE_EQ(0.6, service->GetScore(url2));
EXPECT_DOUBLE_EQ(1.53, service->GetTotalEngagementPoints());
histograms.ExpectTotalCount(SiteEngagementMetrics::kEngagementTypeHistogram,
- 14);
+ 16);
histograms.ExpectBucketCount(SiteEngagementMetrics::kEngagementTypeHistogram,
SiteEngagementMetrics::ENGAGEMENT_NAVIGATION, 2);
histograms.ExpectBucketCount(SiteEngagementMetrics::kEngagementTypeHistogram,
@@ -370,6 +384,9 @@ TEST_F(SiteEngagementHelperTest, MixedInputEngagementAccumulation) {
histograms.ExpectBucketCount(SiteEngagementMetrics::kEngagementTypeHistogram,
SiteEngagementMetrics::ENGAGEMENT_TOUCH_GESTURE,
4);
+ histograms.ExpectBucketCount(
+ SiteEngagementMetrics::kEngagementTypeHistogram,
+ SiteEngagementMetrics::ENGAGEMENT_FIRST_DAILY_ENGAGEMENT, 2);
}
TEST_F(SiteEngagementHelperTest, CheckTimerAndCallbacks) {
diff --git a/chrome/browser/engagement/site_engagement_metrics.h b/chrome/browser/engagement/site_engagement_metrics.h
index 1841055..1c36230 100644
--- a/chrome/browser/engagement/site_engagement_metrics.h
+++ b/chrome/browser/engagement/site_engagement_metrics.h
@@ -26,6 +26,7 @@ class SiteEngagementMetrics {
ENGAGEMENT_MEDIA_HIDDEN,
ENGAGEMENT_MEDIA_VISIBLE,
ENGAGEMENT_WEBAPP_SHORTCUT_LAUNCH,
+ ENGAGEMENT_FIRST_DAILY_ENGAGEMENT,
ENGAGEMENT_LAST,
};
diff --git a/chrome/browser/engagement/site_engagement_service.cc b/chrome/browser/engagement/site_engagement_service.cc
index 1133fe8..8b3a264 100644
--- a/chrome/browser/engagement/site_engagement_service.cc
+++ b/chrome/browser/engagement/site_engagement_service.cc
@@ -47,7 +47,8 @@ const char* kVariationNames[] = {
"user_input_points",
"visible_media_playing_points",
"hidden_media_playing_points",
- "web_app_installed_points"
+ "web_app_installed_points",
+ "first_daily_engagement_points",
};
// Length of time between metrics logging.
@@ -124,6 +125,7 @@ double SiteEngagementScore::param_values[] = {
0.02, // VISIBLE_MEDIA_POINTS
0.01, // HIDDEN_MEDIA_POINTS
5, // WEB_APP_INSTALLED_POINTS
+ 0.5, // FIRST_DAILY_ENGAGEMENT
};
const char* SiteEngagementScore::kRawScoreKey = "rawScore";
@@ -164,6 +166,10 @@ double SiteEngagementScore::GetWebAppInstalledPoints() {
return param_values[WEB_APP_INSTALLED_POINTS];
}
+double SiteEngagementScore::GetFirstDailyEngagementPoints() {
+ return param_values[FIRST_DAILY_ENGAGEMENT];
+}
+
void SiteEngagementScore::UpdateFromVariations() {
double param_vals[MAX_VARIATION];
@@ -208,6 +214,7 @@ double SiteEngagementScore::Score() const {
}
void SiteEngagementScore::AddPoints(double points) {
+ DCHECK_NE(0, points);
// As the score is about to be updated, commit any decay that has happened
// since the last update.
raw_score_ = DecayedScore();
@@ -218,6 +225,13 @@ void SiteEngagementScore::AddPoints(double points) {
points_added_today_ = 0;
}
+ if (points_added_today_ == 0) {
+ // Award bonus engagement for the first engagement of the day for a site.
+ points += GetFirstDailyEngagementPoints();
+ SiteEngagementMetrics::RecordEngagement(
+ SiteEngagementMetrics::ENGAGEMENT_FIRST_DAILY_ENGAGEMENT);
+ }
+
double to_add = std::min(kMaxPoints - raw_score_,
GetMaxPointsPerDay() - points_added_today_);
to_add = std::min(to_add, points);
@@ -236,7 +250,7 @@ void SiteEngagementScore::Reset(double points) {
last_engagement_time_ = clock_->Now();
}
-bool SiteEngagementScore::MaxPointsPerDayAdded() {
+bool SiteEngagementScore::MaxPointsPerDayAdded() const {
if (!last_engagement_time_.is_null() &&
clock_->Now().LocalMidnight() != last_engagement_time_.LocalMidnight()) {
return false;
@@ -311,6 +325,10 @@ double SiteEngagementScore::BonusScore() const {
return 0;
}
+void SiteEngagementScore::DisableFirstDailyEngagementBonusForTesting() {
+ param_values[FIRST_DAILY_ENGAGEMENT] = 0;
+}
+
const char SiteEngagementService::kEngagementParams[] = "SiteEngagement";
// static
diff --git a/chrome/browser/engagement/site_engagement_service.h b/chrome/browser/engagement/site_engagement_service.h
index fe75f74d..efdcc79 100644
--- a/chrome/browser/engagement/site_engagement_service.h
+++ b/chrome/browser/engagement/site_engagement_service.h
@@ -56,6 +56,10 @@ class SiteEngagementScore {
// following a launch; each new launch resets the ten days.
WEB_APP_INSTALLED_POINTS,
+ // The number of points given for the first engagement event of the day for
+ // each site.
+ FIRST_DAILY_ENGAGEMENT,
+
MAX_VARIATION
};
@@ -70,6 +74,7 @@ class SiteEngagementScore {
static double GetVisibleMediaPoints();
static double GetHiddenMediaPoints();
static double GetWebAppInstalledPoints();
+ static double GetFirstDailyEngagementPoints();
// Update the default engagement settings via variations.
static void UpdateFromVariations();
@@ -88,7 +93,7 @@ class SiteEngagementScore {
void Reset(double points);
// Returns true if the maximum number of points today has been added.
- bool MaxPointsPerDayAdded();
+ bool MaxPointsPerDayAdded() const;
// Get/set the last time this origin was launched from an installed shortcut.
base::Time last_shortcut_launch_time() { return last_shortcut_launch_time_; }
@@ -104,7 +109,10 @@ class SiteEngagementScore {
FRIEND_TEST_ALL_PREFIXES(SiteEngagementScoreTest, PartiallyEmptyDictionary);
FRIEND_TEST_ALL_PREFIXES(SiteEngagementScoreTest, PopulatedDictionary);
FRIEND_TEST_ALL_PREFIXES(SiteEngagementScoreTest, Reset);
+ FRIEND_TEST_ALL_PREFIXES(SiteEngagementScoreTest, FirstDailyEngagementBonus);
+ friend class SiteEngagementHelperTest;
friend class SiteEngagementScoreTest;
+ friend class SiteEngagementServiceTest;
// Array holding the values corresponding to each item in Variation array.
static double param_values[];
@@ -124,6 +132,8 @@ class SiteEngagementScore {
// Determine any score bonus from having installed shortcuts.
double BonusScore() const;
+ static void DisableFirstDailyEngagementBonusForTesting();
+
// The clock used to vend times. Enables time travelling in tests. Owned by
// the SiteEngagementService.
base::Clock* clock_;
diff --git a/chrome/browser/engagement/site_engagement_service_unittest.cc b/chrome/browser/engagement/site_engagement_service_unittest.cc
index 5a57d28..bb57a03 100644
--- a/chrome/browser/engagement/site_engagement_service_unittest.cc
+++ b/chrome/browser/engagement/site_engagement_service_unittest.cc
@@ -103,6 +103,12 @@ class SiteEngagementScoreTest : public testing::Test {
public:
SiteEngagementScoreTest() : score_(&test_clock_) {}
+ void SetUp() override {
+ testing::Test::SetUp();
+ // Disable the first engagement bonus for tests.
+ SiteEngagementScore::DisableFirstDailyEngagementBonusForTesting();
+ }
+
protected:
void VerifyScore(const SiteEngagementScore& score,
double expected_raw_score,
@@ -145,6 +151,11 @@ class SiteEngagementScoreTest : public testing::Test {
VerifyScore(updated_score, 5, 10, different_day);
}
+ void SetFirstDailyEngagementPointsForTesting(double points) {
+ SiteEngagementScore::param_values
+ [SiteEngagementScore::FIRST_DAILY_ENGAGEMENT] = points;
+ }
+
base::SimpleTestClock test_clock_;
SiteEngagementScore score_;
};
@@ -370,6 +381,46 @@ TEST_F(SiteEngagementScoreTest, PopulatedDictionary) {
TestScoreInitializesAndUpdates(&dict, 1, 2, GetReferenceTime());
}
+// Ensure bonus engagement is awarded for the first engagement of a day.
+TEST_F(SiteEngagementScoreTest, FirstDailyEngagementBonus) {
+ SetFirstDailyEngagementPointsForTesting(0.5);
+
+ SiteEngagementScore score1(&test_clock_);
+ SiteEngagementScore score2(&test_clock_);
+ base::Time current_day = GetReferenceTime();
+
+ test_clock_.SetNow(current_day);
+
+ // The first engagement event gets the bonus.
+ score1.AddPoints(0.5);
+ EXPECT_EQ(1.0, score1.Score());
+
+ // Subsequent events do not.
+ score1.AddPoints(0.5);
+ EXPECT_EQ(1.5, score1.Score());
+
+ // Bonuses are awarded independently between scores.
+ score2.AddPoints(1.0);
+ EXPECT_EQ(1.5, score2.Score());
+ score2.AddPoints(1.0);
+ EXPECT_EQ(2.5, score2.Score());
+
+ test_clock_.SetNow(current_day + base::TimeDelta::FromDays(1));
+
+ // The first event for the next day gets the bonus.
+ score1.AddPoints(0.5);
+ EXPECT_EQ(2.5, score1.Score());
+
+ // Subsequent events do not.
+ score1.AddPoints(0.5);
+ EXPECT_EQ(3.0, score1.Score());
+
+ score2.AddPoints(1.0);
+ EXPECT_EQ(4.0, score2.Score());
+ score2.AddPoints(1.0);
+ EXPECT_EQ(5.0, score2.Score());
+}
+
// Test that resetting a score has the correct properties.
TEST_F(SiteEngagementScoreTest, Reset) {
base::Time current_day = GetReferenceTime();
@@ -405,6 +456,7 @@ class SiteEngagementServiceTest : public ChromeRenderViewHostTestHarness {
g_temp_history_dir = temp_dir_.path();
HistoryServiceFactory::GetInstance()->SetTestingFactory(
profile(), &BuildTestHistoryService);
+ SiteEngagementScore::DisableFirstDailyEngagementBonusForTesting();
}
void NavigateWithTransitionAndExpectHigherScore(
@@ -633,9 +685,14 @@ TEST_F(SiteEngagementServiceTest, LastShortcutLaunch) {
histograms.ExpectTotalCount(
SiteEngagementMetrics::kDaysSinceLastShortcutLaunchHistogram, 1);
- histograms.ExpectUniqueSample(
+ histograms.ExpectTotalCount(
+ SiteEngagementMetrics::kEngagementTypeHistogram, 4);
+ histograms.ExpectBucketCount(
SiteEngagementMetrics::kEngagementTypeHistogram,
SiteEngagementMetrics::ENGAGEMENT_WEBAPP_SHORTCUT_LAUNCH, 2);
+ histograms.ExpectBucketCount(
+ SiteEngagementMetrics::kEngagementTypeHistogram,
+ SiteEngagementMetrics::ENGAGEMENT_FIRST_DAILY_ENGAGEMENT, 2);
EXPECT_DOUBLE_EQ(2.0, service->GetScore(url1));
EXPECT_DOUBLE_EQ(7.0, service->GetScore(url2));
@@ -746,7 +803,7 @@ TEST_F(SiteEngagementServiceTest, CheckHistograms) {
histograms.ExpectUniqueSample(
SiteEngagementMetrics::kPercentOriginsWithMaxEngagementHistogram, 0, 2);
histograms.ExpectTotalCount(SiteEngagementMetrics::kEngagementTypeHistogram,
- 4);
+ 6);
histograms.ExpectBucketCount(SiteEngagementMetrics::kEngagementTypeHistogram,
SiteEngagementMetrics::ENGAGEMENT_NAVIGATION, 1);
histograms.ExpectBucketCount(SiteEngagementMetrics::kEngagementTypeHistogram,
@@ -756,6 +813,9 @@ TEST_F(SiteEngagementServiceTest, CheckHistograms) {
histograms.ExpectBucketCount(SiteEngagementMetrics::kEngagementTypeHistogram,
SiteEngagementMetrics::ENGAGEMENT_MEDIA_HIDDEN,
1);
+ histograms.ExpectBucketCount(
+ SiteEngagementMetrics::kEngagementTypeHistogram,
+ SiteEngagementMetrics::ENGAGEMENT_FIRST_DAILY_ENGAGEMENT, 2);
// Navigations are still logged within the 1 hour refresh period
clock->SetNow(clock->Now() + base::TimeDelta::FromMinutes(59));
@@ -764,7 +824,7 @@ TEST_F(SiteEngagementServiceTest, CheckHistograms) {
service->HandleNavigation(url2, ui::PAGE_TRANSITION_AUTO_BOOKMARK);
histograms.ExpectTotalCount(SiteEngagementMetrics::kEngagementTypeHistogram,
- 6);
+ 8);
histograms.ExpectBucketCount(SiteEngagementMetrics::kEngagementTypeHistogram,
SiteEngagementMetrics::ENGAGEMENT_NAVIGATION, 3);
histograms.ExpectBucketCount(SiteEngagementMetrics::kEngagementTypeHistogram,
@@ -774,6 +834,9 @@ TEST_F(SiteEngagementServiceTest, CheckHistograms) {
histograms.ExpectBucketCount(SiteEngagementMetrics::kEngagementTypeHistogram,
SiteEngagementMetrics::ENGAGEMENT_MEDIA_HIDDEN,
1);
+ histograms.ExpectBucketCount(
+ SiteEngagementMetrics::kEngagementTypeHistogram,
+ SiteEngagementMetrics::ENGAGEMENT_FIRST_DAILY_ENGAGEMENT, 2);
// Update the hourly histograms again.
clock->SetNow(clock->Now() + base::TimeDelta::FromMinutes(1));
@@ -805,7 +868,7 @@ TEST_F(SiteEngagementServiceTest, CheckHistograms) {
histograms.ExpectUniqueSample(
SiteEngagementMetrics::kPercentOriginsWithMaxEngagementHistogram, 0, 3);
histograms.ExpectTotalCount(SiteEngagementMetrics::kEngagementTypeHistogram,
- 9);
+ 12);
histograms.ExpectBucketCount(SiteEngagementMetrics::kEngagementTypeHistogram,
SiteEngagementMetrics::ENGAGEMENT_NAVIGATION, 4);
histograms.ExpectBucketCount(SiteEngagementMetrics::kEngagementTypeHistogram,
@@ -821,6 +884,9 @@ TEST_F(SiteEngagementServiceTest, CheckHistograms) {
histograms.ExpectBucketCount(SiteEngagementMetrics::kEngagementTypeHistogram,
SiteEngagementMetrics::ENGAGEMENT_MEDIA_HIDDEN,
1);
+ histograms.ExpectBucketCount(
+ SiteEngagementMetrics::kEngagementTypeHistogram,
+ SiteEngagementMetrics::ENGAGEMENT_FIRST_DAILY_ENGAGEMENT, 3);
service->HandleNavigation(url1, ui::PAGE_TRANSITION_GENERATED);
service->HandleNavigation(url1, ui::PAGE_TRANSITION_TYPED);
@@ -829,7 +895,7 @@ TEST_F(SiteEngagementServiceTest, CheckHistograms) {
service->HandleUserInput(url3, SiteEngagementMetrics::ENGAGEMENT_MOUSE);
histograms.ExpectTotalCount(SiteEngagementMetrics::kEngagementTypeHistogram,
- 14);
+ 17);
histograms.ExpectBucketCount(SiteEngagementMetrics::kEngagementTypeHistogram,
SiteEngagementMetrics::ENGAGEMENT_NAVIGATION, 6);
histograms.ExpectBucketCount(SiteEngagementMetrics::kEngagementTypeHistogram,
@@ -841,6 +907,9 @@ TEST_F(SiteEngagementServiceTest, CheckHistograms) {
1);
histograms.ExpectBucketCount(SiteEngagementMetrics::kEngagementTypeHistogram,
SiteEngagementMetrics::ENGAGEMENT_WHEEL, 1);
+ histograms.ExpectBucketCount(
+ SiteEngagementMetrics::kEngagementTypeHistogram,
+ SiteEngagementMetrics::ENGAGEMENT_FIRST_DAILY_ENGAGEMENT, 3);
// Advance an origin to the max for a day and advance the clock an hour before
// the last increment before max. Expect the histogram to be updated.
@@ -873,10 +942,13 @@ TEST_F(SiteEngagementServiceTest, CheckHistograms) {
histograms.ExpectUniqueSample(
SiteEngagementMetrics::kPercentOriginsWithMaxEngagementHistogram, 0, 4);
histograms.ExpectTotalCount(SiteEngagementMetrics::kEngagementTypeHistogram,
- 21);
+ 24);
histograms.ExpectBucketCount(SiteEngagementMetrics::kEngagementTypeHistogram,
SiteEngagementMetrics::ENGAGEMENT_NAVIGATION,
13);
+ histograms.ExpectBucketCount(
+ SiteEngagementMetrics::kEngagementTypeHistogram,
+ SiteEngagementMetrics::ENGAGEMENT_FIRST_DAILY_ENGAGEMENT, 3);
for (const std::string& histogram_name : engagement_bucket_histogram_names)
histograms.ExpectTotalCount(histogram_name, 3);