A/B test wrapper component with analytics hooks
Views
11.5K
Copies
3.4K
Likes
1.3K
Comments
0
Copy rate
30.0%
Prompt
Build a React component wrapper for A/B experiments that integrates with [analytics_provider]. It should:
- Accept an experimentKey and variants (A, B, optionally C)
- Read the assigned variant from [variant_source] (feature flag provider, localStorage, or server)
- Fire an exposure event the first time a user actually sees the variant (via IntersectionObserver)
- Never flicker — SSR-safe, renders a stable variant on first paint
- Provide a useVariant hook for imperative use
- Deduplicate exposure events per session
- Be fully typed
Output a single file plus a usage example.Customise this prompt
Fill in 2 variables to personalise this prompt
Preview
Build a React component wrapper for A/B experiments that integrates with [analytics_provider]. It should:
- Accept an experimentKey and variants (A, B, optionally C)
- Read the assigned variant from [variant_source] (feature flag provider, localStorage, or server)
- Fire an exposure event the first time a user actually sees the variant (via IntersectionObserver)
- Never flicker — SSR-safe, renders a stable variant on first paint
- Provide a useVariant hook for imperative use
- Deduplicate exposure events per session
- Be fully typed
Output a single file plus a usage example.
Example output