Commit 902f59ac authored by Becca Hughes's avatar Becca Hughes Committed by Commit Bot

Media Engagement: Add a UKM bit if the session changed isHigh

This adds an Engagement.IsHigh.Changed bit to the SessionFinished UKM
that will be true if the IsHigh bit changed during the lifetime of the
session.

BUG=814351

Change-Id: I48b296301a59d7f92ce6fd8ac7750c41ed2bbecd
Reviewed-on: https://chromium-review.googlesource.com/964181
Commit-Queue: Becca Hughes <beccahughes@chromium.org>
Reviewed-by: default avatarMounir Lamouri <mlamouri@chromium.org>
Reviewed-by: default avatarSteven Holte <holte@chromium.org>
Cr-Commit-Position: refs/heads/master@{#549242}
parent 84dbdff5
...@@ -108,6 +108,7 @@ class MediaEngagementScore final { ...@@ -108,6 +108,7 @@ class MediaEngagementScore final {
protected: protected:
friend class MediaEngagementAutoplayBrowserTest; friend class MediaEngagementAutoplayBrowserTest;
friend class MediaEngagementContentsObserverTest; friend class MediaEngagementContentsObserverTest;
friend class MediaEngagementSessionTest;
friend class MediaEngagementService; friend class MediaEngagementService;
// Only used by the Media Engagement service when bulk loading data. // Only used by the Media Engagement service when bulk loading data.
......
...@@ -144,6 +144,7 @@ void MediaEngagementSession::RecordUkmMetrics() { ...@@ -144,6 +144,7 @@ void MediaEngagementSession::RecordUkmMetrics() {
.SetEngagement_Score(round(score.actual_score() * 100)) .SetEngagement_Score(round(score.actual_score() * 100))
.SetPlaybacks_Delta(significant_playback_recorded_) .SetPlaybacks_Delta(significant_playback_recorded_)
.SetEngagement_IsHigh(score.high_score()) .SetEngagement_IsHigh(score.high_score())
.SetEngagement_IsHigh_Changed(high_score_changed_)
.SetEngagement_IsHigh_Changes(score.high_score_changes()) .SetEngagement_IsHigh_Changes(score.high_score_changes())
.SetEngagement_IsPreloaded(is_preloaded) .SetEngagement_IsPreloaded(is_preloaded)
.SetPlayer_Audible_Delta(audible_players_total_) .SetPlayer_Audible_Delta(audible_players_total_)
...@@ -181,6 +182,7 @@ void MediaEngagementSession::CommitPendingData() { ...@@ -181,6 +182,7 @@ void MediaEngagementSession::CommitPendingData() {
MediaEngagementScore score = MediaEngagementScore score =
service_->CreateEngagementScore(origin_.GetURL()); service_->CreateEngagementScore(origin_.GetURL());
bool previous_high_value = score.high_score();
if (pending_data_to_commit_.visit) if (pending_data_to_commit_.visit)
score.IncrementVisits(); score.IncrementVisits();
...@@ -216,6 +218,9 @@ void MediaEngagementSession::CommitPendingData() { ...@@ -216,6 +218,9 @@ void MediaEngagementSession::CommitPendingData() {
score.Commit(); score.Commit();
// If the high state has changed store that in a bool.
high_score_changed_ = previous_high_value != score.high_score();
pending_data_to_commit_.visit = pending_data_to_commit_.playback = pending_data_to_commit_.visit = pending_data_to_commit_.playback =
pending_data_to_commit_.players = false; pending_data_to_commit_.players = false;
} }
...@@ -107,6 +107,9 @@ class MediaEngagementSession : public base::RefCounted<MediaEngagementSession> { ...@@ -107,6 +107,9 @@ class MediaEngagementSession : public base::RefCounted<MediaEngagementSession> {
// Whether the session was restored. // Whether the session was restored.
RestoreType restore_status_ = RestoreType::kNotRestored; RestoreType restore_status_ = RestoreType::kNotRestored;
// If the |is_high_| bit has changed since this object was created.
bool high_score_changed_ = false;
DISALLOW_COPY_AND_ASSIGN(MediaEngagementSession); DISALLOW_COPY_AND_ASSIGN(MediaEngagementSession);
}; };
......
...@@ -114,6 +114,18 @@ class MediaEngagementSessionTest : public testing::Test { ...@@ -114,6 +114,18 @@ class MediaEngagementSessionTest : public testing::Test {
base::SimpleTestClock* test_clock() { return &test_clock_; } base::SimpleTestClock* test_clock() { return &test_clock_; }
void SetVisitsAndPlaybacks(int visits, int media_playbacks) {
MediaEngagementScore score =
service()->CreateEngagementScore(origin().GetURL());
score.SetVisits(visits);
score.SetMediaPlaybacks(media_playbacks);
score.Commit();
}
bool ScoreIsHigh() const {
return service()->HasHighEngagement(origin().GetURL());
}
private: private:
const url::Origin origin_; const url::Origin origin_;
base::SimpleTestClock test_clock_; base::SimpleTestClock test_clock_;
...@@ -567,6 +579,8 @@ TEST_F(MediaEngagementSessionTest, RecordUkmMetrics) { ...@@ -567,6 +579,8 @@ TEST_F(MediaEngagementSessionTest, RecordUkmMetrics) {
ukm_entry, Entry::kPlaybacks_SecondsSinceLastName)); ukm_entry, Entry::kPlaybacks_SecondsSinceLastName));
EXPECT_EQ(0, *test_ukm_recorder().GetEntryMetric( EXPECT_EQ(0, *test_ukm_recorder().GetEntryMetric(
ukm_entry, Entry::kEngagement_IsHigh_ChangesName)); ukm_entry, Entry::kEngagement_IsHigh_ChangesName));
EXPECT_EQ(0, *test_ukm_recorder().GetEntryMetric(
ukm_entry, Entry::kEngagement_IsHigh_ChangedName));
} }
SetSignificantPlaybackRecordedForSession(session.get(), false); SetSignificantPlaybackRecordedForSession(session.get(), false);
...@@ -602,6 +616,67 @@ TEST_F(MediaEngagementSessionTest, RecordUkmMetrics) { ...@@ -602,6 +616,67 @@ TEST_F(MediaEngagementSessionTest, RecordUkmMetrics) {
ukm_entry, Entry::kPlaybacks_SecondsSinceLastName)); ukm_entry, Entry::kPlaybacks_SecondsSinceLastName));
EXPECT_EQ(0, *test_ukm_recorder().GetEntryMetric( EXPECT_EQ(0, *test_ukm_recorder().GetEntryMetric(
ukm_entry, Entry::kEngagement_IsHigh_ChangesName)); ukm_entry, Entry::kEngagement_IsHigh_ChangesName));
EXPECT_EQ(0, *test_ukm_recorder().GetEntryMetric(
ukm_entry, Entry::kEngagement_IsHigh_ChangedName));
}
}
TEST_F(MediaEngagementSessionTest, RecordUkmMetrics_Changed_NowHigh) {
const std::string url_string = origin().GetURL().spec();
using Entry = ukm::builders::Media_Engagement_SessionFinished;
// Set the visits and playbacks to just below the threshold so the next
// significant playback will result in the playback being high.
SetVisitsAndPlaybacks(19, 5);
EXPECT_FALSE(ScoreIsHigh());
scoped_refptr<MediaEngagementSession> session = new MediaEngagementSession(
service(), origin(), MediaEngagementSession::RestoreType::kNotRestored);
session->RecordSignificantPlayback();
EXPECT_EQ(0u, test_ukm_recorder().GetEntriesByName(Entry::kEntryName).size());
RecordUkmMetricsForSession(session.get());
{
auto ukm_entries = test_ukm_recorder().GetEntriesByName(Entry::kEntryName);
EXPECT_EQ(1u, ukm_entries.size());
auto* ukm_entry = ukm_entries[0];
test_ukm_recorder().ExpectEntrySourceHasUrl(ukm_entry, origin().GetURL());
EXPECT_EQ(1u, *test_ukm_recorder().GetEntryMetric(
ukm_entry, Entry::kEngagement_IsHigh_ChangedName));
}
}
TEST_F(MediaEngagementSessionTest, RecordUkmMetrics_Changed_WasHigh) {
const std::string url_string = origin().GetURL().spec();
using Entry = ukm::builders::Media_Engagement_SessionFinished;
// Set the visits and playbacks to just above the lower threshold and the is
// high bit to true so the next visit will cross the threshold.
SetVisitsAndPlaybacks(20, 20);
SetVisitsAndPlaybacks(20, 4);
EXPECT_TRUE(ScoreIsHigh());
scoped_refptr<MediaEngagementSession> session = new MediaEngagementSession(
service(), origin(), MediaEngagementSession::RestoreType::kNotRestored);
CommitPendingDataForSession(session.get());
EXPECT_EQ(0u, test_ukm_recorder().GetEntriesByName(Entry::kEntryName).size());
RecordUkmMetricsForSession(session.get());
{
auto ukm_entries = test_ukm_recorder().GetEntriesByName(Entry::kEntryName);
EXPECT_EQ(1u, ukm_entries.size());
auto* ukm_entry = ukm_entries[0];
test_ukm_recorder().ExpectEntrySourceHasUrl(ukm_entry, origin().GetURL());
EXPECT_EQ(1u, *test_ukm_recorder().GetEntryMetric(
ukm_entry, Entry::kEngagement_IsHigh_ChangedName));
} }
} }
......
...@@ -1099,18 +1099,87 @@ be describing additional metrics about the same event. ...@@ -1099,18 +1099,87 @@ be describing additional metrics about the same event.
media playbacks, the total number of visits, the calculated engagement score media playbacks, the total number of visits, the calculated engagement score
and the new number of significant media playbacks that occured this visit. and the new number of significant media playbacks that occured this visit.
</summary> </summary>
<metric name="Engagement.IsHigh"/> <metric name="Engagement.IsHigh">
<metric name="Engagement.IsHigh.Changes"/> <summary>
<metric name="Engagement.IsPreloaded"/> Whether the Media Engagement Service considers the score to be high (we
<metric name="Engagement.Score"/> are using a two threshold approach so there is one threshold to be
<metric name="Playbacks.Delta"/> considered high and another one to lose that status to reduce jitter).
<metric name="Playbacks.SecondsSinceLast"/> </summary>
<metric name="Playbacks.Total"/> </metric>
<metric name="Player.Audible.Delta"/> <metric name="Engagement.IsHigh.Changed">
<metric name="Player.Audible.Total"/> <summary>
<metric name="Player.Significant.Delta"/> Whether the IsHigh bit changed during the current session.
<metric name="Player.Significant.Total"/> </summary>
<metric name="Visits.Total"/> </metric>
<metric name="Engagement.IsHigh.Changes">
<summary>
Counts of IsHigh changing (from 0 to 1 or 1 to 0).
</summary>
</metric>
<metric name="Engagement.IsPreloaded">
<summary>
Whether the origin was preloaded (from the chrome://component) as a high
engagement origin.
</summary>
</metric>
<metric name="Engagement.Score">
<summary>
The calculated Media Engagement score for the current origin. The score is
calculated by dividing the number of significant media playbacks by the
number of visits. If the number of visits is below 5 then the score will
be zero. This score is taken from MediaEngagementService.
</summary>
</metric>
<metric name="Playbacks.Delta">
<summary>
The number of significant media playbacks on this origin during this
session (a visit to an origin on the same tab). A playback is determined
significant if it meets certain criteria such as a video size of at least
200x140px, is not muted, is playing, etc.
</summary>
</metric>
<metric name="Playbacks.SecondsSinceLast">
<summary>
The number of seconds between significant media playback on the last visit
and significant media playback on the current visit. If there was no
previous visit or significant media playback this visit it will be 0.
</summary>
</metric>
<metric name="Playbacks.Total">
<summary>
The total number of significant media playbacks on this origin.
</summary>
</metric>
<metric name="Player.Audible.Delta">
<summary>
The number of unique audio/video players on a page that was audible (made
sound) during a visit.
</summary>
</metric>
<metric name="Player.Audible.Total">
<summary>
The delta from above but instead of a single visit, the total of all
deltas for all visits on this origin.
</summary>
</metric>
<metric name="Player.Significant.Delta">
<summary>
The number of unique audio/video players on a page that was audible (made
sound) and considered significant (played for at least 7 seconds) during a
visit.
</summary>
</metric>
<metric name="Player.Significant.Total">
<summary>
The delta from above but instead of a single visit, the total of all
deltas for all visits on this origin.
</summary>
</metric>
<metric name="Visits.Total">
<summary>
The total number of visits to this origin.
</summary>
</metric>
</event> </event>
<event name="Media.SiteMuted" singular="True"> <event name="Media.SiteMuted" singular="True">
......
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