UserHero Docs
Embedded Portal

SDK reference

API reference for the Embedded Portal JavaScript SDK.

SDK reference

The portal SDK is a small, dependency-free script you load from https://userhero.co/portal.js. After it loads it exposes window.UserHero.

Loading the script

Use the queue pattern so you can call methods before the script finishes loading:

<script>
    (function () {
        window.UserHeroQueue = window.UserHeroQueue || [];
        window.UserHeroQueue.push(['init', { /* options */ }]);
    })();
</script>
<script src="https://userhero.co/portal.js" async></script>

Anything you push onto UserHeroQueue before the script loads runs as soon as it is ready, in order.

init(options)

Initialize the portal. Call once per page load.

UserHero.init({
    publicKey: 'YOUR_PUBLIC_KEY',
    user: userPayload,
    userHmac: serverGeneratedHmac,
    locale: 'en',
    theme: 'auto',
    cssVars: { primary: '#5b6cff' },
    showMetricCards: true,
    launcher: 'button',
    zIndex: 2147483000,
});
OptionTypeDefaultDescription
publicKeystringYour project's public key.
userobjectThe identity payload (see Identity).
userHmacstringHex HMAC-SHA256 of the user payload, generated on your server.
locale'en' | 'es'project defaultPortal language.
theme'light' | 'dark' | 'auto'project defaultColor scheme.
cssVarsobjectInline CSS variable overrides.
showMetricCardsbooleanproject defaultShow the New / In progress / Resolved cards.
launcher'button' | 'custom' | 'none''button'How the portal opens.
zIndexnumber2147483000z-index of the panel and launcher.

Launcher modes

  • button — UserHero renders a floating support button in the bottom-right.
  • custom — no built-in launcher; call UserHero.open() from your own UI (e.g. a "Help" link in your nav).
  • none — the portal opens automatically as soon as init resolves. Useful for dedicated /support pages.

Methods

open() / close() / toggle()

Programmatically control the panel.

document.querySelector('.help-link').addEventListener('click', () => UserHero.open());

setUser(payload, hmac)

Update the signed-in user without a page reload (e.g. after a profile change). Pass a freshly signed payload and HMAC.

logout()

Clear the current session. The next setUser or page load will need a new HMAC.

setTheme(theme)

'light', 'dark', or 'auto'.

setLocale(locale)

'en' or 'es'.

setCssVars(vars)

Update brand colors or other variables at runtime. Same allowlist as init.

on(event, handler) / off(event, handler)

Subscribe to portal events.

UserHero.on('ticket_created', ({ ticketId }) => {
    analytics.track('Support ticket created', { ticketId });
});

Events

EventPayloadWhen it fires
loadedThe portal iframe has loaded and is ready for an HMAC.
opened / closedPanel visibility changed.
ticket_created{ ticketId }Customer created a new ticket.
ticket_replied{ ticketId }Customer added a reply.
ticket_reopened{ ticketId }A resolved ticket was reopened.
auth_failed{ reason }The HMAC was rejected. Re-sign the payload and call setUser.
auth_expiringFires roughly 5 minutes before the current expiresAt. Use it to refresh the payload.

On this page