Add testimonials to a Nuxt site
Collect and show customer testimonials in Nuxt with SiteBackend - load the script from nuxt.config, add a small component, and it works with nuxt generate.
Add SiteBackend testimonials to a Nuxt site with a placeholder div and one script. It works with nuxt generate and server rendering alike, because everything loads in the visitor's browser.
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_…).
Load the script once
export default defineNuxtConfig({
app: {
head: {
script: [{ src: "https://sitebackend.com/widget.js", async: true }],
},
},
});To load it only on some pages, call useHead in those pages instead:
<script setup lang="ts">
useHead({ script: [{ src: "https://sitebackend.com/widget.js", async: true }] });
</script>Add a component
<script setup lang="ts">
defineProps<{ id: string }>();
</script>
<template>
<div :data-sitebackend-widget="id" />
</template>Use it anywhere:
<template>
<main>
<h2>What our customers say</h2>
<Testimonials id="w_YOUR_WIDGET_ID" />
<h2>Leave a testimonial</h2>
<Testimonials id="c_YOUR_COLLECT_ID" />
</main>
</template>Client-side navigation
When a visitor follows a NuxtLink, Nuxt changes the page without reloading it. 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:3000 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 contact form to a Nuxt site.