Widget JavaScript reference
The widget adds one global, FeedbackOtter.
This page lists everything you can call on it.
| Call | What it does |
|---|---|
init(options) |
Starts the widget. |
open(tab?) |
Opens the panel. |
close() |
Closes the panel. |
identify(token) |
Signs a user in or out, without a page reload. |
survey(id) |
Shows a survey now. |
on("unread", fn) |
Tells you how many updates are unread. |
unread() |
Returns the unread count. |
The widget never throws into your page. Bad input is ignored, and calls that return a promise never reject.
Install
Section titled “Install”There are two ways to install it. Copy either one from Widgets → Feedback widget in the dashboard.
Read-only
Section titled “Read-only”One script tag. Visitors can read ideas, but not vote or post.
<script async src="https://widget.feedbackotter.com/widget.js" data-public-key="pk_…"></script>With signed-in users
Section titled “With signed-in users”Add this before </body>:
<script> window.FeedbackOtter = window.FeedbackOtter || { q: [] }; ["init", "open", "close", "identify", "survey", "on"].forEach(function (m) { FeedbackOtter[m] = FeedbackOtter[m] || function () { var a = [].slice.call(arguments); return new Promise(function (r) { FeedbackOtter.q.push([m, a, r]); }); }; }); FeedbackOtter.init({ publicKey: "pk_…", token: "<signed token from your server>", });</script><script async src="https://widget.feedbackotter.com/widget.js"></script>The first lines make a small stand-in for FeedbackOtter.
You can call it straight away, before the script has loaded.
Calls wait in a queue, then run in order once it loads.
FeedbackOtter.init(options): Promise<{ signedIn: boolean; reason?: string }>Starts the widget. Call it once per page.
To change the user later, use identify.
Options
Section titled “Options”| Option | Type | Default | What it does |
|---|---|---|---|
publicKey |
string |
Required | Your product’s public key, pk_…. Not a secret. |
token |
string |
None | The user’s sign-in token, signed by your server. See Single sign-on. |
position |
"left" or "right" |
"right" |
Which corner the button sits in. |
launcher |
boolean |
true |
Show our floating button. Set false to use your own. |
label |
string |
"Feedback" |
The button’s text. Up to 30 characters; longer text is cut. |
theme |
"light", "dark" or "auto" |
"auto" |
"auto" follows the visitor’s system setting, light or dark. |
board |
string |
Default board | Show one board, by its URL slug, such as "bugs". |
debug |
boolean |
false |
Log to the console why a survey didn’t show. |
position, launcher, label, theme and board can also be set in the dashboard.
An option you set in code wins. Leave it out to use the dashboard’s setting.
Then you can change the widget without changing your code.
What it returns
Section titled “What it returns”A promise that resolves once the widget has loaded.
const result = await FeedbackOtter.init({ publicKey: "pk_…", token });// { signedIn: true }// { signedIn: false, reason: "no token" }When signedIn is false, reason says why:
reason |
Meaning |
|---|---|
"no token" |
You didn’t pass a token. The widget is read-only. |
| An error message | The token was rejected, for example because it expired. The message says why. |
"unknown public key" |
No product has this key. The widget doesn’t show. |
"missing publicKey" |
You didn’t pass a publicKey. |
"error" |
Something else went wrong, such as a network error. |
A rejected token never breaks the widget. It carries on read-only and logs a warning to the console.
FeedbackOtter.open(tab?: "ideas" | "roadmap" | "changelog"): voidOpens the panel. Pass a tab to open on it.
document.querySelector("#feedback").addEventListener("click", () => { FeedbackOtter.open();});
// Straight to What's newFeedbackOtter.open("changelog");With no tab, it opens where the user left off.
If the roadmap is turned off, "roadmap" opens Ideas instead.
Use it with launcher: false to open the widget from your own button.
FeedbackOtter.close(): voidCloses the panel. Users can also press Esc.
identify
Section titled “identify”FeedbackOtter.identify(token: string | null): voidSigns a user in, switches to another user, or signs out. The widget reloads ideas, votes and surveys for the new user. There’s no need to reload the page.
// After your app logs someone inconst { token } = await fetch("/api/feedbackotter-token").then((r) => r.json());FeedbackOtter.identify(token);
// After they log outFeedbackOtter.identify(null);Tokens expire, at most 24 hours after you sign them.
If a session lasts longer, fetch a fresh token and call identify again.
survey
Section titled “survey”FeedbackOtter.survey(id: string): Promise< { shown: true } | { shown: false; reason: string }>Shows a survey now, for example after a user finishes an export.
- Create a survey and set its trigger to When your code calls it.
- Save it, then copy its ID,
sv_…, from the top of the editor. - Call
surveywith it.
await exportReport();
const result = await FeedbackOtter.survey("sv_abc123def456");if (!result.shown) console.log(result.reason);Page rules don’t apply here, because your code picks the moment. Everything else does: the audience, how often it shows, and the gap between surveys.
When shown is false, reason is one of:
reason |
Meaning |
|---|---|
"not_signed_in" |
Surveys only go to signed-in users. Pass a token. |
"not_found" |
No survey has this ID, or it isn’t in the sv_… format. |
"paused" |
The survey is a draft or paused. |
"audience" |
This user isn’t in the survey’s audience. |
"answered" |
They’ve already answered it. |
"closed_recently" |
They closed it recently. |
"cooldown" |
They saw another survey recently. One survey every 14 days by default. |
"busy" |
Another survey is showing. |
"not_ready" |
init wasn’t called first. |
"error" |
Something else went wrong, such as a wrong public key or a network error. |
FeedbackOtter.on("unread", (count: number) => void): voidCalls your function with the number of unread updates in What’s new. It’s called once when they’ve loaded, then each time the count changes.
Use it to show a badge on your own button:
FeedbackOtter.on("unread", (count) => { const badge = document.querySelector("#feedback-badge"); badge.textContent = count > 0 ? String(count) : ""; badge.hidden = count === 0;});"unread" is the only event.
unread
Section titled “unread”FeedbackOtter.unread(): numberReturns the unread count now. It’s 0 until What’s new has loaded.
Most apps should use on("unread", fn), which also tells you when it changes.
TypeScript
Section titled “TypeScript”The widget doesn’t ship types. Add this declaration to your app:
type FeedbackOtterTab = "ideas" | "roadmap" | "changelog";
interface Window { FeedbackOtter: { init(options: { publicKey: string; token?: string; position?: "left" | "right"; launcher?: boolean; label?: string; theme?: "light" | "dark" | "auto"; board?: string; debug?: boolean; }): Promise<{ signedIn: boolean; reason?: string }>; open(tab?: FeedbackOtterTab): void; close(): void; identify(token: string | null): void; survey(id: string): Promise<{ shown: true } | { shown: false; reason: string }>; on(event: "unread", fn: (count: number) => void): void; unread?(): number; };}Console messages
Section titled “Console messages”The widget writes to the console only when something needs fixing.
Each message starts with [FeedbackOtter].
| Message | What to do |
|---|---|
Unknown public key … |
Copy the code again from Widgets in the dashboard. |
The sign-in token was rejected (…) |
The reason is in brackets. See Troubleshooting. |
No survey on /path: … |
Shown with debug: true. It says why no survey showed. |