Skip to content

Commit

Permalink
Merge pull request #26543 from brave/leo-search-p3a
Browse files Browse the repository at this point in the history
Add SERP entry point to Leo metrics
  • Loading branch information
DJAndries authored Nov 15, 2024
2 parents 77b46de + cdd9854 commit 7097006
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
6 changes: 4 additions & 2 deletions components/ai_chat/core/browser/ai_chat_metrics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,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<ContextMenuAction, const char*>(
Expand All @@ -86,7 +87,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)

Expand Down Expand Up @@ -234,7 +236,7 @@ void AIChatMetrics::RecordReset() {
UMA_HISTOGRAM_EXACT_LINEAR(kEnabledHistogramName,
std::numeric_limits<int>::max() - 1, 3);
UMA_HISTOGRAM_EXACT_LINEAR(kAcquisitionSourceHistogramName,
std::numeric_limits<int>::max() - 1, 6);
std::numeric_limits<int>::max() - 1, 7);
}

void AIChatMetrics::OnPremiumStatusUpdated(bool is_new_user,
Expand Down
3 changes: 2 additions & 1 deletion components/ai_chat/core/browser/ai_chat_metrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ enum class EntryPoint {
kToolbarButton = 3,
kMenuItem = 4,
kOmniboxCommand = 5,
kMaxValue = kOmniboxCommand
kBraveSearch = 6,
kMaxValue = kBraveSearch
};

enum class ContextMenuAction {
Expand Down
12 changes: 10 additions & 2 deletions components/ai_chat/core/browser/ai_chat_metrics_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -350,11 +350,19 @@ TEST_F(AIChatMetricsUnitTest, MostUsedEntryPoint) {
kMostUsedEntryPointHistogramName,
static_cast<int>(EntryPoint::kToolbarButton), 1);

for (size_t i = 0; i < 4; i++) {
ai_chat_metrics_->HandleOpenViaEntryPoint(EntryPoint::kBraveSearch);
}

histogram_tester_.ExpectBucketCount(
kMostUsedEntryPointHistogramName,
static_cast<int>(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)
Expand Down
5 changes: 5 additions & 0 deletions components/ai_chat/core/browser/ai_chat_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,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();
Expand Down

0 comments on commit 7097006

Please sign in to comment.