EmbedProvider — Basic to Advanced Guide for React
EmbedProvider is a React context provider that manages where and when the AI widget appears across your app. Instead of manually placing <EmbedButton /> on every page, you wrap your app once and let the provider handle everything.
How It Works (Internals Overview)
- If
includeScreensis empty → widget shows on every route - If
includeScreenshas values → widget shows only on those routes - Path detection priority:
currentPathprop >usePathHook>window.location
Level 1 — Show Widget on Every Page
The simplest setup. No route filtering, no delays.Level 2 — Show Widget Only on Specific Routes
UseincludeScreens to whitelist which routes show the widget.
Exact Match (default)
/help matches only /help — not /help/faq.
Prefix Match
/help matches /help, /help/faq, /help/contact, etc.
Injecting the Router Hook
The provider needs to know the current path. Pass your router’s hook so it updates on navigation. Next.js App Router:Level 3 — Delay the Widget Appearance
Show the widget after the user has been on a screen for a few seconds, so it doesn’t feel intrusive.- User navigates to
/pricing - Provider hides the widget and starts a 4-second timer
- Timer fires → widget appears with animation
- User navigates away → widget hides immediately, timer resets
- User comes back to
/pricing→ 4-second timer starts again
Level 4 — Customize the Button Position
Override where the floating button sits on the screen.EmbedButton prop through embedButtonProps:
Level 5 — Group-Based Visibility
This is the advanced visibility engine. Use it when different sections of your app need different delay or continuity behavior.The Problem It Solves
Without groups, every navigation triggers the delay timer — so if a user moves between/checkout and /payment (both part of checkout), the widget keeps hiding and re-appearing. Groups prevent that.
Core Concepts
continuity — controls what happens when navigating within a group:
| Value | Behavior |
|---|---|
"continuous" | Widget stays visible — no re-animation when moving between screens in the same group |
"perScreen" | Widget re-applies delay on every screen, even within the group |
delayPolicy — controls when the delay fires:
| Value | Behavior |
|---|---|
"perScreen" | Delay fires on every screen in the group |
"oncePerGroupEntry" | Delay fires only the first time the user enters this group |
"oncePerAppSession" | Delay fires at most once per browser session for this group |
Basic Groups Example
- User is on
/home→ widget hidden (not in any group) - User goes to
/cart→ 2-second delay, then widget appears - User goes to
/checkout→ widget stays visible (same group,continuous) - User goes to
/payment→ widget stays visible (same group,continuous) - User leaves to
/home→ widget hidden - User comes back to
/cart→ no delay this time (oncePerGroupEntry— already triggered)
Multiple Groups
defaultDelayMs
Applies to any screen that is included (viaincludeScreens) but not in any group:
Level 6 — Reading Current Path in Children
Any component insideEmbedProvider can access the current path via useEmbed:
useEmbed()throws if called outsideEmbedProvider. Always use it inside the provider tree.
Complete Real-World Example
A Next.js app with multiple sections, each with their own widget behavior:Props Quick Reference
| Prop | Type | Default | Purpose |
|---|---|---|---|
children | ReactNode | — | Your app content |
currentPath | string | — | Manual path override (highest priority) |
usePathHook | () => string | — | Router hook for automatic path detection |
includeScreens | string[] | [] (all) | Routes where the widget appears |
matchMode | "exact" | "startsWith" | "exact" | How routes are matched |
embedButtonDelayMs | number | 0 | Global delay before widget appears (ms) |
embedButtonVisibilityConfig | EmbedButtonVisibilityConfig | — | Advanced group-based visibility |
embedButtonProps | EmbedButtonProps | — | Props forwarded to <EmbedButton /> |
embedButtonPosition | { bottom?, right? } | { bottom: 20, right: 16 } | Fixed position of the floating button |
Common Mistakes
Passing the hook result instead of the hook itself:useEmbed outside the provider:
includeScreens + groups to be separate:
Screens listed in groups[].screens are automatically added to the include list — you don’t need to repeat them in includeScreens.
"use client" in Next.js App Router: