Ratings

Ratings increase trust and help distinguish popular assets on your marketplace.

Creating a rating is as simple as:

stelace.ratings.create({
  score: 70,
  comment: 'Super!',
  targetId: 'usr_WHlfQps1I3a1gJYz2I3a',
  assetId: 'ast_2l7fQps1I3a1gJYz2I3a',
  bookingId: 'bkg_a3BfQps1I3a1gJYz2I3a'
})

Aggregated ratings statistics

A single rating isn’t enough to ascertain an asset’s popularity. Get all ratings corresponding to the asset and compute the average.

Stelace provides a convenient way to aggregate ratings in one request:

stelace.ratings.getStats({
  groupBy: 'assetId',
  assetId: 'ast_2l7fQps1I3a1gJYz2I3a'
})

To go further, you can also rank assets with:

stelace.ratings.getStats({
  groupBy: 'assetId',
  computeRanking: true
})

Advanced ratings

Let's say you want to rate users according to two criteria: friendliness and asset cleanliness. Those are two different types of ratings that will be combined.

Types of ratings

We have two types of independent ratings. The aggregated scores are separated for display.

stelace.ratings.create({
  score: 70,
  comment: 'Cool!',
  targetId: 'usr_WHlfQps1I3a1gJYz2I3a',
  assetId: 'ast_2l7fQps1I3a1gJYz2I3a',
  bookingId: 'bkg_a3BfQps1I3a1gJYz2I3a',
  label: 'friendliness'
})

stelace.ratings.create({
  score: 30,
  comment: 'The car was dirty',
  targetId: 'usr_WHlfQps1I3a1gJYz2I3a',
  assetId: 'ast_2l7fQps1I3a1gJYz2I3a',
  bookingId: 'bkg_a3BfQps1I3a1gJYz2I3a',
  label: 'cleanliness'
})

// Get two aggregated scores
stelace.ratings.getStats({
  groupBy: 'assetId',
  label: 'friendliness'
})

stelace.ratings.getStats({
  groupBy: 'assetId',
  label: 'cleanliness'
})

Multi-level ratings

Here users are still rated according to both previous criteria, combined to give a unique aggregated score:

stelace.ratings.create({
  score: 70,
  comment: 'Cool!',
  targetId: 'usr_WHlfQps1I3a1gJYz2I3a',
  assetId: 'ast_2l7fQps1I3a1gJYz2I3a',
  bookingId: 'bkg_a3BfQps1I3a1gJYz2I3a',
  label: 'main:friendliness'
})

stelace.ratings.create({
  score: 30,
  comment: 'The car was dirty',
  targetId: 'usr_WHlfQps1I3a1gJYz2I3a',
  assetId: 'ast_2l7fQps1I3a1gJYz2I3a',
  bookingId: 'bkg_a3BfQps1I3a1gJYz2I3a',
  label: 'main:cleanliness'
})

// Get a unique aggregated score
stelace.ratings.getStats({
  groupBy: 'assetId',
  label: 'main:*'
})