Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SERP entry point to Leo metrics (uplift to 1.74.x) #26579

Open
wants to merge 1 commit into
base: 1.74.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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<ContextMenuAction, const char*>(
Expand All @@ -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)

Expand Down Expand Up @@ -220,7 +222,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 @@ -70,7 +70,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 @@ -346,11 +346,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 @@ -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();
Expand Down
Loading