Ask for Google Play Store Rating

Hello guys, In this example, we will see how can you ask to rate your React Native App on Google Play Store or Apple App Store. This is a very easy but very useful example that can help you to make a meaningful feature in your app.

Integrating Rate this app feature in any app is very common which will help you to get feedback from your audience and to make your application better and better.

To open the Google Play Store or Apple App Store according to the platform

For this example, I have used an interval in the background to generate the alert after 5 seconds but you can use your own logic to show the alert. If the user clicks on agreed to rate your app you can use the below code snippet to open the platform-specific application store so that the user can rate your app.

I have used the concept of deep linking and used the Linking component to trigger the URL.

if (Platform.OS != 'ios') { //To open the Google Play Store Linking.openURL(`market://details?id=${GOOGLE_PACKAGE_NAME}`).catch(err => alert('Please check for the Google Play Store') ); } else { //To open the Apple App Store Linking.openURL( `itms://itunes.apple.com/in/app/apple-store/${APPLE_STORE_ID}` ).catch(err => alert('Please check for the App Store')); }

In this example, we will make a simple screen with some headings and a button to reset the interval counter running in the background. The idea is to make an alert asking to rate this app after a certain time and when the user clicks on the “Sure” button we will take the user to Google Play Store if the device is Android or on Apple App Store if the device is iOS.

I generally add rate this app feature in my applications so that I can get the ratings and reviews about my app on Google Play Store or Apple App Store. So let’s get started with the example to see how can you ask for the rating of your app on play store or app store.

To Make a React Native App

Getting started with React Native will help you to know more about the way you can make a React Native project. We are going to use react-native init to make our React Native App. Assuming that you have node installed, you can use npm to install the react-native-cli command line utility. Open the terminal and go to the workspace and run

npm install -g react-native-cli

Run the following commands to create a new React Native project

react-native init ProjectName

If you want to start a new project with a specific React Native version, you can use the --version argument:

react-native init ProjectName --version X.XX.X

react-native init ProjectName --version react-native@next

This will make a project structure with an index file named App.js in your project directory.

Now jump into your project using

cd ProjectName

Code to Ask for the Rating of your React Native App

Now Open App.js in any code editor and replace the code with the following code

App.js

//Example to add rate this app feature in React Native import React, { Component } from 'react'; //Import React import { Platform, StyleSheet, View, Linking, TouchableOpacity, Text, Alert, } from 'react-native'; //Import basic react native components const GOOGLE_PACKAGE_NAME = 'agrawal.trial.yourfeedback'; const APPLE_STORE_ID = 'id284882215'; export default class App extends Component { constructor() { super(); //Alert will be visible after 5 seconds this.state = { count: 5 }; } componentDidMount() { //Start counter for the rating this.startRatingCounter(); } startRatingCounter = () => { //Initialize count by 5 to start counter for 5 sec this.setState({ count: 5 }); let t = setInterval(() => { this.setState({ count: this.state.count - 1 }); if (this.state.count == 0) { clearInterval(t); //After 5 second ask for the rate this app Alert.alert( 'Rate us', 'Would you like to share your review with us? This will help and motivate us a lot.', [ { text: 'Sure', onPress: () => this.openStore() }, { text: 'No Thanks!', onPress: () => console.log('No Thanks Pressed'), style: 'cancel', }, ], { cancelable: false } ); } }, 1000); }; openStore = () => { //This is the main trick if (Platform.OS != 'ios') { Linking.openURL(`market://details?id=${GOOGLE_PACKAGE_NAME}`).catch(err => alert('Please check for the Google Play Store') ); } else { Linking.openURL( `itms://itunes.apple.com/in/app/apple-store/${APPLE_STORE_ID}` ).catch(err => alert('Please check for the App Store')); } }; render() { return ( <View style={styles.MainContainer}> <Text style={{ fontSize: 25, textAlign: 'center' }}> Example to add rate this app feature in React Native </Text> <Text style={{ fontSize: 15, marginTop: 30 }}> Rate this App alert will be in {this.state.count} second </Text> <TouchableOpacity onPress={this.startRatingCounter} activeOpacity={0.6} style={styles.button}> <Text style={styles.TextStyle}>Restart Reating Counter</Text> </TouchableOpacity> </View> ); } } const styles = StyleSheet.create({ MainContainer: { justifyContent: 'center', alignItems: 'center', flex: 1, padding: 20, }, button: { width: '80%', paddingTop: 12, paddingBottom: 12, backgroundColor: '#00BCD4', borderRadius: 7, marginTop: 20, }, TextStyle: { color: '#fff', textAlign: 'center', }, });

To Run the React Native App

cd ProjectName

react-native run-android

react-native run-ios (macOS only).

Output Screenshots

iOS

Android

Open the terminal again and jump into your project using.To run the project on an Android Virtual Device or on real debugging deviceor on the iOS Simulator by running

This is how you ask to rate your React Native app on Google Play Store or Apple App Store. If you have any doubts or you want to share something about the topic you can comment below or contact us here. There will be more posts coming soon. Stay tuned!

Hope you liked it. 🙂