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
| Prop | Type | Default | Description |
|---|---|---|---|
trackClicks | boolean | true | Whether to automatically track click events. |
trackVisibility | boolean | true | Whether to automatically track view events via IntersectionObserver. |
trackTimeSpent | boolean | true | Whether to track time spent viewing the component. |
trackHover | boolean | false | Whether to track hover events with duration. |
hoverThreshold | number | 500 | Minimum hover duration in ms before tracking. |
trackFormInteractions | boolean | false | Whether 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
| Prop | Type | Default | Description |
|---|---|---|---|
pageId* | string | - | The page to get personalized UI for. |
zoneId | string | - | Optional zone to narrow down the request. |
fallback | LayoutConfig | - | 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.