# Add the feedback widget to a Vue app

Canonical: https://feeblo.com/install/vue Markdown mirror of: https://feeblo.com/install/vue

The core SDK has no framework dependency, so a Vue component mounts it with two lifecycle hooks. Initialize in `onMounted`, destroy in `onBeforeUnmount`, and keep the handle in a plain variable.

Try it: https://app.feeblo.com

## Before you start

- **A Vue 3 project.** The examples use `script setup` and the Composition API. Options API components can call the same functions from `mounted` and `beforeUnmount`.
- **No Vue package.** feeblo publishes `@feeblo/sdk` and `@feeblo/sdk-react`. There is no Vue package. The core SDK has no framework dependency, so a Vue component imports it directly.
- **Your organization ID.** Copy it from Settings → Widget → Installation. `Feeblo.init` takes it as the first argument.
- **Your board and user.** Posts submit to a board, so pick one with `defaultBoard`. Have the signed-in user's `id` ready to identify them.

## Mount the widget from a component

Each step adds one piece to the same component. Run them in order and refresh the page after each one.

1. **Install the core SDK.** Add the framework-free package. It ships an ESM build and a UMD build, and it has no runtime dependencies.

   ```bash
   npm install @feeblo/sdk
   ```

2. **Initialize the widget in `onMounted`.** Mount the widget once inside the component. The `onMounted` hook runs only in the browser, so the SDK never touches `document` during server rendering.

   ```vue
   <script setup lang="ts">
   import { Feeblo } from "@feeblo/sdk";
   import { onBeforeUnmount, onMounted } from "vue";

   let widget: ReturnType<typeof Feeblo.init>;

   onMounted(() => {
     widget = Feeblo.init("org_123", { placement: "bottom-right" });
   });

   onBeforeUnmount(() => {
     widget?.destroy();
   });
   </script>
   ```

3. **Open the widget from a button.** Call `open` on the handle from a template handler. The handle is a plain variable, not a ref, because it is not UI state.

   ```vue
   <script setup lang="ts">
   import { Feeblo } from "@feeblo/sdk";
   import { onBeforeUnmount, onMounted } from "vue";

   let widget: ReturnType<typeof Feeblo.init>;

   onMounted(() => {
     widget = Feeblo.init("org_123");
   });

   function openFeedback() {
     widget?.open();
   }

   onBeforeUnmount(() => {
     widget?.destroy();
   });
   </script>

   <template>
     <button type="button" @click="openFeedback">Give feedback</button>
   </template>
   ```

4. **Identify the user.** Send the user after the widget loads. Call `identify` again whenever the user's details change. Only `id` is required.

   ```ts
   onMounted(() => {
     widget = Feeblo.init("org_123");

     Feeblo.identify({
       id: user.id,
       email: user.email,
       name: user.name,
     });
   });
   ```

5. **Subscribe to widget events.** `on` returns an unsubscribe function. Store it and call it before unmount so the listener does not outlive the component.

   ```ts
   import { Feeblo } from "@feeblo/sdk";
   import { onBeforeUnmount, onMounted } from "vue";

   let off: (() => void) | undefined;

   onMounted(() => {
     off = Feeblo.on("feedbackSubmitted", (event) => {
       console.log(event.detail.data);
     });
   });

   onBeforeUnmount(() => {
     off?.();
   });
   ```

6. **Or use a plain DOM trigger.** The SDK scans the page for `data-feeblo-feedback` elements, so a template button needs no handler at all.

   ```vue
   <template>
     <button data-feeblo-feedback data-feeblo-board="roadmap">
       Give feedback
     </button>
   </template>
   ```

7. **Confirm the widget loaded.** Add `debug` for the first run. The SDK logs a banner with the org ID and base URL, then trigger bindings and events.

   ```ts
   onMounted(() => {
     widget = Feeblo.init("org_123", {
       placement: "bottom-right",
       debug: true,
     });
   });
   ```

## What you should see

- **A launcher in the corner.** The `placement` option renders a launcher 20px from the bottom corner you picked. Leave it out and open the widget from your own button.
- **An overlay over the app.** Clicking the button opens the widget in an iframe over the page. Your router does not navigate, and the page behind it stays put.
- **Identity on the post.** A submission lands on the board with the id, email, and name you sent through `identify`.
- **Clean teardown.** When the component unmounts, `destroy` removes the iframe, the launcher, and the listeners the SDK registered.

## Send a signed token

An identify call without a token can be faked from the browser console. Sign a JWT on your server with your organization secret and pass it as `token`. Feeblo verifies it and attaches the post to a real contact.

Keep the token short-lived. Mint a fresh one per page render or session, then pass it into the component as a prop. The secret never leaves the server.

```ts
Feeblo.identify({
  id: user.id,
  email: user.email,
  name: user.name,
  token, // signed on your server
});
```

Only `id` is required. Email, name, and token are optional, and the token is what makes the identity trustworthy. Widget SSO documents the claims and the signing call: https://docs.feeblo.com/developers/widget-sso

## Vue rules that matter

The SDK is not reactive. Treat it as a browser resource with a lifecycle.

- **Init in `onMounted`, never at module scope.** Module scope runs during server rendering, where `window` and `document` do not exist.
- **Keep the handle in a plain `let`.** The widget is not reactive state. A ref would proxy an object your template never renders.
- **Destroy on unmount.** The SDK keeps one global widget instance. `destroy` releases the iframe and the listener set.
- **Unsubscribe your listeners.** `Feeblo.on` returns a function. Call it so a listener from an old component cannot fire.
- **One instance per page.** The SDK keeps a single global widget, so init belongs in one long-lived component, not in every view.
- **Markup triggers work anywhere.** Any element with `data-feeblo-feedback` opens the widget, including elements outside the component tree.

## Common problems

These four are about where the code runs, not about the widget.

- **`document is not defined`.** `Feeblo.init` ran at module scope or during SSR. Move the call into `onMounted`.
- **Two widgets appear.** The component is mounted twice, for example in a layout and a page. Mount it once above your routes.
- **The button does nothing.** The handler ran before `onMounted` assigned the handle, or the package did not load. Log `widget` to check.
- **The widget survives navigation.** `onBeforeUnmount` did not call `destroy`, so the iframe outlived its component. Add the cleanup.

## Where to go next

The widget options, the identity object, and the signed token are the same in every framework. Only the mounting code changes. If you move to React later, the provider wraps the same calls.

- All install paths: React, Next.js, Vue, and plain HTML. https://feeblo.com/install
- Plain HTML setup. https://feeblo.com/install/html

A template trigger needs no handler. The SDK rescans the page for triggers every second, so a button rendered by `v-if` or `v-for` binds after it appears.

```html
<button data-feeblo-feedback data-feeblo-plan="pro">Give feedback</button>
```

## SDK docs

- Quickstart: https://docs.feeblo.com/developers/quickstart
- Every widget option: https://docs.feeblo.com/developers/configuration
- Triggers and events: https://docs.feeblo.com/developers/triggers-and-events
- Identify users: https://docs.feeblo.com/developers/identity
