Hooks

React hooks for tracking events, fetching personalized layouts, and accessing experiment state.

useTrackComponent

Track interactions with a specific component. Returns tracking functions and a ref for automatic view tracking.

typescript

Options

PropTypeDefaultDescription
trackClicksbooleantrueWhether to automatically track click events.
trackVisibilitybooleantrueWhether to automatically track view events via IntersectionObserver.
trackTimeSpentbooleantrueWhether to track time spent viewing the component.
trackHoverbooleanfalseWhether to track hover events with duration.
hoverThresholdnumber500Minimum hover duration in ms before tracking.
trackFormInteractionsbooleanfalseWhether to track form field changes.

Returns

typescript

useTrackZone

Track zone-level events. Useful for tracking interactions that span multiple components.

typescript

usePersonalizedUI

Fetch personalized layout configuration for a page or zone. Useful when you need more control than M0rphicZone provides.

typescript

Options

PropTypeDefaultDescription
pageId*string-The page to get personalized UI for.
zoneIdstring-Optional zone to narrow down the request.
fallbackLayoutConfig-Fallback layout to use while loading or on error.

Tip

For most use cases, prefer M0rphicZone which handles layout fetching and rendering automatically.

useExperiment

Access experiment state and variant information. Useful for custom experiment implementations.

typescript

Returns

typescript

useM0rphic

Access the m0rphic SDK context, including configuration and user information.

typescript

Warning

This hook must be used within a M0rphicProvider. It will throw an error if used outside the provider tree.