diff --git a/components/ai_chat/core/browser/ai_chat_metrics.cc b/components/ai_chat/core/browser/ai_chat_metrics.cc index 2b4903c207af..c4ec714c9a9b 100644 --- a/components/ai_chat/core/browser/ai_chat_metrics.cc +++ b/components/ai_chat/core/browser/ai_chat_metrics.cc @@ -53,6 +53,7 @@ constexpr char kContextMenuEntryPointKey[] = "context_menu"; constexpr char kToolbarButtonEntryPointKey[] = "toolbar_button"; constexpr char kMenuItemEntryPointKey[] = "menu_item"; constexpr char kOmniboxCommandEntryPointKey[] = "omnibox_command"; +constexpr char kBraveSearchEntryPointKey[] = "brave_search"; constexpr auto kContextMenuActionKeys = base::MakeFixedFlatMap( @@ -72,7 +73,8 @@ constexpr auto kEntryPointKeys = {EntryPoint::kContextMenu, kContextMenuEntryPointKey}, {EntryPoint::kToolbarButton, kToolbarButtonEntryPointKey}, {EntryPoint::kMenuItem, kMenuItemEntryPointKey}, - {EntryPoint::kOmniboxCommand, kOmniboxCommandEntryPointKey}}); + {EntryPoint::kOmniboxCommand, kOmniboxCommandEntryPointKey}, + {EntryPoint::kBraveSearch, kBraveSearchEntryPointKey}}); #endif // !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_IOS) @@ -220,7 +222,7 @@ void AIChatMetrics::RecordReset() { UMA_HISTOGRAM_EXACT_LINEAR(kEnabledHistogramName, std::numeric_limits::max() - 1, 3); UMA_HISTOGRAM_EXACT_LINEAR(kAcquisitionSourceHistogramName, - std::numeric_limits::max() - 1, 6); + std::numeric_limits::max() - 1, 7); } void AIChatMetrics::OnPremiumStatusUpdated(bool is_new_user, diff --git a/components/ai_chat/core/browser/ai_chat_metrics.h b/components/ai_chat/core/browser/ai_chat_metrics.h index 2c5dd7dfc0c5..20bd0d11cda4 100644 --- a/components/ai_chat/core/browser/ai_chat_metrics.h +++ b/components/ai_chat/core/browser/ai_chat_metrics.h @@ -70,7 +70,8 @@ enum class EntryPoint { kToolbarButton = 3, kMenuItem = 4, kOmniboxCommand = 5, - kMaxValue = kOmniboxCommand + kBraveSearch = 6, + kMaxValue = kBraveSearch }; enum class ContextMenuAction { diff --git a/components/ai_chat/core/browser/ai_chat_metrics_unittest.cc b/components/ai_chat/core/browser/ai_chat_metrics_unittest.cc index e41ac0baa28b..759f71d7c3da 100644 --- a/components/ai_chat/core/browser/ai_chat_metrics_unittest.cc +++ b/components/ai_chat/core/browser/ai_chat_metrics_unittest.cc @@ -346,11 +346,19 @@ TEST_F(AIChatMetricsUnitTest, MostUsedEntryPoint) { kMostUsedEntryPointHistogramName, static_cast(EntryPoint::kToolbarButton), 1); + for (size_t i = 0; i < 4; i++) { + ai_chat_metrics_->HandleOpenViaEntryPoint(EntryPoint::kBraveSearch); + } + + histogram_tester_.ExpectBucketCount( + kMostUsedEntryPointHistogramName, + static_cast(EntryPoint::kBraveSearch), 1); + task_environment_.FastForwardBy(base::Days(7)); - histogram_tester_.ExpectTotalCount(kMostUsedEntryPointHistogramName, 10); + histogram_tester_.ExpectTotalCount(kMostUsedEntryPointHistogramName, 14); task_environment_.FastForwardBy(base::Days(7)); - histogram_tester_.ExpectTotalCount(kMostUsedEntryPointHistogramName, 10); + histogram_tester_.ExpectTotalCount(kMostUsedEntryPointHistogramName, 14); } #endif // !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_IOS) diff --git a/components/ai_chat/core/browser/ai_chat_service.cc b/components/ai_chat/core/browser/ai_chat_service.cc index f19954747b27..33c8b2ede049 100644 --- a/components/ai_chat/core/browser/ai_chat_service.cc +++ b/components/ai_chat/core/browser/ai_chat_service.cc @@ -426,6 +426,11 @@ void AIChatService::OpenConversationWithStagedEntries( associated_content->GetContentId(), associated_content); CHECK(conversation); +#if !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_IOS) + if (ai_chat_metrics_ != nullptr) { + ai_chat_metrics_->HandleOpenViaEntryPoint(EntryPoint::kBraveSearch); + } +#endif // Open AI Chat and trigger a fetch of staged conversations from Brave Search. std::move(open_ai_chat).Run(); conversation->MaybeFetchOrClearContentStagedConversation();