Skip to content

Instantly share code, notes, and snippets.

@AustineA
Last active July 31, 2023 10:44
Show Gist options
  • Save AustineA/5afeafca536a5db9f57bcf06e91e1a20 to your computer and use it in GitHub Desktop.
Save AustineA/5afeafca536a5db9f57bcf06e91e1a20 to your computer and use it in GitHub Desktop.
//Don't for get to install this cap package. It works for iOS and Android
import { RateApp } from "capacitor-rate-app";
//Firts ask the user to rate your app
const OpenRating = () => {
presentAlert({
header: "Do you love what you see 😍?",
backdropDismiss: false,
subHeader:
"An honest review will help me further improve your experience.",
cssClass: "ace-onboarding-alert",
buttons: [
{
text: "Yes 🥳",
role: "confirm",
//If yes call the native appstore rating modal
handler: () => {
handleRating();
},
},
{
text: "No 😔",
role: "cancel",
//If no save the last time you asked them for it and maybe a feedback form
handler: () => {
handleMaybeLater();
},
},
],
});
};
export const handleRating = async () => {
const value = {
lastOpened: new Date().toISOString(),
rated: true,
};
//This is what called native ratings
RateApp.requestReview();
await Preferences.set({ key: "rating", value: JSON.stringify(value) });
dataBase.rating = value;
};
export const handleMaybeLater = async () => {
const value = {
lastOpened: new Date().toISOString(),
rated: false,
};
dataBase.rating = value;
await Preferences.set({ key: "rating", value: JSON.stringify(value) });
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment