Skip to content

Commit 97124fd

Browse files
committed
Add eight Leo metrics
1 parent 8eecf5c commit 97124fd

File tree

16 files changed

+779
-81
lines changed

16 files changed

+779
-81
lines changed

browser/ui/webui/ai_chat/ai_chat_ui_page_handler.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include "base/functional/callback_forward.h"
1515
#include "brave/browser/ai_chat/ai_chat_service_factory.h"
1616
#include "brave/browser/ai_chat/ai_chat_urls.h"
17+
#include "brave/browser/brave_browser_process.h"
18+
#include "brave/browser/misc_metrics/process_misc_metrics.h"
1719
#include "brave/browser/ui/side_panel/ai_chat/ai_chat_side_panel_utils.h"
1820
#include "brave/components/ai_chat/core/browser/ai_chat_service.h"
1921
#include "brave/components/ai_chat/core/browser/constants.h"
@@ -137,13 +139,20 @@ AIChatUIPageHandler::AIChatUIPageHandler(
137139
mojo::PendingReceiver<ai_chat::mojom::AIChatUIHandler> receiver)
138140
: owner_web_contents_(owner_web_contents),
139141
profile_(profile),
142+
ai_chat_metrics_(
143+
g_brave_browser_process->process_misc_metrics()->ai_chat_metrics()),
140144
receiver_(this, std::move(receiver)) {
141145
// Standalone mode means Chat is opened as its own tab in the tab strip and
142146
// not a side panel. chat_context_web_contents is nullptr in that case
143147
favicon_service_ = FaviconServiceFactory::GetForProfile(
144148
profile_, ServiceAccessType::EXPLICIT_ACCESS);
145149
const bool is_standalone = chat_context_web_contents == nullptr;
146150
if (!is_standalone) {
151+
#if !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_IOS)
152+
if (ai_chat_metrics_) {
153+
ai_chat_metrics_->RecordSidebarUsage();
154+
}
155+
#endif // !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_IOS)
147156
active_chat_tab_helper_ =
148157
ai_chat::AIChatTabHelper::FromWebContents(chat_context_web_contents);
149158
chat_tab_helper_observation_.Observe(active_chat_tab_helper_);
@@ -190,6 +199,11 @@ void AIChatUIPageHandler::OpenConversationFullPage(
190199
const std::string& conversation_uuid) {
191200
CHECK(ai_chat::features::IsAIChatHistoryEnabled());
192201
CHECK(active_chat_tab_helper_);
202+
#if !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_IOS)
203+
if (ai_chat_metrics_) {
204+
ai_chat_metrics_->RecordFullPageSwitch();
205+
}
206+
#endif
193207
active_chat_tab_helper_->web_contents()->OpenURL(
194208
{
195209
ConversationUrl(conversation_uuid),

browser/ui/webui/ai_chat/ai_chat_ui_page_handler.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ class AIChatUIPageHandler : public mojom::AIChatUIHandler,
100100
raw_ptr<content::WebContents> owner_web_contents_ = nullptr;
101101
raw_ptr<favicon::FaviconService> favicon_service_ = nullptr;
102102
raw_ptr<Profile> profile_ = nullptr;
103+
raw_ptr<AIChatMetrics> ai_chat_metrics_;
103104

104105
base::CancelableTaskTracker favicon_task_tracker_;
105106

chromium_src/chrome/browser/autocomplete/chrome_autocomplete_provider_client.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,12 @@ void ChromeAutocompleteProviderClient::OpenLeo(const std::u16string& query) {
110110
base::Time::Now(), std::nullopt /* edits */,
111111
false /* from_brave_search_SERP */);
112112

113-
conversation_handler->SubmitHumanConversationEntry(std::move(turn));
114-
115113
ai_chat::AIChatMetrics* metrics =
116114
g_brave_browser_process->process_misc_metrics()->ai_chat_metrics();
117115
CHECK(metrics);
118116
metrics->RecordOmniboxOpen();
117+
118+
conversation_handler->SubmitHumanConversationEntry(std::move(turn));
119119
#endif
120120
}
121121

chromium_src/chrome/browser/renderer_context_menu/render_view_context_menu.cc

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,12 @@ void BraveRenderViewContextMenu::ExecuteAIChatCommand(int command) {
544544
auto [action_type, p3a_action] = GetActionTypeAndP3A(command);
545545
auto selected_text = base::UTF16ToUTF8(params_.selection_text);
546546

547+
auto* ai_chat_metrics =
548+
g_brave_browser_process->process_misc_metrics()->ai_chat_metrics();
549+
if (ai_chat_metrics) {
550+
ai_chat_metrics->OnQuickActionStatusChange(true);
551+
}
552+
547553
if (rewrite_in_place) {
548554
source_web_contents_->SetUserData(kAIChatRewriteDataKey,
549555
std::make_unique<AIChatRewriteData>());
@@ -594,9 +600,9 @@ void BraveRenderViewContextMenu::ExecuteAIChatCommand(int command) {
594600
conversation->SubmitSelectedText(selected_text, action_type);
595601
}
596602

597-
g_brave_browser_process->process_misc_metrics()
598-
->ai_chat_metrics()
599-
->RecordContextMenuUsage(p3a_action);
603+
if (ai_chat_metrics) {
604+
ai_chat_metrics->RecordContextMenuUsage(p3a_action);
605+
}
600606
}
601607

602608
void BraveRenderViewContextMenu::BuildAIChatMenu() {

0 commit comments

Comments
 (0)