Start from your own UI

Already asking your own quick question — a thumbs block, a star row at the end of a flow? Keep it. When the visitor answers, hand that answer to the study and the follow-up chat opens inline, right where your component is, already knowing what they picked. No launcher of ours is shown.

Load the script

Load the script in manual mode. It renders nothing by itself and needs no data-study; it only installs window.feedbackMango.startChat.

<script src="https://www.feedbackmango.com/widget.js" data-mode="manual" defer></script>

Start the chat

When the visitor answers your question:

const chat = window.feedbackMango.startChat({
  study: "pk_your_study_key",
  rating: "up",                       // the answer your UI collected
  container: document.querySelector("#feedback-chat"),
});

// Later, to remove it:
chat.destroy();
studyrequired
The study’s publishable key.
containerrequired
The element the chat goes into. It fills the element’s width, and replaces anything inside it.
ratingoptional
The answer your UI collected, as the study’s rating values: up or down for thumbs, 1…max for a scale or reaction faces, 0…10 for NPS. The chat opens with it already answered and asks the follow-up.
heightoptional · default 460
The chat’s height in pixels. Messages scroll inside it.
metaoptional
Metadata for this response, merged over window.feedbackMango.meta (see metadata).

It returns a handle with destroy(). Calling startChat again for the same container replaces the chat, so a visitor who changes their mind starts over with the new answer. Nothing is stored until the chat sends its first message.

Set the study up to match

The study’s interview style must be rating first, with the same rating type your UI asks — otherwise the answer you pass has nothing to seed. Use your own question as the study’s rating prompt, so the transcript reads the way the visitor saw it. When something doesn’t fit, startChat says so in the browser console.

React and Next.js

A client component does the whole job:

"use client";
import Script from "next/script";
import { useEffect, useRef, useState } from "react";

declare global {
  interface Window {
    feedbackMango?: {
      startChat?: (options: {
        study: string;
        rating?: string;
        container: Element;
        height?: number;
        meta?: Record<string, string | number | boolean>;
      }) => { destroy(): void };
    };
  }
}

/** Mount once the visitor has answered; re-renders with a new rating restart the chat. */
export function FeedbackChat({ rating }: { rating: "up" | "down" }) {
  const container = useRef<HTMLDivElement>(null);
  const [ready, setReady] = useState(false);

  useEffect(() => {
    if (!ready || !container.current) return;
    const chat = window.feedbackMango?.startChat?.({
      study: "pk_your_study_key",
      rating,
      container: container.current,
    });
    return () => chat?.destroy();
  }, [ready, rating]);

  return (
    <>
      <Script
        src="https://www.feedbackmango.com/widget.js"
        data-mode="manual"
        strategy="afterInteractive"
        onReady={() => setReady(true)}
      />
      <div ref={container} />
    </>
  );
}

Without the script

Without the script at all, the same chat loads as a plain iframe. It works, but the response won’t record which page it came from or any meta — those travel through the script. Keep referrerpolicy="origin": it lets the chat check your domain against the allowlist in every browser.

<iframe
  src="https://www.feedbackmango.com/embed/pk_your_study_key?layout=inline&rating=up"
  referrerpolicy="origin"
  style="width:100%;height:460px;border:0"
  title="Feedback"
></iframe>