Embedding
Two ways to add the widget to your site: script tag or direct iframe.
Option 1: Script tag (recommended)
The simplest approach. One script tag handles iframe creation, theming, event relay, and auto-resizing.
<div id="bh-insurance-widget"></div>
<script
src="https://cdn.benefithub.com/widget/v1/widget.js"
data-bh-key="YOUR_KEY"
data-bh-type="auto"
data-bh-container="#bh-insurance-widget"
data-bh-base-url="https://widget.benefithub.insure"
></script>Available data attributes
| Attribute | Required | Description |
|---|---|---|
data-bh-key | Yes | Your widget key |
data-bh-type | No | "auto" (default) or "home" |
data-bh-container | No | CSS selector for container (default: #bh-insurance-widget) |
data-bh-mode | No | "embedded" (default) or "modal" |
data-bh-base-url | Yes* | Widget app URL (required when loading from CDN) |
data-bh-agent-id | No | Agent/vendor tracking ID |
data-bh-logo | No | Custom logo URL (replaces BenefitHub logo) |
data-bh-color-* | No | Theme color overrides (see Theming) |
data-bh-prefill-* | No | Prefill form fields (firstname, lastname, email, phone, zip, address, city, state) |
Modal mode
Display the widget in a centered overlay instead of inline. With the script tag, set data-bh-mode="modal" — the modal opens automatically on page load:
<!-- Auto-open modal on page load -->
<script
src="https://cdn.benefithub.com/widget/v1/widget.js"
data-bh-key="YOUR_KEY"
data-bh-type="auto"
data-bh-mode="modal"
data-bh-base-url="https://widget.benefithub.insure"
></script>For a "click to open" pattern, use the SDK programmatically:
<button id="get-quote-btn">Get Insurance Quote</button>
<div id="bh-insurance-widget"></div>
<script src="https://cdn.benefithub.com/widget/v1/widget.js"></script>
<script>
const widget = BHWidget.init({
key: 'YOUR_KEY',
type: 'auto',
mode: 'modal',
baseUrl: 'https://widget.benefithub.insure',
});
document.getElementById('get-quote-btn')
.addEventListener('click', () => widget.open());
</script>Modal features: close via ESC key, backdrop click, or the built-in X button. Body scroll is locked while the modal is open. See the SDK Reference for .open(), .close(), and .isOpen() methods.
Option 2: Direct iframe
If you prefer full control, embed the widget iframe directly. You handle sizing and event listening yourself.
<iframe
src="https://widget.benefithub.insure/embed/auto?key=YOUR_KEY"
style="width: 100%; min-height: 600px; border: none;"
allow="geolocation"
title="Insurance Quote"
></iframe>iframe URL parameters
| Parameter | Description |
|---|---|
key | Widget key (required) |
apiUrl | API base URL override |
agentId | Agent/vendor ID |
logoUrl | Custom logo URL |
color-primary | Theme color override |
parentOrigin | Parent page origin (set automatically by SDK) |
Security note: PII (name, email, phone) should not be passed as URL parameters — URLs appear in browser history, server logs, and referrer headers. The SDK sends prefill data securely via
postMessageafter the iframe loads. If you embed via direct iframe and need prefill, use thebh:prefillpostMessage protocol (see Events).
Auto-resizing the iframe
The widget sends bh:resize postMessage events with the content height. Listen for them to prevent scrollbars:
window.addEventListener('message', (event) => {
if (event.data?.type === 'bh:resize') {
const iframe = document.querySelector('iframe');
iframe.style.height = event.data.height + 'px';
}
});Server-managed settings
Some settings are managed by BenefitHub in the backend and cannot be set via embed attributes or URL parameters. These are configured during onboarding or by contacting your account manager.
| Setting | Default | Description |
|---|---|---|
| Benefit Badge Text | Exclusive Member Benefits | Trust badge text on the landing page. Custom text up to 200 characters, or empty to hide. HTML is stripped for security. |
| Logo URL | BenefitHub logo | Organization logo (HTTPS URL). |
| Allowed Origins | None | Domains authorized to load the widget. Supports wildcards. |
Configuration priority
When both embed-level and server-managed values exist for the same setting (e.g., logo), the embed-level value wins:
- Embed attributes / URL params (highest priority)
- Server-managed client overrides (from database)
- BenefitHub defaults (fallback)
Next steps
- Theming — customize every color and font
- Webhooks & Events — event reference
