Add testimonials to an Astro site

Collect and show customer testimonials in Astro with SiteBackend - a small component and an inline script. Works with static builds and view transitions.

1 minUpdated

Add SiteBackend testimonials to an Astro site with a placeholder div and one script. It works with fully static builds (output: "static"), with no adapter or integration.

Get the IDs from your site's Testimonials tab in the dashboard: Collect for the form customers fill in (c_…), and Widgets for the wall, carousel, highlight or badge that shows approved ones (w_…).

Add a component

src/components/Testimonials.astro
---
interface Props {
  id: string;
}
const { id } = Astro.props;
---
 
<div data-sitebackend-widget={id}></div>
<script is:inline src="https://sitebackend.com/widget.js" async></script>

is:inline tells Astro to leave the script as it is instead of bundling it. It's fine for the script to appear more than once on a page; it only runs once.

Use the component anywhere:

src/pages/index.astro
---
import Testimonials from "../components/Testimonials.astro";
---
 
<h2>What our customers say</h2>
<Testimonials id="w_YOUR_WIDGET_ID" />
 
<h2>Leave a testimonial</h2>
<Testimonials id="c_YOUR_COLLECT_ID" />

View transitions

With Astro's ClientRouter, pages change without a full reload. The script notices widgets on the new page and loads them, so you don't need to do anything.

Local development

Widgets work on localhost:4321 even when your site has a domain set in the dashboard: localhost and 127.0.0.1 are always allowed. Preview or staging addresses on other domains are blocked, though. See sites.

For a contact form on the same site, see add a form to an Astro site.