@@ -5,6 +5,8 @@ import { focusTrap } from '@primer/behaviors'
55import { useTranslation } from '@/languages/components/useTranslation'
66import { useMaxWidthBreakpoint , useMinWidthBreakpoint } from '../hooks/useBreakpoint'
77import { useCTAPopoverContext } from '@/frame/components/context/CTAContext'
8+ import { sendEvent } from '@/events/components/events'
9+ import { EventType } from '@/events/types'
810
911let previouslyFocused : HTMLElement | null = null
1012
@@ -13,11 +15,13 @@ export function AISearchCTAPopup({
1315 dismiss,
1416 setIsSearchOpen,
1517 isDismissible = true ,
18+ bannerType = 'popover' ,
1619} : {
1720 isOpen : boolean
1821 dismiss ?: ( ) => void
1922 setIsSearchOpen : ( value : boolean ) => void
2023 isDismissible ?: boolean
24+ bannerType ?: 'popover' | 'footer'
2125} ) {
2226 const { t } = useTranslation ( 'search' )
2327 const { permanentDismiss } = useCTAPopoverContext ( )
@@ -26,7 +30,21 @@ export function AISearchCTAPopup({
2630 let overlayRef = useRef < HTMLDivElement > ( null )
2731 let dismissButtonRef = useRef < HTMLButtonElement > ( null )
2832
33+ // Analytics helper functions
34+ const sendCTAAnalytics = ( variation : 'dismiss' | 'ask_copilot' ) => {
35+ const experimentName =
36+ bannerType === 'footer' ? 'copilot_footer_banner' : 'copilot_popover_banner'
37+ sendEvent ( {
38+ type : EventType . experiment ,
39+ experiment_name : experimentName ,
40+ experiment_variation : variation ,
41+ experiment_success : true ,
42+ } )
43+ }
44+
2945 const openSearch = ( ) => {
46+ // Send analytics before taking action
47+ sendCTAAnalytics ( 'ask_copilot' )
3048 setIsSearchOpen ( true )
3149 // They engaged with the CTA, so let's not show this popup for them anymore
3250 permanentDismiss ( )
@@ -47,6 +65,8 @@ export function AISearchCTAPopup({
4765 if ( isTooSmallForCTA ) {
4866 return
4967 }
68+ // Send analytics before taking action
69+ sendCTAAnalytics ( 'dismiss' )
5070 if ( previouslyFocused ) {
5171 previouslyFocused . focus ( )
5272 }
0 commit comments