Skip to content

Commit

Permalink
Add eight Leo metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
DJAndries committed Feb 28, 2025
1 parent 8eecf5c commit 97124fd
Show file tree
Hide file tree
Showing 16 changed files with 779 additions and 81 deletions.
14 changes: 14 additions & 0 deletions browser/ui/webui/ai_chat/ai_chat_ui_page_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include "base/functional/callback_forward.h"
#include "brave/browser/ai_chat/ai_chat_service_factory.h"
#include "brave/browser/ai_chat/ai_chat_urls.h"
#include "brave/browser/brave_browser_process.h"
#include "brave/browser/misc_metrics/process_misc_metrics.h"
#include "brave/browser/ui/side_panel/ai_chat/ai_chat_side_panel_utils.h"
#include "brave/components/ai_chat/core/browser/ai_chat_service.h"
#include "brave/components/ai_chat/core/browser/constants.h"
Expand Down Expand Up @@ -137,13 +139,20 @@ AIChatUIPageHandler::AIChatUIPageHandler(
mojo::PendingReceiver<ai_chat::mojom::AIChatUIHandler> receiver)
: owner_web_contents_(owner_web_contents),
profile_(profile),
ai_chat_metrics_(
g_brave_browser_process->process_misc_metrics()->ai_chat_metrics()),
receiver_(this, std::move(receiver)) {
// Standalone mode means Chat is opened as its own tab in the tab strip and
// not a side panel. chat_context_web_contents is nullptr in that case
favicon_service_ = FaviconServiceFactory::GetForProfile(
profile_, ServiceAccessType::EXPLICIT_ACCESS);
const bool is_standalone = chat_context_web_contents == nullptr;
if (!is_standalone) {
#if !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_IOS)
if (ai_chat_metrics_) {
ai_chat_metrics_->RecordSidebarUsage();
}
#endif // !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_IOS)
active_chat_tab_helper_ =
ai_chat::AIChatTabHelper::FromWebContents(chat_context_web_contents);
chat_tab_helper_observation_.Observe(active_chat_tab_helper_);
Expand Down Expand Up @@ -190,6 +199,11 @@ void AIChatUIPageHandler::OpenConversationFullPage(
const std::string& conversation_uuid) {
CHECK(ai_chat::features::IsAIChatHistoryEnabled());
CHECK(active_chat_tab_helper_);
#if !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_IOS)
if (ai_chat_metrics_) {
ai_chat_metrics_->RecordFullPageSwitch();
}
#endif
active_chat_tab_helper_->web_contents()->OpenURL(
{
ConversationUrl(conversation_uuid),
Expand Down
1 change: 1 addition & 0 deletions browser/ui/webui/ai_chat/ai_chat_ui_page_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class AIChatUIPageHandler : public mojom::AIChatUIHandler,
raw_ptr<content::WebContents> owner_web_contents_ = nullptr;
raw_ptr<favicon::FaviconService> favicon_service_ = nullptr;
raw_ptr<Profile> profile_ = nullptr;
raw_ptr<AIChatMetrics> ai_chat_metrics_;

base::CancelableTaskTracker favicon_task_tracker_;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ void ChromeAutocompleteProviderClient::OpenLeo(const std::u16string& query) {
base::Time::Now(), std::nullopt /* edits */,
false /* from_brave_search_SERP */);

conversation_handler->SubmitHumanConversationEntry(std::move(turn));

ai_chat::AIChatMetrics* metrics =
g_brave_browser_process->process_misc_metrics()->ai_chat_metrics();
CHECK(metrics);
metrics->RecordOmniboxOpen();

conversation_handler->SubmitHumanConversationEntry(std::move(turn));
#endif
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,12 @@ void BraveRenderViewContextMenu::ExecuteAIChatCommand(int command) {
auto [action_type, p3a_action] = GetActionTypeAndP3A(command);
auto selected_text = base::UTF16ToUTF8(params_.selection_text);

auto* ai_chat_metrics =
g_brave_browser_process->process_misc_metrics()->ai_chat_metrics();
if (ai_chat_metrics) {
ai_chat_metrics->OnQuickActionStatusChange(true);
}

if (rewrite_in_place) {
source_web_contents_->SetUserData(kAIChatRewriteDataKey,
std::make_unique<AIChatRewriteData>());
Expand Down Expand Up @@ -594,9 +600,9 @@ void BraveRenderViewContextMenu::ExecuteAIChatCommand(int command) {
conversation->SubmitSelectedText(selected_text, action_type);
}

g_brave_browser_process->process_misc_metrics()
->ai_chat_metrics()
->RecordContextMenuUsage(p3a_action);
if (ai_chat_metrics) {
ai_chat_metrics->RecordContextMenuUsage(p3a_action);
}
}

void BraveRenderViewContextMenu::BuildAIChatMenu() {
Expand Down
Loading

0 comments on commit 97124fd

Please sign in to comment.