For the complete documentation index, see llms.txt. This page is also available as Markdown.

React app example

Quick installation guide to setup the BetterBugs feedback widget for your React applications.

How to Install BetterBugs Feedback Widget in React apps

lightbulb

PREREQUISITES

Here’s what you need to set up the feedback widget:

  • React app.

  • Workspace-Wide API Key.

  • BetterBugs Project API key.

Here are the steps for it:

1

Generate API key and Project ID

Log in to your BetterBugs.io dashboard and generate API key and project ID from Workspace Settings. You’ll need it them initialize the feedback widget in the following steps.

Steps for Generating API Key and Project ID

2

Install BetterBugs Web SDK using npm/yarn

In your React 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@latest

yarn add @betterbugs/web-sdk@latest

Make sure to install npm/yarn package the latest BetterBugs Web SDK version (0.0.44):

3

Initialize the Widget (with default UI)

Use the following initialization code in your React app’s component. Don’t forget to add your Workspace API Key and Project ID in the function:

import { useEffect, useRef } from "react";

function App() {
  // Initialization Code
  const bbInstanceRef = useRef(null);
  useEffect(() => {
    let isMounted = true;
    const initBetterbugs = async () => {
      if (typeof window !== "undefined") {
        const { default: Betterbugs } = await import("@betterbugs/web-sdk");
        const instance = new Betterbugs({
          apiKey: "YOUR_API_KEY_HERE", // Workspace API key
          projectId: "YOUR_PROJECT_ID_KEY_HERE", // Project to report bugs to
        });
        if (isMounted) {
          bbInstanceRef.current = instance;
        }
      }
    };

    initBetterbugs();
    return () => {
      isMounted = false;
      bbInstanceRef.current?.destroy?.();
    };
  }, []);

  // Example Component
  return (
    <>
      <h1>BetterBugs Web SDK Widget | React</h1>
    </>
  );
}

export default App;
4

Customize the Widget UI (Optional)

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

import { useEffect, useRef } from "react";

function App() {
  // Initialization Code
  const bbInstanceRef = useRef(null);

  useEffect(() => {
    let isMounted = true;
    const initBetterbugs = async () => {
      if (typeof window !== "undefined") {
        const { default: Betterbugs } = await import("@betterbugs/web-sdk");
        const instance = new Betterbugs({
          apiKey: "YOUR_API_KEY_HERE", // Workspace API key
          projectId: "YOUR_PROJECT_ID_KEY_HERE", // Project to report bugs to

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

    initBetterbugs();
    return () => {
      isMounted = false;
      bbInstanceRef.current?.destroy?.();
    };
  }, []);

  // Example Component
  return (
    <>
      <h1>BetterBugs Web SDK Widget | React</h1>
    </>
  );
}

export default App;
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 feedback widget should be available at the bottom right side of your app screen (with the default UI).

You're good to go.

Last updated