Ask to Rate Your React Native App on Google Play Store or Apple App Store

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 command line interface to make our React Native App.

If you have previously installed a global react-native-cli package, please remove it as it may cause unexpected issues:

npm uninstall -g react-native-cli @react-native-community/cli

Run the following commands to create a new React Native project

npx react-native init ProjectName

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

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

Note If the above command is failing, you may have old version of react-native or react-native-cli installed globally on your pc. Try uninstalling the cli and run the cli using npx.

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

// Ask to Rate Your React Native App on Google Play Store or Apple App Store
// https://aboutreact.com/react-native-rate-this-app-feature/

// import React in our code
import React, {useState, useEffect} from 'react';

// import all the components we are going to use
import {
  SafeAreaView,
  Platform,
  StyleSheet,
  View,
  Linking,
  TouchableOpacity,
  Text,
  Alert,
} from 'react-native';

const GOOGLE_PACKAGE_NAME = 'agrawal.trial.yourfeedback';
const APPLE_STORE_ID = 'id284882215';

const App = () => {
  // Data Source for the SearchableDropdown
  const [count, setCount] = useState(5);
  const [isIntervalRunnig, setIsIntervalRunnig] = useState(false);

  useEffect(() => {
    startRatingCounter();
  }, []);

  const startRatingCounter = () => {
    //Initialize count by 5 to start counter for 5 sec
    setCount(5);
    tempcount = 5;
    if (!isIntervalRunnig) {
      setIsIntervalRunnig(true);
      let t = setInterval(() => {
        tempcount = tempcount - 1;
        console.log(tempcount);
        setCount(tempcount);
        if (tempcount == 0) {
          clearInterval(t);
          setIsIntervalRunnig(false);
          //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: () => openStore()},
              {
                text: 'No Thanks!',
                onPress: () => console.log('No Thanks Pressed'),
                style: 'cancel',
              },
            ],
            {cancelable: false},
          );
        }
      }, 1000);
    }
  };

  const openStore = () => {
    //This is the main trick
    if (Platform.OS != 'ios') {
      Linking.openURL(
        `market://details?id=${GOOGLE_PACKAGE_NAME}`,
      ).catch(
          (err) => alert('Please check for 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'));
    }
  };

  return (
    <SafeAreaView style={styles.container}>
      <View style={styles.container}>
        <Text style={styles.titleText}>
          Example to add rate this app feature in React Native
        </Text>
        {isIntervalRunnig ? (
          <Text style={styles.textStyle}>
            Rate this App alert will be in {count} second
          </Text>
        ) : null}
        {isIntervalRunnig ? null : (
          <TouchableOpacity
            onPress={startRatingCounter}
            activeOpacity={0.6}
            style={styles.buttonStyle}>
            <Text style={styles.buttonTextStyle}>
              Restart Rating Counter
            </Text>
          </TouchableOpacity>
        )}
      </View>
    </SafeAreaView>
  );
};

export default App;

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: 'white',
    padding: 10,
    justifyContent: 'center',
    textAlign: 'center',
  },
  titleText: {
    padding: 8,
    fontSize: 16,
    textAlign: 'center',
    fontWeight: 'bold',
  },
  textStyle: {
    fontSize: 15,
    marginTop: 30,
    textAlign: 'center',
  },
  buttonStyle: {
    width: '100%',
    paddingTop: 12,
    paddingBottom: 12,
    backgroundColor: '#00BCD4',
    borderRadius: 7,
    marginTop: 20,
  },
  buttonTextStyle: {
    color: '#fff',
    textAlign: 'center',
  },
});

To Run the React Native App

Open the terminal again and jump into your project using.

cd ProjectName

1. Start Metro Bundler

First, you will need to start Metro, the JavaScript bundler that ships with React Native. To start Metro bundler run following command:

npx react-native start

Once you start Metro Bundler it will run forever on your terminal until you close it. Let Metro Bundler run in its own terminal. Open a new terminal and run the application.

2. Start React Native Application

To run the project on an Android Virtual Device or on real debugging device:

npx react-native run-android

or on the iOS Simulator by running (macOS only)

npx react-native run-ios

Output Screenshots

iOS

Image   Image   Image

Android

Image   Image   Image

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 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. 🙂

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.