> ## Documentation Index
> Fetch the complete documentation index at: https://docs.widgetic.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Embed a workflow

> Show a path of compositions in one place, with the embed tag on your page or with a frame and an oEmbed card where you cannot add a tag

A [workflow](https://docs.widgetic.com/docs/partners/ui-components/workflows.md) chains compositions together, with filters between them, so a visitor moves from one to the next. This page is for the developer who shows one on a page. To show a single composition, see [Embedding widgets](https://docs.widgetic.com/docs/api/embedding.md).

## Show a path of compositions in one place

On your page a workflow is still one `<widgetic>` tag: add `workflow-id` to the tag you already use, and keep `composition-id` for the composition a new visitor starts on. The Workflows screen gives you this tag as **Embed code**, in its **Settings**.

```html theme={"theme":"css-variables"}
<script src="https://cdn.widgetic.com/sdks/browser/embed-sdk.js?v=6"></script>
<widgetic workflow-id="WORKFLOW_ID" composition-id="FIRST_COMPOSITION_ID" resize="fill-width" width="800" embed-target="site"></widgetic>
```

When something happens (the visitor saves an entry, does something in the widget, your page tells the workflow, or a wait is over), the composition on screen is replaced by the next one, in place and without reloading the page. The box the widget sits in grows or shrinks to the height of the next composition: autoscale is always on for a workflow embed, so `autoscale="false"` and `fixed-height` are ignored, and the `autoscale-min-height`, `autoscale-max-height`, `autoscale-debounce`, `autoscale-threshold`, `autoscale-animate` and `autoscale-animation-duration` attributes still apply. A visitor whose device asks for reduced motion gets no animation.

* **The first composition shows as soon as the workflow is read, and never later than two seconds.** The workflow's answer says which language to show it in, so the composition the tag names (or the one a returning visitor was on) is built when the answer is in. If the answer is slower than two seconds, the composition is shown as it is, and swapped for its translation when the answer arrives.
* **Every step is in the visitor's language.** A composition that has translations (copies of it in other languages, made with Widgetic's Translations) is shown in the language of the visitor's browser, the way a translated embed shows it: the first of the visitor's languages that has a copy, in the browser's order (`fr-CA` before `fr`), then a copy in the same language family, and otherwise the composition as it was written. It applies to the composition of every step, not only the first, and each one is judged on its own: a visitor can read the second step in French and the third as it was written when only the second has a French copy. The copies come with the workflow, so a language you add to a translation shows up without publishing the workflow again, and a copy that cannot be shown is replaced by the composition itself. The workflow still names the compositions you put in it: counts, the visitor's place and the tag's events keep their ids, not those of the copies.
* **Every composition takes the tag's look and data.** `width`, `height`, `resize`, the theme attributes and the page's `values`, `context` and `media-resolver` apply to every composition of the workflow, and follow a change you make to them. What you wrote *inside* the tag for one composition (inline `design` and `content` overrides) applies to the composition the tag names, and to no other.
* **When it is not a workflow, it is a plain embed.** If the workflow is paused, does not exist, cannot be read, or does not contain the tag's `composition-id`, the tag shows that composition as any embed does. A workflow never keeps a page from showing something.
* **One tag for a workflow per page.** Two tags with the same `workflow-id` share one position.
* **Where the visitor is.** In their own browser, in `localStorage` under `widgetic_workflow_<workflowId>`: ids and times only, never a value and never who the visitor is. A visitor finishes the version they started on, even when a newer one is published, and after 30 days the position is forgotten and they start again on the latest version.
* **What a visitor types.** The values of an entry a visitor saves, and of an event your page sends, are read by the conditions of a published workflow and then forgotten: they are never stored and never sent back to Widgetic.
* **Counts.** The tag reports how many visitors reached a block, took a line, or could not be moved on, so the **Runs** tab can show them. A report holds ids and numbers only, never a visitor, a value, an address or a page. It is best effort and never delays the page.

### What moves a visitor

A step starts with one of four triggers: an **input added** (an entry the widget saved), an **action in the widget** (a click, a submit, a play), an **event from your page**, or a **scheduled** wait or date. The first two work only with a widget that can supply them: a widget that keeps what visitors send (a Pro widget) for an input, a widget that reports actions for an action, and a widget published after workflows were added (an older one cannot report either). The editor enables a step only when the composition's widget can supply it, and says why when it cannot. An **event from your page** and a **scheduled** step work with any widget. To send an event from your page:

```javascript theme={"theme":"css-variables"}
import { sendWorkflowEvent } from '@widgetic/embed-sdk';

// Returns true when the event was sent, and false (and nothing happens) when its name or values do not fit.
sendWorkflowEvent(document.querySelector('#signup'), 'checkout-started', { total: 42, member: true });
```

With the script from the CDN, send the same thing as a DOM event on the tag:

```javascript theme={"theme":"css-variables"}
document.querySelector('#signup').dispatchEvent(
  new CustomEvent('widgetic:workflow-event', { detail: { name: 'checkout-started', values: { total: 42, member: true } } }),
);
```

A name, of an event or of a value, is 1 to 64 letters, digits, `_`, `.`, `:` or `-`. An event has up to 12 values, each a text (cut to 200 characters), a number or a yes/no. What does not fit is dropped before the workflow sees it.

### What the tag tells your page

Besides the usual `widgetic:ready`, `widgetic:error` and `widgetic:submitted` of the composition on screen (their `compositionId` is the translation when the visitor is shown one), the tag fires `widgetic:workflow-step` with `{ workflowId, from, to }` (the ids of the compositions in the workflow, whatever language they are shown in) each time a visitor moves on. If the next composition cannot be shown, or does not appear within 8 seconds, the visitor stays on the one they are on, the tag fires `widgetic:error`, and one more try is made 30 seconds later.

## Show a workflow where you cannot add a tag

Some places take an address or an iframe and no script: a chat messenger, a link page, a site builder, a blog or a notes tool that follows oEmbed. For those, a workflow has a **frame**, as a composition has (see [Embedding widgets](https://docs.widgetic.com/docs/api/embedding.md#embed-code)): one page of Widgetic's that holds the tag above with the embed script, so it runs the workflow from its first composition to its last and does what the tag does. Its address is

```text theme={"theme":"css-variables"}
https://api.widgetic.com/embed/workflows/WORKFLOW_ID/frame
```

`WORKFLOW_ID` is the `workflow-id` of the tag that the workflow's **Embed code** gives you. Paste the address where the place asks for one, or put it in an iframe:

```html theme={"theme":"css-variables"}
<iframe src="https://api.widgetic.com/embed/workflows/WORKFLOW_ID/frame" width="800" height="600" title="Widgetic interactive content" frameborder="0" allowfullscreen></iframe>
```

A place that follows oEmbed can ask for the card of the workflow instead, at `https://api.widgetic.com/oembed/workflows/WORKFLOW_ID`. It answers an oEmbed `rich` card in JSON whose `html` is that iframe, 800 by 600 at most: a `maxwidth` or a `maxheight` in the request lowers the size, and never raises it. `json` is the only `format` it gives. The frame page also links to the card in its head, for a place that finds it from the address of the frame. Whether a given place accepts an address it does not already know is that place's own rule.

* **A frame sees less than a page does.** A workflow in a frame moves a visitor on only by what the frame can see itself: the entries the visitor saves, an action in the widget, and waits. An **event from your page** never reaches it, because the events of a page do not cross a frame, so a step that waits for one does not start there. The `widgetic:workflow-step` event of the tag stays in the frame as well. A workflow that depends on events from your page needs the tag on your own page.
* **What the frame shows when there is nothing to run.** A workflow that is paused shows its first composition, as a plain embed. A workflow that is not published, is archived, or does not exist, and a workflow whose owner is no longer being served (a plan that has lapsed, for example), show one short page that says "This workflow is unavailable." with a `404`, and the same words for every reason. When Widgetic cannot read the workflow at that moment, the answer is `503`.
* **It is never kept by a cache.** Whether the frame can be shown depends on the state of the workflow and of its owner, so the answer carries `Cache-Control: no-store`.
* **The websites you list apply.** If you limit the [websites that may show your widgets](https://docs.widgetic.com/resources/security.md#domain-validation), the frame is shown only on the websites that the owner of the workflow's **first composition** listed, and the card answers `403` with `DOMAIN_NOT_ALLOWED` to a website that is not on that list. Later compositions of the workflow are not asked about. Add the address of the place that will show the frame, for example the domain of the link page.
* **There are limits.** The frame and the card count together, for one network address on one workflow and for one workflow as a whole. Past a limit the answer is `429` with a `Retry-After` header.

## Related

> [card] [Embedding widgets](https://docs.widgetic.com/docs/api/embedding.md)
>
> The embed script, allowed websites and the events of a single composition

> [card] [Workflows for partners](https://docs.widgetic.com/docs/partners/ui-components/workflows.md)
>
> Make workflows for your customers, with the Workflows screen and from your server


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.