1.2.0 • Published 6 months ago

react-google-reviews v1.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

React Google Reviews

React Google Reviews Integration by Featurable

npm GitHub release (latest SemVer) Release Date License: MIT Pull Requests welcome


This React Google Reviews library is brought to you by Featurable, and the following documentation can also be found at https://featurable.com/docs/react-google-reviews


What is it? React component to display Google reviews on your website. This library is built with React and uses the Google Places API -or- the free Featurable API to fetch and display Google reviews on your website.

Documentation and examples at https://featurable.com/docs/react-google-reviews. Source code at https://github.com/Featurable/react-google-reviews.

Demo

Check out the live demo to see the React Google Reviews library in action.

Features

  1. Customizable: Choose from three layout options and customize the appearance of the reviews component
  2. SEO-friendly: Include JSON-LD structured data for search engines to index your reviews
  3. Responsive: Works on all devices and screen sizes
  4. Fast: Caches reviews for quick loading and improved performance
  5. Free: No cost to use the Featurable API for fetching reviews
  6. Fresh: Automatically updates with new reviews from Google every 48 hours (using Featurable API)
  7. Accessible: Built with accessibility in mind (WAI-ARIA compliant)
  8. Lightweight: Small bundle size and minimal dependencies

Installation

Install it from npm:

npm install react-google-reviews

Usage

Using the Featurable API (recommended)

Prerequisites: 1. Create a free Featurable account at https://featurable.com 2. Create a new Featurable widget 3. Click Embed > API and copy the widget ID

!NOTE The Featurable API is free to use and provides additional features like caching, automatic updates, and more reviews. To prevent abuse, the Featurable API is subject to rate limits.

Copy Featurable Widget ID

import { ReactGoogleReviews } from "react-google-reviews";
import "react-google-reviews/dist/index.css";

function Reviews() {
  // Create a free Featurable account at https://featurable.com
  // Then create a new Featurable widget and copy the widget ID
  const featurableWidgetId = "842ncdd8-0f40-438d-9c..."; // You can use "example" for testing

  return (
    <ReactGoogleReviews layout="carousel" featurableId={featurableWidgetId} />
  );
}

Using the Google Places API (limited to 5 reviews)

Prerequisites: 1. Create a Google Cloud Platform account at https://cloud.google.com 2. Create a new project and enable the Google Places API (old version) 3. Find the Google Place ID using the Place ID Finder

import { ReactGoogleReviews, dangerouslyFetchPlaceReviews } from "react-google-reviews";
import "react-google-reviews/dist/index.css";

/**
 * Example using NextJS server component
 */
async function ReviewsPage() {
  const placeId = "ChIJN1t_tDeuEmsRU..."; // Google Place ID
  const apiKey = "AIzaSyD..."; // Google API Key

  // IMPORTANT: Only fetch reviews server-side to avoid exposing API key
  const reviews = await dangerouslyFetchPlaceReviews(placeId, apiKey)

  return (
    // Carousel and other layouts require wrapping ReactGoogleReviews in a client component
    <ReactGoogleReviews layout="badge" reviews={reviews} />
  );
}

export default ReviewsPage;

!NOTE The Google Places API only returns the 5 most recent reviews. If you need more reviews or want to customize which reviews are returned, consider using the free Featurable API.

Configuration

Layout

There are three layout options currently available:

  1. Badge: Display a badge with the average rating, total reviews, and link to Google Business profile
 <ReactGoogleReviews layout="badge" featurableId={featurableWidgetId} />
  1. Carousel: An interactive carousel that displays reviews
 <ReactGoogleReviews layout="carousel" featurableId={featurableWidgetId} />

Carousel Layout

  1. Custom renderer: Render reviews using a custom function
<ReactGoogleReviews layout="custom" featurableId={featurableWidgetId} renderer={(reviews) => {
  return (
    <div>
      {reviews.map(({ reviewId, reviewer, comment }) => (
        <div key={reviewId}>
          <h3>{reviewer.displayName}</h3>
          <p>{comment}</p>
        </div>
      ))}
    </div>
  );
}} />

CSS Styling

For the carousel widget to work correctly, you must include the CSS file in your project:

import "react-google-reviews/dist/index.css";

To override the default styles, you can use the CSS props to add custom styles:

<style>
{`
.read-more {
  color: blue;
}
`}
</style>

<ReactGoogleReviews 
  layout="carousel"
  id="example"
  reviewReadMoreClassName="read-more"
  reviewReadMoreStyle={{ color: "blue" }}
/>

Please see the documentation for a list of CSS properties and examples of how to style the component.

View CSS classes and examples

Props

Common Props

PropTypeDescription
featurableIdstringFeaturable widget ID
reviewsGoogleReview[]Array of reviews to display, fetched using dangerouslyFetchPlaceReviews
layout"badge" \| "carousel" \| "custom"Layout of the reviews component
nameDisplay?"fullNames" \| "firstAndLastInitials" \| "firstNamesOnly"How to display names on reviews;
logoVariant?"logo" \| "icon" \| "none"How to display the Google logo
maxCharacters?numberWhen collapsed, the maximum number of characters to display in the review body
dateDisplay?"relative" \| "absolute"How to display the review date
reviewVariant?"card" \| "testimonial"Review layout variations
theme?"light" \| "dark"Color scheme of the component
structuredData?booleanWhether to include JSON-LD structured data for SEO
brandName?stringCustomize business name for structured data
productName?stringCustomize product name for structured data
productDescription?stringOptional product description for structured data
accessibility?booleanEnable/disable accessibility features
totalReviewCount?numberTotal number of reviews on Google Business profile. This is automatically fetched if using featurableId. Otherwise, this is required if passing reviews manually and structuredData is true.
averageRating?numberAverage rating for Google Business profile. This is automatically fetched if using featurableId. Otherwise, this is required if passing reviews manually and structuredData is true.

Carousel Props

PropTypeDescription
carouselSpeed?numberAutoplay speed of the carousel in milliseconds
carouselAutoplay?booleanWhether to autoplay the carousel
maxItems?numberMaximum number of items to display at any one time in carousel

Badge Props

PropTypeDescription
profileUrl?stringLink to Google Business profile, if manually fetching reviews via Place API. Using Featurable API will automatically supply this URL.

Custom Layout Props

PropTypeDescription
renderer?(reviews: ReactGoogleReview[]) => React.ReactNodeCustom rendering function

License

This project is licensed under the MIT License - see the LICENSE file for details. By using the Featurable API, you agree to the Featurable Terms of Service.

Acknowledgements

This library uses slick-carousel and react-slick for the carousel layout.

Contributing

Contributions are what make the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

1.2.0

6 months ago

1.1.2

6 months ago

1.1.1

8 months ago

1.1.0

8 months ago

1.0.0

8 months ago