Embed code
After you publish a composition, the dashboard (orget_embed_code in MCP) gives you a tag and script. The supported way is the CDN script plus a <widgetic> element placed where the widget should appear. There is nothing to install and no key in the page: showing a widget needs only the composition id.
- Several widgets on one page work with one script tag.
data-api-urlis the API the script asks for the composition. Copy it as the dashboard gives it.- Every other attribute is an option of the Embed code screen. Together they decide how the widget fits its place (Size and layout), where it appears (Choose how the widget appears) and when (Choose when a pop-up opens).
- Where the widget runs. The script mounts the widget in the page when it can, and in an iframe of its own when it cannot. Add
render-mode="iframe"to ask for the iframe from the start. - Allowed websites: if you limited the websites that may show your widgets, the script shows nothing on other websites. Your own machine and Widgetic’s own sites are always allowed, and so is a partner’s platform website with all of its subdomains. See Allowed domains.
Paste an embed code to set the options
The Embed code screen in the dashboard shows your embed code in a box at the top, with the line “Not sure how embedding works? Learn more” just below it, and the options under that. You can paste an existing embed code into the box and the options (size, resize mode, overlay position and the rest) change to match it, which is the quickest way to edit an embed that is already on a page:- Copy the embed code from your page.
- Click the code box in the Embed code screen.
- Press
Cmd+V(Mac) orCtrl+V(Windows, Linux).
Choose how the widget appears
The Embed target decides how a visitor meets the widget:
The Embed code screen starts on Overlay, so a code you copy without changing it is a pop-up. A
<widgetic> tag that has no embed-target is Inline.
Inline
The widget is part of the page and takes the space of its tag. This is the code at the top of this page, and Size and layout says how the box is sized.Overlay: a pop-up
A pop-up in the middle of the window on a dimmed background, that opens when the visitor is about to leave, at most twice in 72 hours, and not on phones:- The tag is hidden from the first moment, so the widget never flashes in the page before the pop-up. A pop-up that never opens never loads the widget.
- It opens when the trigger fires (Choose when a pop-up opens). It sits at the Overlay position you chose, one of nine cells of the window, 20 pixels from the edges. It is as big as
widthandheightsay, and never larger than 90% of the window. - The visitor can always close it: it has a close button, and
Esccloses it too. - Add background puts a layer behind the pop-up, in the color and opacity you choose, and the page behind cannot be clicked. Without it the page stays usable while the pop-up is open.
- View limits keep a visitor from seeing it over and over: at most Max # of views within the Time period, counted in the visitor’s browser.
Mixed: a box that follows the visitor
A widget in the page that floats in the bottom-right corner, at 320 by 180 pixels, once its place has scrolled out of view, and never on/checkout:
- The widget is in the page from the start, and the floating box appears when the visitor scrolls it out of view. An empty space the size of the widget stays in the page, so the page does not jump. When the visitor scrolls back to that space, or closes the floating box, the widget returns to it.
- Keep dimensions on lets the floating box keep the size the widget has in the page. Off, the Overlay resize mode, Overlay width and Overlay height size it, as in the code above. A floating box is never larger than 90% of the window.
- Mixed has fewer options than Overlay. It has no trigger and no rules except Exclude URLs, and the device switches of View limits apply. The view limits themselves, Max # of views and Time period, count pop-ups only.
Use iframe: a frame with no script
With Use iframe on, the code is only the frame of the composition. It needs no script, so it works where scripts cannot run, but the widget cannot follow the height of its content or hear events from your page, and only Width and Height are left to set:Size and layout
How the box of an Inline embed is sized comes fromresize, width and height:
A tag with no
resize, or with a value that is not in the table, is a fixed box, and a tag that gives no width or height gets 400 by 300 pixels. resize and adaptive are for an Inline embed: an Overlay or a Mixed embed is not sized by them, and a pop-up or a floating box is sized as described above.
- Height of a wide box. With
fill-widthorresponsive, the height isheight. When the tag has no Autoscale and bothwidthandheightare numbers of pixels, the height instead keeps the proportions of thatwidthandheightas the box gets wider or narrower, so a narrow box is shorter, as a picture is. - Autoscale (
autoscale="on") makes the box as tall as the widget needs, so the widget never clips and the paragraph after it is never covered. The box starts atheight, or at the height the last visit ended on so a reload does not jump, and then follows the widget betweenautoscale-min-height(the tag’sheightunless you say otherwise) andautoscale-max-height(2000 pixels unless you say otherwise, at most 20000). A widget shown in an iframe is followed by the height it reports. Each change sendswidgetic:autoscale. Off, the box stays the height of the tag. A tag that saysautoscale="false"(or0,offorno) is off too. - Adaptive (
adaptive="480") is a breakpoint in pixels, a whole number from 1 to 10000. The tag saysdata-widgetic-mobile="true"while the window is that narrow or narrower, and"false"above it, and sendswidgetic:adaptiveonce the box is made and each time the window crosses it, so your page, or a widget that listens, can switch to a narrow layout. The box itself does not change: afixedtag stays fixed. Aresponsivetag withoutadaptiveuses 480.
Choose when a pop-up opens
The Event triggers setting decides what opens an Overlay pop-up by itself (event-trigger in the tag):
Pick one trigger. Besides the trigger, a pop-up can follow rules, which the visitor’s browser checks before it opens:
- Excludes: pages it must not open on, and not again after the visitor closed it or after it opened once.
- Visitors: new or returning visitors, the time spent on the page, the number of pages seen on your site.
- Schedule: a range of dates, weekdays and hours of the day, by the visitor’s clock.
- Acquisition: direct traffic only, the referrer, the page’s address, and its
utm_source,utm_mediumandutm_campaign. - View limits: at most so many views in a number of hours.
utm_campaign contains spring, never on /checkout or /cart, and not again once the visitor has closed it:
Open it from your page
With the Manual trigger the pop-up never opens by itself. Your page opens it withWidgetic.show, for example from a button, and gives it the composition-id of the tag:
Widgetic.show is there once the embed script has run. It returns true when the page has a pop-up for that id, and false when it has none, for example because the script has not found the composition yet. The rules and the view limits still apply, so a true is not a promise that the pop-up opened: listen for widgetic:overlay-blocked (below) to know why it did not.
Set the options with the API
The options of a composition are saved in itsembedSettings, under the keys listed in Embed settings:
GET /compositions/{id}/schema/embedreturns the schema of the options, which is the same for every composition, with thedefaultsof all of them.GET /compositions/{id}/embed-settingsreturns what the composition saved. A composition that has saved nothing answers404: start from thedefaultsof the schema.PUT /compositions/{id}withembedSettingssaves them. The object you send replaces the saved one, so send every setting you want to keep.
- Send each value as the schema types it: a switch is
trueorfalse, a number is a number (8, not"8"). The opacity of a color is saved beside it, asoverlayBackgroundColor_opacity, a number from 0 to 1. - Send only keys the schema lists. The gateway checks the object before it saves it: a key it does not know, or a value of the wrong kind, makes the call fail and nothing is saved. Read the schema rather than guessing a name.
- The next new composition starts from them. The settings saved last on any composition of a widget are where a new composition of the same widget starts, unless you give it
embedSettingsof its own. A composition filed under a managed user is the exception: its settings stay with it, and no other composition starts from them. - Build the tag from the settings the way Compositions shows, or hand the job to an assistant:
get_embed_settingsandsave_embed_settingsread and save them,apply_embed_codecopies them from a code you paste, andget_embed_codereturns the standard JavaScript embed code (or an iframe, for a page that cannot run a script), plus a share link. See Embed settings in the MCP tools.
Use the npm package
If you bundle your own JavaScript (Vite, webpack, Next.js) and would rather not add a third-party script tag, the same code is on npm:import('@widgetic/embed-sdk').then(({ getSDK }) => getSDK()). The <widgetic> tag and its attributes are the same as above. For a page, a CMS or a template where you can add a <script> tag, the script from the CDN stays the supported way. It is published separately from the package, so it can be a different build from the version you installed.
Allowed domains
By default, a published widget can appear on any website. You can limit it:- Dashboard: workspace Settings → Allowed domains (team workspaces: admins and owners only).
- API:
GETandPOST /organizations/{orgId}/domains,PUTandDELETE /organizations/{orgId}/domains/{domainId}(orgIdis the id of the workspace) — see Domain validation and the matchingwidgetic api organizations …commands. The routes under/users/{id}/workspace/domainsare gone.
localhost, Widgetic’s own sites and (for partners) your platform domain are always allowed. A page on another site gets 403 DOMAIN_NOT_ALLOWED; the embed script draws nothing and sets data-widgetic-refused="DOMAIN_NOT_ALLOWED".
Partners can also set allowedDomains on the partner account; those domains are added to the allowed domains of your partner’s workspace, which is where your customers’ embeds are filed.
Events from the embed
The<widgetic> tag fires bubbling DOM events (same names as inside the iframe), including:
Workflow embeds also fire
widgetic:workflow-step. Send page events into a workflow with sendWorkflowEvent from @widgetic/embed-sdk or widgetic:workflow-event on the tag — see Embed a workflow.
A pop-up or a floating box announces itself on document, with the id of the composition in detail.widgetId (a second tag for the same composition on the page gets -2 after the id, a third -3):
If the widget does not appear
Related
Embed settings
Every option of the Embed code screen, with its key and its attribute
Embed a workflow
Show a path of compositions in one place, or in a frame
Compositions API
Create and publish compositions your embed points at
Security
Domains, keys in the browser and webhook signatures