Commit 7ac6a078 authored by Becca Hughes's avatar Becca Hughes Committed by Chromium LUCI CQ

[Kaleidoscope] Add session result metric

Add a metric that records whether a user opened
a recommendation from Kaleidoscope during the
Kaleidoscope session.

BUG=1110373

Change-Id: I49cc5ac2b8a3dbccb711301068b23c315e725eb7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2551286Reviewed-by: default avatarTommy Steimel <steimel@chromium.org>
Reviewed-by: default avatarMark Pearson <mpearson@chromium.org>
Commit-Queue: Becca Hughes <beccahughes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#831975}
parent 6e961a36
...@@ -27,15 +27,18 @@ const url::Origin& KaleidoscopeUntrustedOrigin() { ...@@ -27,15 +27,18 @@ const url::Origin& KaleidoscopeUntrustedOrigin() {
return *origin; return *origin;
} }
bool IsOpenedFromKaleidoscope(content::NavigationHandle* handle) { bool IsMediaItemOpenedFromKaleidoscope(content::NavigationHandle* handle) {
// Google MyActivity is excluded since it is opened from Kaleidoscope FRE
// and settings.
return (handle->GetInitiatorOrigin() && return (handle->GetInitiatorOrigin() &&
handle->GetInitiatorOrigin()->IsSameOriginWith( handle->GetInitiatorOrigin()->IsSameOriginWith(
KaleidoscopeUntrustedOrigin())); KaleidoscopeUntrustedOrigin()) &&
handle->GetURL().host() != "myactivity.google.com");
} }
bool ShouldAllowAutoplay(content::NavigationHandle* handle) { bool ShouldAllowAutoplay(content::NavigationHandle* handle) {
// If the initiating origin is Kaleidoscope then we should allow autoplay. // If the initiating origin is Kaleidoscope then we should allow autoplay.
if (IsOpenedFromKaleidoscope(handle)) if (IsMediaItemOpenedFromKaleidoscope(handle))
return true; return true;
// If the tab is Kaleidoscope then we should allow autoplay. // If the tab is Kaleidoscope then we should allow autoplay.
...@@ -53,6 +56,10 @@ bool ShouldAllowAutoplay(content::NavigationHandle* handle) { ...@@ -53,6 +56,10 @@ bool ShouldAllowAutoplay(content::NavigationHandle* handle) {
const char KaleidoscopeTabHelper::kKaleidoscopeNavigationHistogramName[] = const char KaleidoscopeTabHelper::kKaleidoscopeNavigationHistogramName[] =
"Media.Kaleidoscope.Navigation"; "Media.Kaleidoscope.Navigation";
const char KaleidoscopeTabHelper::
kKaleidoscopeOpenedMediaRecommendationHistogramName[] =
"Media.Kaleidoscope.OpenedMediaRecommendation";
KaleidoscopeTabHelper::KaleidoscopeTabHelper(content::WebContents* web_contents) KaleidoscopeTabHelper::KaleidoscopeTabHelper(content::WebContents* web_contents)
: content::WebContentsObserver(web_contents) {} : content::WebContentsObserver(web_contents) {}
...@@ -66,7 +73,7 @@ void KaleidoscopeTabHelper::ReadyToCommitNavigation( ...@@ -66,7 +73,7 @@ void KaleidoscopeTabHelper::ReadyToCommitNavigation(
RecordMetricsOnNavigation(handle); RecordMetricsOnNavigation(handle);
SetAutoplayOnNavigation(handle); SetAutoplayOnNavigation(handle);
if (IsOpenedFromKaleidoscope(handle)) { if (IsMediaItemOpenedFromKaleidoscope(handle)) {
is_kaleidoscope_derived_ = true; is_kaleidoscope_derived_ = true;
return; return;
} }
...@@ -77,12 +84,33 @@ void KaleidoscopeTabHelper::ReadyToCommitNavigation( ...@@ -77,12 +84,33 @@ void KaleidoscopeTabHelper::ReadyToCommitNavigation(
if (!current_origin.IsSameOriginWith(new_origin)) { if (!current_origin.IsSameOriginWith(new_origin)) {
is_kaleidoscope_derived_ = false; is_kaleidoscope_derived_ = false;
} }
// If the user was on Kaleidoscope but no longer is then the session has been
// ended.
if (current_origin.IsSameOriginWith(KaleidoscopeOrigin()) &&
!new_origin.IsSameOriginWith(KaleidoscopeOrigin()) &&
handle->IsInMainFrame()) {
OnKaleidoscopeSessionEnded();
}
}
void KaleidoscopeTabHelper::WebContentsDestroyed() {
auto current_origin =
url::Origin::Create(web_contents()->GetLastCommittedURL());
if (current_origin.IsSameOriginWith(KaleidoscopeOrigin())) {
OnKaleidoscopeSessionEnded();
}
} }
void KaleidoscopeTabHelper::RecordMetricsOnNavigation( void KaleidoscopeTabHelper::RecordMetricsOnNavigation(
content::NavigationHandle* handle) { content::NavigationHandle* handle) {
// Only record metrics if this page was opened by Kaleidoscope. // Only record metrics if this page was opened by Kaleidoscope.
if (IsOpenedFromKaleidoscope(handle)) { if (IsMediaItemOpenedFromKaleidoscope(handle)) {
if (auto* opener = web_contents()->GetOpener()) {
auto* wc = content::WebContents::FromRenderFrameHost(opener);
KaleidoscopeTabHelper::FromWebContents(wc)->MarkAsSuccessful();
}
base::UmaHistogramEnumeration(kKaleidoscopeNavigationHistogramName, base::UmaHistogramEnumeration(kKaleidoscopeNavigationHistogramName,
KaleidoscopeNavigation::kNormal); KaleidoscopeNavigation::kNormal);
...@@ -109,4 +137,11 @@ void KaleidoscopeTabHelper::SetAutoplayOnNavigation( ...@@ -109,4 +137,11 @@ void KaleidoscopeTabHelper::SetAutoplayOnNavigation(
blink::mojom::kAutoplayFlagUserException); blink::mojom::kAutoplayFlagUserException);
} }
void KaleidoscopeTabHelper::OnKaleidoscopeSessionEnded() {
base::UmaHistogramBoolean(kKaleidoscopeOpenedMediaRecommendationHistogramName,
was_successful_);
was_successful_ = false;
}
WEB_CONTENTS_USER_DATA_KEY_IMPL(KaleidoscopeTabHelper) WEB_CONTENTS_USER_DATA_KEY_IMPL(KaleidoscopeTabHelper)
...@@ -13,6 +13,7 @@ class KaleidoscopeTabHelper ...@@ -13,6 +13,7 @@ class KaleidoscopeTabHelper
public content::WebContentsUserData<KaleidoscopeTabHelper> { public content::WebContentsUserData<KaleidoscopeTabHelper> {
public: public:
static const char kKaleidoscopeNavigationHistogramName[]; static const char kKaleidoscopeNavigationHistogramName[];
static const char kKaleidoscopeOpenedMediaRecommendationHistogramName[];
// These values are persisted to logs. Entries should not be renumbered and // These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused. // numeric values should never be reused.
...@@ -27,11 +28,16 @@ class KaleidoscopeTabHelper ...@@ -27,11 +28,16 @@ class KaleidoscopeTabHelper
// content::WebContentsObserver: // content::WebContentsObserver:
void ReadyToCommitNavigation(content::NavigationHandle* handle) override; void ReadyToCommitNavigation(content::NavigationHandle* handle) override;
void WebContentsDestroyed() override;
// A tab is Kaleidoscope derived if the tab was opened by Kaleidoscope and // A tab is Kaleidoscope derived if the tab was opened by Kaleidoscope and
// remains on the same origin. // remains on the same origin.
bool IsKaleidoscopeDerived() const { return is_kaleidoscope_derived_; } bool IsKaleidoscopeDerived() const { return is_kaleidoscope_derived_; }
// A tab is successful if it had a Kaleidoscope session in it that resulted
// in the user opening another tab.
void MarkAsSuccessful() { was_successful_ = true; }
private: private:
friend class content::WebContentsUserData<KaleidoscopeTabHelper>; friend class content::WebContentsUserData<KaleidoscopeTabHelper>;
...@@ -39,8 +45,10 @@ class KaleidoscopeTabHelper ...@@ -39,8 +45,10 @@ class KaleidoscopeTabHelper
void RecordMetricsOnNavigation(content::NavigationHandle* handle); void RecordMetricsOnNavigation(content::NavigationHandle* handle);
void SetAutoplayOnNavigation(content::NavigationHandle* handle); void SetAutoplayOnNavigation(content::NavigationHandle* handle);
void OnKaleidoscopeSessionEnded();
bool is_kaleidoscope_derived_ = false; bool is_kaleidoscope_derived_ = false;
bool was_successful_ = false;
WEB_CONTENTS_USER_DATA_KEY_DECL(); WEB_CONTENTS_USER_DATA_KEY_DECL();
}; };
......
...@@ -118,3 +118,52 @@ IN_PROC_BROWSER_TEST_F(KaleidoscopeTabHelperBrowserTest, ...@@ -118,3 +118,52 @@ IN_PROC_BROWSER_TEST_F(KaleidoscopeTabHelperBrowserTest,
"example.com", kTestPagePath)); "example.com", kTestPagePath));
EXPECT_FALSE(GetTabHelper()->IsKaleidoscopeDerived()); EXPECT_FALSE(GetTabHelper()->IsKaleidoscopeDerived());
} }
IN_PROC_BROWSER_TEST_F(KaleidoscopeTabHelperBrowserTest,
SessionMetric_OpenedRecommendation) {
const GURL kTestPageUrl = embedded_test_server()->GetURL(kTestPagePath);
{
// Navigate to Kaleidoscope.
NavigateParams params(browser(), GURL(kKaleidoscopeUIURL),
ui::PAGE_TRANSITION_LINK);
ui_test_utils::NavigateToURL(&params);
}
// Simulate a playback.
KaleidoscopeTabHelper::FromWebContents(GetWebContents())->MarkAsSuccessful();
{
// Navigate away from Kaleidoscope.
NavigateParams params(browser(), kTestPageUrl, ui::PAGE_TRANSITION_LINK);
ui_test_utils::NavigateToURL(&params);
}
histogram_tester_.ExpectBucketCount(
KaleidoscopeTabHelper::
kKaleidoscopeOpenedMediaRecommendationHistogramName,
true, 1);
}
IN_PROC_BROWSER_TEST_F(KaleidoscopeTabHelperBrowserTest,
SessionMetric_DidNotOpenRecommendation) {
const GURL kTestPageUrl = embedded_test_server()->GetURL(kTestPagePath);
{
// Navigate to Kaleidoscope.
NavigateParams params(browser(), GURL(kKaleidoscopeUIURL),
ui::PAGE_TRANSITION_LINK);
ui_test_utils::NavigateToURL(&params);
}
{
// Navigate away from Kaleidoscope.
NavigateParams params(browser(), kTestPageUrl, ui::PAGE_TRANSITION_LINK);
ui_test_utils::NavigateToURL(&params);
}
histogram_tester_.ExpectBucketCount(
KaleidoscopeTabHelper::
kKaleidoscopeOpenedMediaRecommendationHistogramName,
false, 1);
}
...@@ -241,7 +241,8 @@ KaleidoscopeUI::KaleidoscopeUI(content::WebUI* web_ui) ...@@ -241,7 +241,8 @@ KaleidoscopeUI::KaleidoscopeUI(content::WebUI* web_ui)
} }
KaleidoscopeUI::~KaleidoscopeUI() { KaleidoscopeUI::~KaleidoscopeUI() {
metrics_recorder_->OnExitPage(); if (metrics_recorder_)
metrics_recorder_->OnExitPage();
// Ensure that the provider is deleted before the metrics recorder, since the // Ensure that the provider is deleted before the metrics recorder, since the
// provider has a pointer to the metrics recorder. // provider has a pointer to the metrics recorder.
......
...@@ -2193,6 +2193,16 @@ reviews. Googlers can read more about this at go/gwsq-gerrit. ...@@ -2193,6 +2193,16 @@ reviews. Googlers can read more about this at go/gwsq-gerrit.
</summary> </summary>
</histogram> </histogram>
<histogram name="Media.Kaleidoscope.OpenedMediaRecommendation" enum="Boolean"
expires_after="2021-08-19">
<owner>beccahughes@chromium.org</owner>
<owner>media-dev@chromium.org</owner>
<summary>
Recorded each time that Kaleidoscope is closed with whether the user opened
a media recommendation from Kaleidoscope during that session.
</summary>
</histogram>
<histogram name="Media.Kaleidoscope.TimeTakenToStartWatch" units="ms" <histogram name="Media.Kaleidoscope.TimeTakenToStartWatch" units="ms"
expires_after="2021-08-19"> expires_after="2021-08-19">
<owner>beccahughes@chromium.org</owner> <owner>beccahughes@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