Add NTP widget answer to Leo entry point metrics (#34592)

This commit is contained in:
Darnell Andries
2026-03-20 11:05:11 -07:00
committed by GitHub
parent ea2ccf00d1
commit 9d43525020
7 changed files with 39 additions and 10 deletions
@@ -38,7 +38,10 @@ export default function AIChatContextsProvider(props: {
conversationEntriesComponent={() => <></>}
>
<ActiveChatContext.Provider value={conversationDetails}>
<ConversationProvider {...conversationDetails}>
<ConversationProvider
{...conversationDetails}
isNTPWidget
>
{props.children}
</ConversationProvider>
</ActiveChatContext.Provider>
@@ -73,6 +73,7 @@ constexpr char kToolbarButtonEntryPointKey[] = "toolbar_button";
constexpr char kMenuItemEntryPointKey[] = "menu_item";
constexpr char kOmniboxCommandEntryPointKey[] = "omnibox_command";
constexpr char kBraveSearchEntryPointKey[] = "brave_search";
constexpr char kNTPWidgetEntryPointKey[] = "ntp_widget";
constexpr auto kContextMenuActionKeys =
base::MakeFixedFlatMap<ContextMenuAction, const char*>(
@@ -93,7 +94,8 @@ constexpr auto kEntryPointKeys =
{EntryPoint::kToolbarButton, kToolbarButtonEntryPointKey},
{EntryPoint::kMenuItem, kMenuItemEntryPointKey},
{EntryPoint::kOmniboxCommand, kOmniboxCommandEntryPointKey},
{EntryPoint::kBraveSearch, kBraveSearchEntryPointKey}});
{EntryPoint::kBraveSearch, kBraveSearchEntryPointKey},
{EntryPoint::kNTPWidget, kNTPWidgetEntryPointKey}});
#endif // !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_IOS)
@@ -324,7 +326,8 @@ 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, 7);
std::numeric_limits<int>::max() - 1,
static_cast<int>(EntryPoint::kMaxValue) + 1);
}
void AIChatMetrics::OnPremiumStatusUpdated(bool is_enabled,
@@ -418,6 +421,12 @@ void AIChatMetrics::OnSendingPromptWithFullPage() {
prompted_via_full_page_ = true;
}
void AIChatMetrics::OnSendingPromptWithNTP() {
#if !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_IOS)
HandleOpenViaEntryPoint(EntryPoint::kNTPWidget);
#endif // !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_IOS)
}
void AIChatMetrics::OnQuickActionStatusChange(bool is_enabled) {
prompted_via_quick_action_ = is_enabled;
}
@@ -97,7 +97,8 @@ enum class EntryPoint {
kMenuItem = 4,
kOmniboxCommand = 5,
kBraveSearch = 6,
kMaxValue = kBraveSearch
kNTPWidget = 7,
kMaxValue = kNTPWidget
};
enum class ContextMenuAction {
@@ -182,6 +183,7 @@ class AIChatMetrics : public mojom::Metrics,
// Metrics:
void OnSendingPromptWithFullPage() override;
void OnSendingPromptWithNTP() override;
void OnQuickActionStatusChange(bool is_enabled) override;
void RecordSkillClick(const std::string& skill_id) override;
@@ -281,9 +281,10 @@ TEST_F(AIChatMetricsUnitTest, AcquisitionSource) {
ai_chat_metrics_->RecordOmniboxOpen();
histogram_tester_.ExpectUniqueSample(kAcquisitionSourceHistogramName, 1, 1);
ai_chat_metrics_->OnSendingPromptWithNTP();
ai_chat_metrics_->RecordEnabled(true, true, GetPremiumCallback());
histogram_tester_.ExpectTotalCount(kAcquisitionSourceHistogramName, 2);
histogram_tester_.ExpectBucketCount(kAcquisitionSourceHistogramName, 0, 1);
histogram_tester_.ExpectBucketCount(kAcquisitionSourceHistogramName, 7, 1);
}
TEST_F(AIChatMetricsUnitTest, OmniboxOpens) {
@@ -421,11 +422,17 @@ TEST_F(AIChatMetricsUnitTest, MostUsedEntryPoint) {
kMostUsedEntryPointHistogramName,
static_cast<int>(EntryPoint::kBraveSearch), 1);
task_environment_.FastForwardBy(base::Days(7));
histogram_tester_.ExpectTotalCount(kMostUsedEntryPointHistogramName, 14);
for (size_t i = 0; i < 5; i++) {
ai_chat_metrics_->OnSendingPromptWithNTP();
}
histogram_tester_.ExpectBucketCount(kMostUsedEntryPointHistogramName, 7, 1);
task_environment_.FastForwardBy(base::Days(7));
histogram_tester_.ExpectTotalCount(kMostUsedEntryPointHistogramName, 14);
histogram_tester_.ExpectTotalCount(kMostUsedEntryPointHistogramName, 19);
task_environment_.FastForwardBy(base::Days(7));
histogram_tester_.ExpectTotalCount(kMostUsedEntryPointHistogramName, 19);
}
#endif // !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_IOS)
@@ -435,6 +435,9 @@ interface Metrics {
// Notify metrics service that a full page prompt is being sent
OnSendingPromptWithFullPage();
// Notify metrics service that a prompt is being sent from the NTP widget
OnSendingPromptWithNTP();
// Notify metrics service if a quick action is being used
OnQuickActionStatusChange(bool is_enabled);
@@ -261,6 +261,7 @@ export function createMockMetrics(
overrides: Partial<Mojom.MetricsInterface> = {},
): Closable<Mojom.MetricsInterface> {
return makeCloseable({
onSendingPromptWithNTP: () => {},
onQuickActionStatusChange: () => {},
onSendingPromptWithFullPage: () => {},
recordSkillClick: () => {},
@@ -55,7 +55,9 @@ export function useCharCountInfo(inputText: string) {
// Each instance of ConversationContext should be provided with an API interface
// connected to the relevant API endpoints.
export type ConversationContextProps = SelectedChatDetails
export type ConversationContextProps = SelectedChatDetails & {
isNTPWidget?: boolean
}
//
// Given the provided conversation API connection, provides neccessary
@@ -281,7 +283,9 @@ export function useProvideConversationContext(props: ConversationContextProps) {
aiChat.dismissStorageNotice()
}
if (aiChat.isStandalone) {
if (props.isNTPWidget) {
aiChat.api.metrics.onSendingPromptWithNTP()
} else if (aiChat.isStandalone) {
aiChat.api.metrics.onSendingPromptWithFullPage()
}