Skip to content
ScrapeField

Blog · Guides ·

How a business compares with its neighbours

Two calls show where a business stands on Google against the same kind of business nearby: its rating, its number of reviews, and who is ahead of it.

ScrapeField

A rating means little on its own. A 4.4 is good for a car repair shop and weak for a bakery in a street of 4.8s. This guide puts one business beside the businesses of the same kind around it, and shows where it stands on rating and on the number of reviews.

The business

GET /v1/google-maps/place gives the listing: its category, its location pin, its rating and its user_ratings_total. It costs 3 credits.

const placeId = 'ChIJN1t_tDeuEmsRUsoyG83frY4'; // the business to compare, from a search or a Maps URL
const headers = { Authorization: `Bearer ${process.env.SCRAPEFIELD_KEY}` };

const res = await fetch(`https://api.scrapefield.com/v1/google-maps/place?place_id=${placeId}`, { headers });
const body = await res.json();
if (!res.ok) throw new Error(body.error.message); // a failed call is not charged
const mine = body.data;

Its neighbours

GET /v1/google-maps/places searches around a point: give it the business’s category as the query, its pin as lat and lng, and a radius_m. A page of up to 20 places costs 3 credits. A listing without a pin cannot be searched around; search by its address instead.

const neighbours = [];
if (mine.location) {
  const near = new URLSearchParams({
    query: mine.category ?? mine.categories[0] ?? mine.name,
    lat: String(mine.location.lat),
    lng: String(mine.location.lng),
    radius_m: '2000',
  });
  const res = await fetch(`https://api.scrapefield.com/v1/google-maps/places?${near}`, { headers });
  const body = await res.json();
  if (res.ok) neighbours.push(...body.data.filter((p) => p.place_id !== mine.place_id && p.business_status === 'OPERATIONAL'));
} else {
  console.log('This listing has no pin: search by its address instead');
}

Where it stands

const rated = [mine, ...neighbours].filter((p) => p.rating !== null);
const byRating = [...rated].sort((a, b) => b.rating - a.rating || (b.user_ratings_total ?? 0) - (a.user_ratings_total ?? 0));
const byReviews = [...rated].sort((a, b) => (b.user_ratings_total ?? 0) - (a.user_ratings_total ?? 0));
const place = (list) => list.findIndex((p) => p.place_id === mine.place_id) + 1;

if (mine.rating === null) console.log(`${mine.name} has no ratings yet`);
else console.log(`${mine.name}: ${mine.rating} from ${mine.user_ratings_total} ratings. By rating, ${place(byRating)} of ${rated.length} nearby; by reviews, ${place(byReviews)}.`);
for (const p of byRating.slice(0, 5)) console.log(`  ${p.rating}  ${p.user_ratings_total} ratings  ${p.name}`);

Read the two orders together. A neighbour with a 4.9 from 12 ratings is not ahead of a 4.6 from 900: a few more one-star reviews would move the first a long way, and the second hardly at all. And the number of ratings is shown beside the stars wherever the business is listed.

Every month

One business costs 6 credits a check: the place and one page of neighbours. Ten businesses checked every month cost 60 credits, about $0.56 a year on the smallest pack. To see what the reviews ahead of you say, read the neighbours’ newest reviews. To follow the score of each one week by week, see Watch a business’s Google rating every week.