[M135] btm: Add metrics for the navigation that led to the short visit.
UKM collection review: go/btm-shortvisit-ukm
(cherry picked from commit 4711cb014b
)
Fixed: 402791476
Bug: 400503246
Change-Id: I5e0c495b6a056670d07e323654d753b45a6a7934
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6329729
Commit-Queue: Ryan Tarpine <rtarpine@chromium.org>
Reviewed-by: Robert Kaplow <rkaplow@chromium.org>
Reviewed-by: Giovanni Ortuno Urquidi <ortuno@chromium.org>
Cr-Original-Commit-Position: refs/heads/main@{#1430335}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6358016
Owners-Override: Daniel Cheng <dcheng@chromium.org>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Cr-Commit-Position: refs/branch-heads/7049@{#921}
Cr-Branched-From: 2dab7846d0951a552bdc4f350dad497f986e6fed-refs/heads/main@{#1427262}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
982778bf31
commit
cf257362f6
content/browser/btm
tools/metrics/ukm
@ -265,6 +265,10 @@ void BtmShortVisitObserver::DidFinishNavigation(
|
||||
const int32_t visit_id = static_cast<int32_t>(base::RandUint64());
|
||||
ukm::builders::BTM_ShortVisit event(page_source_id_);
|
||||
event.SetVisitDuration(visit_seconds)
|
||||
.SetEntranceWasRendererInitiated(
|
||||
last_navigation.was_renderer_initiated)
|
||||
.SetEntranceHadUserGesture(last_navigation.had_user_gesture)
|
||||
.SetEntrancePageTransition(last_navigation.page_transition)
|
||||
.SetExitWasRendererInitiated(
|
||||
navigation_handle->IsRendererInitiated())
|
||||
.SetExitHadUserGesture(navigation_handle->HasUserGesture())
|
||||
@ -301,6 +305,10 @@ void BtmShortVisitObserver::DidFinishNavigation(
|
||||
}
|
||||
}
|
||||
|
||||
last_navigation.was_renderer_initiated =
|
||||
navigation_handle->IsRendererInitiated();
|
||||
last_navigation.had_user_gesture = navigation_handle->HasUserGesture();
|
||||
last_navigation.page_transition = navigation_handle->GetPageTransition();
|
||||
prev_source_id_ = page_source_id_;
|
||||
page_source_id_ = navigation_handle->GetNextPageUkmSourceId();
|
||||
last_committed_at_ = clock_->Now();
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include "content/common/content_export.h"
|
||||
#include "content/public/browser/web_contents_observer.h"
|
||||
#include "services/metrics/public/cpp/ukm_source_id.h"
|
||||
#include "ui/base/page_transition_types.h"
|
||||
|
||||
namespace base {
|
||||
class Clock;
|
||||
@ -52,6 +53,12 @@ class CONTENT_EXPORT BtmShortVisitObserver
|
||||
std::optional<std::string> prev_site_;
|
||||
// The UKM source id of the page visited before the current page.
|
||||
ukm::SourceId prev_source_id_ = ukm::kInvalidSourceId;
|
||||
// Several properties of the navigation that led to the current page.
|
||||
struct {
|
||||
bool was_renderer_initiated = false;
|
||||
bool had_user_gesture = false;
|
||||
ui::PageTransition page_transition = ui::PAGE_TRANSITION_LINK;
|
||||
} last_navigation;
|
||||
// The time the current page committed.
|
||||
base::Time last_committed_at_;
|
||||
// The source ID of the current page -- used in DidFinishNavigation() to emit
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include "content/public/test/browser_test.h"
|
||||
#include "content/public/test/browser_test_utils.h"
|
||||
#include "content/public/test/content_browser_test.h"
|
||||
#include "content/public/test/test_frame_navigation_observer.h"
|
||||
#include "content/public/test/test_navigation_observer.h"
|
||||
#include "content/shell/browser/shell.h"
|
||||
#include "net/dns/mock_host_resolver.h"
|
||||
@ -535,5 +536,88 @@ IN_PROC_BROWSER_TEST_F(BtmShortVisitObserverBrowserTest, ShortVisitNeighbor) {
|
||||
visit_id5);
|
||||
}
|
||||
|
||||
IN_PROC_BROWSER_TEST_F(BtmShortVisitObserverBrowserTest,
|
||||
EntranceWasRendererInitiated) {
|
||||
ukm::TestAutoSetUkmRecorder ukm_recorder;
|
||||
const GURL url1 =
|
||||
embedded_https_test_server().GetURL("a.test", "/empty.html");
|
||||
const GURL url2 =
|
||||
embedded_https_test_server().GetURL("b.test", "/empty.html");
|
||||
const GURL url3 =
|
||||
embedded_https_test_server().GetURL("c.test", "/empty.html");
|
||||
|
||||
ASSERT_TRUE(NavigateToURL(web_contents(), url1));
|
||||
ASSERT_TRUE(NavigateToURLFromRenderer(web_contents(), url2));
|
||||
ASSERT_TRUE(NavigateToURL(web_contents(), url3));
|
||||
|
||||
UkmEntryVector entries = GetBtmShortVisits(2, ukm_recorder);
|
||||
ASSERT_THAT(EntryURLs(ukm_recorder, entries),
|
||||
testing::ElementsAre(url1, url2));
|
||||
ukm_recorder.ExpectEntryMetric(entries[0], "EntranceWasRendererInitiated", 0);
|
||||
ukm_recorder.ExpectEntryMetric(entries[1], "EntranceWasRendererInitiated", 1);
|
||||
}
|
||||
|
||||
IN_PROC_BROWSER_TEST_F(BtmShortVisitObserverBrowserTest,
|
||||
EntranceHadUserGesture) {
|
||||
ukm::TestAutoSetUkmRecorder ukm_recorder;
|
||||
// FYI, the first navigation must be browser-based, because the WebContents
|
||||
// starts on the empty URL, which doesn't support JavaScript. So we need an
|
||||
// extra navigation in order to test renderer-initiated navigations with and
|
||||
// without user gestures.
|
||||
const GURL url1 =
|
||||
embedded_https_test_server().GetURL("a.test", "/empty.html");
|
||||
const GURL url2 =
|
||||
embedded_https_test_server().GetURL("b.test", "/empty.html");
|
||||
const GURL url3 =
|
||||
embedded_https_test_server().GetURL("c.test", "/empty.html");
|
||||
const GURL url4 =
|
||||
embedded_https_test_server().GetURL("d.test", "/empty.html");
|
||||
|
||||
ASSERT_TRUE(NavigateToURL(web_contents(), url1));
|
||||
ASSERT_TRUE(NavigateToURLFromRenderer(web_contents(), url2));
|
||||
ASSERT_TRUE(
|
||||
NavigateToURLFromRendererWithoutUserGesture(web_contents(), url3));
|
||||
ASSERT_TRUE(NavigateToURL(web_contents(), url4));
|
||||
|
||||
UkmEntryVector entries = GetBtmShortVisits(3, ukm_recorder);
|
||||
ASSERT_THAT(EntryURLs(ukm_recorder, entries),
|
||||
testing::ElementsAre(url1, url2, url3));
|
||||
ukm_recorder.ExpectEntryMetric(entries[0], "EntranceHadUserGesture", 0);
|
||||
ukm_recorder.ExpectEntryMetric(entries[1], "EntranceHadUserGesture", 1);
|
||||
ukm_recorder.ExpectEntryMetric(entries[2], "EntranceHadUserGesture", 0);
|
||||
}
|
||||
|
||||
IN_PROC_BROWSER_TEST_F(BtmShortVisitObserverBrowserTest,
|
||||
EntrancePageTransition) {
|
||||
ukm::TestAutoSetUkmRecorder ukm_recorder;
|
||||
const GURL url1 =
|
||||
embedded_https_test_server().GetURL("a.test", "/empty.html");
|
||||
const GURL url2 =
|
||||
embedded_https_test_server().GetURL("a.test", "/title1.html");
|
||||
const GURL url3 =
|
||||
embedded_https_test_server().GetURL("b.test", "/empty.html");
|
||||
|
||||
ASSERT_TRUE(NavigateToURL(web_contents(), url1));
|
||||
// Click a link to navigate to url2.
|
||||
TestFrameNavigationObserver nav_observer(web_contents());
|
||||
ASSERT_TRUE(ExecJs(web_contents(), R"(
|
||||
const anchor = document.createElement("a");
|
||||
anchor.href = "/title1.html";
|
||||
anchor.click(); )",
|
||||
EXECUTE_SCRIPT_NO_USER_GESTURE));
|
||||
nav_observer.Wait();
|
||||
ASSERT_EQ(web_contents()->GetLastCommittedURL(), url2);
|
||||
ASSERT_TRUE(NavigateToURL(web_contents(), url3));
|
||||
|
||||
UkmEntryVector entries = GetBtmShortVisits(2, ukm_recorder);
|
||||
ASSERT_THAT(EntryURLs(ukm_recorder, entries),
|
||||
testing::ElementsAre(url1, url2));
|
||||
ukm_recorder.ExpectEntryMetric(
|
||||
entries[0], "EntrancePageTransition",
|
||||
ui::PAGE_TRANSITION_TYPED | ui::PAGE_TRANSITION_FROM_ADDRESS_BAR);
|
||||
ukm_recorder.ExpectEntryMetric(entries[1], "EntrancePageTransition",
|
||||
ui::PAGE_TRANSITION_LINK);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace content
|
||||
|
@ -5593,6 +5593,25 @@ be describing additional metrics about the same event.
|
||||
a page for 10 seconds or less, and either (or both) of the previous and
|
||||
following pages are not same-site to the current page.
|
||||
</summary>
|
||||
<metric name="EntranceHadUserGesture">
|
||||
<summary>
|
||||
Whether or not the navigation to the page was initiated by a user gesture
|
||||
(i.e., the value returned by NavigationHandle::HasUserGesture()).
|
||||
</summary>
|
||||
</metric>
|
||||
<metric name="EntrancePageTransition">
|
||||
<summary>
|
||||
The type of transition to the page (i.e., the value returned by
|
||||
NavigationHandle::GetPageTransition()).
|
||||
</summary>
|
||||
</metric>
|
||||
<metric name="EntranceWasRendererInitiated">
|
||||
<summary>
|
||||
Whether or not the navigation to the page was initiated by the renderer
|
||||
process (i.e., the value returned by
|
||||
NavigationHandle::IsRendererInitiated()).
|
||||
</summary>
|
||||
</metric>
|
||||
<metric name="ExitHadUserGesture">
|
||||
<summary>
|
||||
Whether or not the navigation away from the page was initiated by a user
|
||||
|
Reference in New Issue
Block a user