Vue app example

Quick installation guide to setup the BetterBugs Web SDK widget for your Vue applications.

How to install BetterBugs Web SDK in Vue apps

Here are the steps for it:

1

Generate an API key from Project Settings

Log in to your BetterBugs dashboard and generate an API key from Project Settings. You’ll need it to initialize the SDK in the following steps.

Steps for generating API key

2

Install BetterBugs Web SDK using npm/yarn

In your Vue project’s root terminal, run the following command to install the SDK files in your application using npm or yarn. We’ve used npm for this demo setup.

npm install @betterbugs/web-sdk

3

Initialize the SDK (with default UI)

Use the following initialization code in your Vue app’s component. Add your BetterBugs project API key to the code.

<!-- Vue Template -->
<template>
  <h1>BetterBugs Web SDK Widget | Vue</h1>
</template>

<script setup>
import { onMounted, onBeforeUnmount, ref } from "vue";

const bbInstanceRef = ref(null);

onMounted(async () => {
  if (typeof window !== "undefined") {
    const { default: Betterbugs } = await import("@betterbugs/web-sdk");
    const instance = new Betterbugs({
      // Replace with your BetterBugs Project API Key
      apiKey: "YOUR-API-KEY-GOES-HERE",
    });
    bbInstanceRef.value = instance;
  }
});

onBeforeUnmount(() => {
  bbInstanceRef.value?.destroy?.();
});
</script>
4

Customize the SDK widget UI (Optional)

You can customize the SDK with your brand colors and design from the initialization function:

<!-- Vue Template -->
<template>
  <h1>BetterBugs Web SDK Widget | Vue</h1>
</template>

<script setup>
// BetterBugs SDK Initialization Code
import { onMounted, onBeforeUnmount, ref } from "vue";

const bbInstanceRef = ref(null);

onMounted(async () => {
  if (typeof window !== "undefined") {
    const { default: Betterbugs } = await import("@betterbugs/web-sdk");
    const instance = new Betterbugs({
      // Replace with your BetterBugs Project API Key
      apiKey: "YOUR-API-KEY-GOES-HERE",

      // UI Customization Examples
      position: {
        top: "30px",
        right: "20px",
      },
      styles: {
        primaryColor: "#e41c38",
        primaryTextColor: "#fff",
        theme: "light",
      },
    });
    bbInstanceRef.value = instance;
  }
});

onBeforeUnmount(() => {
  bbInstanceRef.value?.destroy?.();
});
</script>
5

Test the setup

To test the setup, run your local dev server (http://localhost:5173/) with the following command (or with the one that you might be using):

npm run dev

The Web SDK widget should be available at the bottom right side of your app screen (with the default UI).

You're good to go.

Last updated

Was this helpful?