UNPKG

@shopify/shop-minis-react

Version:

React component library for Shopify Shop Minis with Tailwind CSS v4 support (source-only, requires TypeScript)

34 lines (26 loc) 959 B
import {useCallback} from 'react' import {ReportInteractionParams} from '@shopify/shop-minis-platform/actions' import {getWindowLocationPathname} from '../utils/getWindowLocationPathname' import {useHandleAction} from './useHandleAction' import {useShopActions} from './useShopActions' interface UseReportInteractionReturns { /** * Report a user interaction event for analytics. */ reportInteraction: (params: ReportInteractionParams) => Promise<void> } export const useReportInteraction = (): UseReportInteractionReturns => { const {reportInteraction} = useShopActions() const handleAction = useHandleAction(reportInteraction) const report = useCallback( (params: ReportInteractionParams) => { const enrichedParams = { ...params, pageValue: params.pageValue || getWindowLocationPathname(), } return handleAction(enrichedParams) }, [handleAction] ) return {reportInteraction: report} }