JavaScript API reference
After installation, the browser creates window.FlowtomateWidget. To send IDs, email addresses, and events, start with the step-by-step guide. This page lists the methods, their results, and the early call queue.
| Member | Result | Purpose |
|---|---|---|
version | string | The version of the loaded widget. |
ready() | Promise<void> | Wait for the first loading cycle. Completion does not prove that content was received. |
refresh() | Promise<void> | Fetch settings and content again. Handle errors with try/catch. |
identify(userId, attributes?) | Promise<void> | Send a stable user ID and their string fields, including email. |
setTraits(attributes) | Promise<void> | Update individual string fields for an already identified user. |
setConsent(state) | void | Pass 'granted', 'denied', or 'unknown' based on the user's decision. |
reset(options?) | Promise<void> | Reset the user on sign-out. The { clearConsent: true } option also removes the consent choice. |
track(name, properties?) | void | Send an event; the result does not confirm delivery. |
openPopup(id) | Promise<boolean> | Open a popup with manual launch enabled. |
startTour(id) | Promise<StartTourResult> | Attempt to start a tour and get its status. |
openOnboarding(id) | Promise<{ ok: true } | { ok: false; code: string }> | Open published onboarding with manual launch enabled. |
closeOnboarding(id) | void | Close the displayed onboarding. |
registerOnboardingAction(name, handler) | () => void | Connect a product command; returns a function that removes the handler. |
openChecklist(id) | void | Open a loaded checklist. |
openFeedback(idOrKey) | void | Open a feedback form by ID or key. |
destroy() | void | Remove the widget from the page. Do not use the old object afterward. |
For identify and setTraits, attributes values must be strings. For example, pass seats: '12'. track also accepts numbers, booleans, null, and arrays of strings or numbers. See the events article for the full limits.
ready() waits for the first loading cycle, but the widget handles any network error from that cycle internally. If you need fresh content, call await refresh() and handle the error. Before switching accounts, wait for await reset(), then call identify. See consent and manual launch for details about consent and the results of manual opening.
Early call queue
If your website code needs to issue a command before widget.js loads, create a queue before the widget tag:
html
<script>
window.flowtomate = window.flowtomate || function (...args) {
window.flowtomate.q.push(args);
};
window.flowtomate.q = window.flowtomate.q || [];
</script>
<script async src="https://app.flowtomate.ru/widget/v1/widget.js"
data-flowtomate-key="pub_live_REPLACE_WITH_YOUR_KEY"
data-flowtomate-api="https://api.flowtomate.ru"></script>The queue accepts identify, setTraits, setConsent, reset, track, openPopup, startTour, openOnboarding, closeOnboarding, and registerOnboardingAction. An example after the user has actually consented:
js
window.flowtomate('setConsent', 'granted');
window.flowtomate('identify', 'user_42', { email: 'anna@example.com' });Early identify, setTraits, and setConsent calls affect the first load. The widget executes the other commands after ready(). Before the script loads, the queue does not return method results; after loading, its calls are also unsuitable for error handling. If you need the result of openPopup, the status from startTour, or confirmation that reset has completed, call the method through window.FlowtomateWidget with await. Do not queue ready, refresh, openChecklist, openFeedback, destroy, or version.