Skip to main content

How to add Google reviews to your Astro website

Pull your Google reviews into your Astro site when it builds, with code you can paste and a prompt for your AI coding agent.

A
Written by Axel Lavergne

The best way to show Google reviews on an Astro site is to fetch them from a review API when the site builds, then rebuild on a schedule. The reviews land in your static HTML, so the page stays fast, search engines read them, and your API key never reaches the browser. The code is at the end, with a prompt you can hand to your AI coding agent. Before you paste it, four choices decide how well it works, so make them on purpose.

TLDR

  • The best way to show Google reviews on an Astro site is to fetch them from a review API when the site builds, so the reviews land in your static HTML and your API key never reaches the browser.

  • The Reviewflowz API pulls your Google reviews without Google Business Profile access or Google's approval, and the same API returns reviews from 200+ platforms in the same fields.

  • A Reviewflowz review widget is one iframe you customize freely, so you show always-fresh Google reviews on an Astro site without rebuilding it.

  • Reviewflowz tags let each page of your site ask for only the reviews that fit it, whether you tag reviews by hand or let AI tag them.

When to pull the reviews: at build, at page load, or in an iframe

You have three moments to get reviews onto a page, and each one trades speed, freshness and indexing differently.

Option

How it works

The tradeoff

At build

Astro fetches the reviews when the site builds and writes them into the HTML.

The fastest, most efficient and most effective way. Reviews are as fresh as your last build, so if you don't deploy often, rebuild on a daily or weekly cron.

Async at page load

A script loads the reviews after the page opens.

It hurts how the page gets indexed and read.

Iframe at page load

The page embeds a review widget in an iframe.

A decent tradeoff: always fresh, and still extremely fast, because the widget is loaded statically.

On Astro, build is the way to go. Code in a component's frontmatter runs when the site builds, so the reviews are plain HTML by the time anyone opens the page, and the key stays on your machine or your build server.

The iframe, without building it. The Reviewflowz review widget is one iframe you customize as much as you like. We keep it fresh and load it statically, so it stays extremely fast. You find it in Integrations, on the Widgets tab.

Where the reviews come from: Places API, Business Profile API, or a review API

Your choice of source sets how many reviews you can show and how much setup stands between you and the first one.

Source

What you get

What it takes

Google Places API

5 reviews, a random sample. They can be old, and they can be bad.

A Google Cloud API key.

Google Business Profile API

All the reviews of your own profile.

Approval first: you apply for access, and Google reviews requests within 14 days. Then OAuth, with owner or manager access to the profile.

A third-party review API

All your reviews, and reviews from other platforms too.

An API key. No Business Profile access needed.

Five reviews won't get you far. So in practice you need Business Profile access, through Google's approval, or a service that handles it for you.

No Business Profile access needed. The Reviewflowz API pulls your Google reviews without Business Profile access and without Google's approval, and the same API covers 200+ platforms in the same fields. Here is what it returns for Google.

Which reviews to show

Showing every review is the simplest choice, and rarely the best one. Decide these before you write any code:

  • All reviews, or a selection?

  • Selected by hand, or automatically?

  • With rules: a minimum rating, text required, newest first?

  • Filtered by topic, by location, by language, or by whatever fits the page?

The code below selects automatically, with rules: 6 reviews, 5 stars, with written text, still on Google, newest first. Each rule is one commented line, so you change it in place. Three more filters go further: language=en for reviews in one language, location=<id> for one of your locations, and tag=<id> for reviews you picked by hand or by AI tag.

Pick reviews per page with tags. In Reviewflowz you tag reviews by hand, or let AI tag them, and each page asks the API for its own tag. Lugg built its reviews page this way: visitors choose a use case and a city and read the reviews about exactly that, and about 6 to 9% of Lugg's new users land on a reviews page first. The testimonial feed guide shows the setup.

Reviews from Tripadvisor, Trustpilot and other platforms

If you want more than Google, you need a third-party review API here too. Some platforms, like Tripadvisor, forbid using your own reviews on your website. De facto, most people don't care. In general, it's best practice to link back to the original review, so those platforms don't bark.

The code below does that for Google: each review carries a url that opens it on Google, and the component shows it as a "Read on Google" link, so a visitor can check the review is real.

Other platforms, same call. With Reviewflowz, Tripadvisor, Trustpilot and the rest come through the same request: change platform, and the reviews come back in the same fields, each with its own url to link back to. The testimonial feed guide lists every filter.

Add Google reviews to your Astro site, step by step

Step 1. In Reviewflowz, open Review Sources and click New review source. Pick Google Maps, then search for your business and select it.

The New review source page with Google Maps selected and a business found by name

Step 2. Open Settings → Webhooks & API and click Create an API key. Name it, pick Read only, and create it. The API is part of the Premium plan.

The Create an API key window with the Read only permission selected

Step 3. Put the key in the .env file at the root of your project, as REVIEWFLOWZ_KEY. Add the same variable to your build server's environment variables, so the build can read it. Step 4. Create src/components/GoogleReviews.astro and paste this:

---
// src/components/GoogleReviews.astro
// Runs when the site builds: the key stays on your machine or build server,
// never in the page. Put REVIEWFLOWZ_KEY=rfz_live_... in your .env file.
const params = new URLSearchParams({
platform: "google_maps", // Google reviews only
rating_min: "5", // 5 stars
has_text: "true", // with written text
removed: "false", // still on Google
sort: "date", // newest first
limit: "6", // how many to show
});

const res = await fetch(`https://api.reviewflowz.com/v3/reviews?${params}`, {
headers: { Authorization: `Bearer ${import.meta.env.REVIEWFLOWZ_KEY}` },
});
if (!res.ok) throw new Error(`Reviewflowz API ${res.status}: ${await res.text()}`);
const { data: reviews } = await res.json();
---

<section class="google-reviews">
{reviews.map((review) => (
<figure>
<p aria-label={`${review.rating} out of 5 stars`}>{"★".repeat(Math.round(review.rating))}</p>
<blockquote>{review.text}</blockquote>
<figcaption>
{review.reviewer.name}
{review.url && <a href={review.url} target="_blank" rel="noopener">Read on Google</a>}
</figcaption>
</figure>
))}
</section>

Step 5. Import the component into any page and place <GoogleReviews /> where the reviews should appear. Step 6. Keep it fresh: rebuild the site on a daily or weekly schedule, or when a webhook tells your server a new review landed.

Prompt for your AI coding agent: Add a Google reviews section to this Astro site. Create src/components/GoogleReviews.astro that fetches GET https://api.reviewflowz.com/v3/reviews?platform=google_maps&rating_min=5&has_text=true&removed=false&sort=date&limit=6 with the header "Authorization: Bearer" plus the REVIEWFLOWZ_KEY environment variable. Fetch in the component frontmatter, so it runs at build time and the key never reaches the browser. Show each review's rating, text, reviewer name and a "Read on Google" link to its url. Follow the checklist in https://api.reviewflowz.com/v3/docs/guides/testimonial-feeds.

Want every option, filter and webhook in one place? Read Build a testimonial feed for every page. Running WordPress instead? Embed a review widget on WordPress.

Did this answer your question?