AppReviewService Example

Here’s a minimal but complete example of a Lightning web component that uses AppReviewService to request an app review.

The component’s HTML template contains a button to request an app review.

1<!-- appReviewFeedbackServiceExample.html -->
2<template>
3  <lightning-card title="App Review Feedback" icon-name="custom:custom14">
4    <div class="slds-var-m-around_medium">
5      <div>Hello, {name}!</div>
6      <div class="slds-var-m-top_x-small">
7        <lightning-button
8          label="Request App Review"
9          value="Action"
10          onclick="{handleBeginClick}"
11        ></lightning-button>
12      </div>
13    </div>
14  </lightning-card>
15</template>

Each phase of the app review request writes a console message.

1// appReviewServiceExample.js
2import { LightningElement, wire } from "lwc";
3import { getAppReviewService } from "lightning/mobileCapabilities";
4import { getRecord, getFieldValue } from "lightning/uiRecordApi";
5import Id from "@salesforce/user/Id";
6import NAME_FIELD from "@salesforce/schema/User.Name";
7const fields = [NAME_FIELD];
8const userName = getFieldValue(this.user.data, NAME_FIELD);
9
10export default class AppReviewFeedbackService extends LightningElement {
11  userId = Id;
12  user;
13
14  @wire(getRecord, { recordId: "$userId", fields })
15  user;
16
17  get name() {
18    return userName || "Guest User";
19  }
20
21  handleBeginClick(event) {
22    const myAppReviewService = getAppReviewService();
23    if (myAppReviewService.isAvailable()) {
24      myAppReviewService
25        .requestAppReview(null)
26        .then(() => {
27          // Do something with success response
28          console.log("App review request complete successfully");
29        })
30        .catch((error) => {
31          // Handle cancellation and scanning errors here
32          console.error(error);
33        });
34    } else {
35      // Handle with message, error, beep, and so on
36      console.error("App Review service not available");
37    }
38  }
39}

See Also