Angular — Advanced Provider Usage
Advanced EmbedProviderComponent patterns — route-based visibility, delay policies, group configuration, programmatic control, and best practices.
Table of Contents
- Quick Start
- EmbedProviderComponent — Props Reference
- embedButtonVisibilityConfig
- EmbedButtonComponent Props
- EmbedInitService
- Usage Patterns
- Best Practices
Quick Start
- Call
EmbedInitService.initialize(apiKey)inAppComponent.ngOnInit(). - Wrap your layout with
<revrag-embed-provider>. - Keep
currentPathin sync with the Angular router. - Add the CSS to
angular.jsonstyles array.
EmbedProviderComponent — Props Reference
Selector:revrag-embed-provider
| Input | Type | Default | Description |
|---|---|---|---|
currentPath | string | undefined | undefined | Highest-priority path override. Keep in sync with the Angular router (or active tab). When omitted the widget is always hidden. |
includeScreens | string[] | [] | Paths where the embed button is visible. Empty = never shown via provider (use EmbedButtonComponent directly). |
matchMode | 'exact' | 'startsWith' | 'exact' | exact — path must match exactly. startsWith — path and all sub-routes (e.g. /help matches /help/faq). |
embedButtonDelayMs | number | 0 | Global delay (ms) before showing the button. Applies when no group config matches. |
embedButtonVisibilityConfig | EmbedButtonVisibilityConfig | undefined | undefined | Per-group config for delays and continuity. See below. |
embedButtonPosition | EmbedButtonPosition | undefined | undefined | Override the button’s pixel position (bottom, right). |
widgetPositioning | 'fixed' | 'embedded' | 'fixed' | fixed — viewport-fixed. embedded — in normal document flow. |
widgetSide | 'left' | 'right' | undefined | undefined | Horizontal alignment of the widget. |
widgetBottomOffset | number | 0 | Extra pixels to raise the widget from the bottom. |
widgetClassName | string | '' | Extra CSS class applied to the widget container. |
Path detection
Unlike React’sEmbedProvider (which auto-detects window.location.pathname), Angular’s EmbedProviderComponent requires you to supply currentPath explicitly because Angular’s router is service-based. Always keep it in sync with NavigationEnd events:
embedButtonVisibilityConfig
Use this for per-route or per-group behavior — different delays, policies, and continuity settings.EmbedButtonVisibilityConfig
| Field | Type | Description |
|---|---|---|
defaultDelayMs | number | Fallback delay when a group matches but has no delayMs. |
groups | EmbedButtonGroupConfig[] | Per-group configuration array. |
EmbedButtonGroupConfig
| Field | Type | Description |
|---|---|---|
id | string | Unique ID for the group (used for session/continuity logic). |
screens | string[] | Paths belonging to this group. |
continuity | 'perScreen' | 'continuous' | See EmbedButtonContinuity below. |
delayMs | number | Delay (ms) before showing the button when this group matches. |
delayPolicy | EmbedButtonDelayPolicy | When to apply the delay. See below. |
EmbedButtonContinuity
| Value | Behavior |
|---|---|
'perScreen' | Treat each screen in the group as a separate visit. Delays apply per screen according to delayPolicy. |
'continuous' | Once you enter the group, the button stays visible while navigating within the group. No delay on subsequent screens in the same group. |
EmbedButtonDelayPolicy
| Value | When delay applies |
|---|---|
'perScreen' | Every time you land on any screen in the group. |
'oncePerGroupEntry' | Only when first entering the group from outside. No delay when moving between screens within the group. |
'oncePerAppSession' | Only the first time you visit any screen in this group during the session. Page refresh resets. |
EmbedButtonComponent Props
Props for the standalone<revrag-embed-button> component (also forwarded internally by EmbedProviderComponent).
| Input | Type | Default | Description |
|---|---|---|---|
positioning | 'fixed' | 'embedded' | 'fixed' | fixed — viewport-fixed. embedded — in-flow. |
side | 'left' | 'right' | 'center' | undefined | undefined | Auto-position in bottom-left, bottom-right, or bottom-center. |
bottomOffset | number | 0 | Extra offset from bottom (e.g. for nav bars). |
position | PositionConfig | undefined | undefined | Fine-grained CSS position override. |
className | string | '' | Additional CSS class for the button container. |
PositionConfig
Example
EmbedInitService
Initializes the SDK. Call once inAppComponent.ngOnInit() before any widget renders.
SDKConfig options
| Field | Type | Description |
|---|---|---|
baseUrl | string | Override API base URL. |
enableTracker | boolean | Enable analytics/tracking. |
trackerCallback | (event: EventPayload) => void | Custom callback for tracking events. |
Return / Observables
| Observable / Getter | Type | Description |
|---|---|---|
isInitialized$ | Observable<boolean> | Emits true after successful init. |
isLoading$ | Observable<boolean> | Emits true while init is in progress. |
error$ | Observable<string | null> | Emits error message if init fails, null otherwise. |
sessionData$ | Observable<SessionStorageData> | Stored session/config for debugging. |
isInitialized | boolean (getter) | Synchronous check. |
Usage Patterns
Pattern 1 — Manual conditional rendering
Best for: apps where you want explicit, imperative control over when the widget appears. Use*ngIf to conditionally render EmbedButtonComponent based on the current route.
*ngIf; adding/removing screens means editing the same conditional.
Pattern 2 — EmbedProvider with includeScreens
Best for: router-based apps where the widget should appear on a known set of routes.
The provider handles route matching, delay logic, and button lifecycle automatically.
/help and all sub-routes like /help/faq, use matchMode="startsWith":
Pattern 3 — Object-based config
Best for: teams that prefer keeping widget configuration in a separate object (easier to share across components, load from a config service, or drive from environment variables).Config from a service or environment
environment.ts:
Pattern 4 — Tab-based navigation (no router)
Best for: single-page apps or dashboards that use tab components instead of the Angular router. Map your active tab to a virtual path and pass it ascurrentPath. The widget appears whenever currentPath matches a path in includeScreens.
Pattern 5 — With delay and embedButtonVisibilityConfig
Best for: onboarding flows, checkout funnels, or support pages where you want the widget to appear after a delay — but only once per session or per group entry.
Pattern 6 — startsWith for nested routes
Best for: feature areas with nested routes where the widget should appear on any sub-page.
Pattern 7 — NgModule-based Apps
For applications that have not migrated to standalone components, importEmbedModule in your root module:
revrag-embed-button, revrag-embed-provider) and inputs remain the same. You do not need to import individual components when EmbedModule is imported.
Pattern 8 — With global delay (embedButtonDelayMs)
Use the simple embedButtonDelayMs input when you want a uniform delay across all included screens without per-group config:
Best Practices
-
Keep
currentPathin sync — Always update it fromNavigationEnd.urlAfterRedirects, notNavigationStart, to ensure the URL reflects the fully resolved route. -
Use
matchMode: 'startsWith'for nested routes — Matches/helpplus any sub-path like/help/faq. Use'exact'when you need precise control. -
Initialize first — Always call
EmbedInitService.initialize()inAppComponent.ngOnInit()and gate widget rendering onisInitialized$. -
Handle errors — Subscribe to
error$fromEmbedInitServiceand surface it to the user or log it. -
Add CSS to
angular.json— Importnode_modules/@revrag-ai/embed-angular/styles/widget.cssin thestylesarray; rebuild after adding it. -
Add
provideAnimations()— Place it inapp.config.ts(standalone) or importBrowserAnimationsModule(NgModule). Missing it breaks widget transitions silently. -
Use
embedButtonVisibilityConfigfor per-route delay policies — Prefer per-group delays over a single globalembedButtonDelayMsin multi-route apps. -
oncePerAppSessionfor support screens — Avoids re-showing the delay on every visit during a session. -
oncePerGroupEntryfor funnels — Delay only when a user first enters a checkout or onboarding flow; no delay when they move between steps. -
continuousfor multi-step flows — Prevents the widget from disappearing and reappearing as the user navigates through/checkout→/payment→/confirmation. -
Clean up subscriptions — Unsubscribe from router event subscriptions (or use
takeUntilDestroyed()) inngOnDestroy()to prevent memory leaks. -
Use
embedButtonPositionfor fine-grained placement — When the defaultwidgetSide+widgetBottomOffsetisn’t precise enough, pass anEmbedButtonPositionobject with explicit pixel values.
Summary
| Pattern | Approach | Best For |
|---|---|---|
| 1 — Manual | *ngIf + EmbedButtonComponent | Explicit imperative control |
| 2 — Provider + screens | EmbedProviderComponent + includeScreens | Router-based apps |
| 3 — Object config | Config constant / service → EmbedProviderComponent | Shared config, env-driven |
| 4 — Tab-based | Virtual paths from active tab state | No-router / dashboard apps |
| 5 — Visibility config | embedButtonVisibilityConfig with groups | Delay + continuity policies |
| 6 — startsWith | matchMode="startsWith" | Nested route areas |
| 7 — NgModule | EmbedModule | Legacy NgModule apps |
| 8 — Global delay | embedButtonDelayMs | Uniform delay, no group logic needed |
EmbedProviderComponent + includeScreens is the recommended pattern for most Angular apps: one provider, one config list, the widget shown only on the screens you choose.