KjellConnelly / react-native-rate

Send your app users to Apple App Store, Google Play, Amazon, or other using the newest APIs
635 stars 100 forks source link

react-native-rate

React Native Rate is a cross platform solution to getting users to easily rate your app.

Stores Supported:
Apple App Store Google Play Amazon Other Android Markets All Others
Building your app for a different Android store, you can provide your own URL If your platform isn't one of the others, you can input a fallback url to send users to instead

Getting started

$ npm i react-native-rate

Mostly automatic installation (new way with react-native v0.60+)

cd ios && pod install && cd ../

Mostly automatic installation (old way)

$ react-native link react-native-rate

Manual installation

iOS

Without CocoaPods
  1. In XCode, in the project navigator, right click LibrariesAdd Files to [your project's name]
  2. Go to node_modulesreact-native-rate and add RNRate.xcodeproj
  3. In XCode, in the project navigator, select your project. Add libRNRate.a to your project's Build PhasesLink Binary With Libraries
  4. Run your project (Cmd+R)<
Using CocoaPods

Add the following to your Podfile (and run pod install):

pod 'RNRate', :path => '../node_modules/react-native-rate'

Other Platforms

Android, Windows, etc don't use any native code. So don't worry! (There still is linking to Android if you do react-native link. We only left this here so that we can call native code if there is native code to call someday.)

iOS Specific:

Users using iOS 10.3 (from 2017) and above can now use SKStoreReviewController to open a Rating Alert right from within their app. There are a few gotchas to using this ReviewController though:

Android Specific for in-app popups:

Example

import React from 'react'
import { View, Button } from 'react-native'
import Rate, { AndroidMarket } from 'react-native-rate'

export default class ExamplePage extends React.Component {
  constructor(props) {
    super(props)
    this.state = {
      rated: false
    }
  }

  render() {
    return (
      <View>
        <Button title="Rate App" onPress={()=>{
          const options = {
            AppleAppID:"2193813192",
            GooglePackageName:"com.mywebsite.myapp",
            AmazonPackageName:"com.mywebsite.myapp",
            OtherAndroidURL:"http://www.randomappstore.com/app/47172391",
            preferredAndroidMarket: AndroidMarket.Google,
            preferInApp:false,
            openAppStoreIfInAppFails:true,
            fallbackPlatformURL:"http://www.mywebsite.com/myapp.html",
          }
          Rate.rate(options, (success, errorMessage)=>{
            if (success) {
              // this technically only tells us if the user successfully went to the Review Page. Whether they actually did anything, we do not know.
              this.setState({rated:true})
            }
            if (errorMessage) {
              // errorMessage comes from the native code. Useful for debugging, but probably not for users to view
              console.error(`Example page Rate.rate() error: ${errorMessage}`)
            }
          })
        }} />
      </View>
    )
  }
}

options:

There are lots of options. You can ignore some of them if you don't plan to have them on that App Store.

Option Description
AppleAppID When you create an app in iTunes Connect, you get a number that is around 10 digits long.
GooglePackageName Created when you create an app on Google Play Developer Console.
AmazonPackageName Create when you create an app on the Amazon Developer Console.
preferredAndroidMarket This only matters if you plan to deploy to both Google Play and Amazon or other markets. Since there is no reliable way to check at run time where the app was downloaded from, we suggest creating your own build logic to decipher if the app was built for Google Play or Amazon, or Other markets. Available Options: AndroidMarket.Google, AndroidMarket.Amazon, Other
preferInApp If true and user is on iOS, tries to use SKStoreReviewController. If true and user is on Android, it will try to use the native UI. If fails for whatever reason, or user is on another platform, opens the App Store externally. Default false
fallbackPlatformURL if ((Platform.OS != 'ios) && (Platform.OS != 'android')), open this URL.
inAppDelay (IOS ONLY) Delay to wait for the InApp review dialog to show (if preferInApp == true). After delay, opens the App Store if the InApp review doesn't show. Default 3.0
openAppStoreIfInAppFails If preferInApp = true but the native iOS and Android UI failed, opens the store externally. Default true
Options Example1
// iOS only, not using in-app rating (this is the default)
const options = {
  AppleAppID:"2193813192",
}
Options Example2
// Android only, able to target both Google Play & Amazon stores. You have to write custom build code to find out if the build was for the Amazon App Store, or Google Play
import {androidPlatform} from './buildConstants/androidPlatform' // this is a hypothetical constant created at build time
const options = {
  GooglePackageName:"com.mywebsite.myapp",
  AmazonPackageName:"com.mywebsite.myapp",
  preferredAndroidMarket: androidPlatform == 'google' ? AndroidMarket.Google : AndroidMarket.Amazon
}
Options Example3
// targets only iOS app store and Amazon App Store (not google play or anything else). Also, on iOS, tries to open SKStoreReviewController.
const options = {
  AppleAppID:"2193813192",
  AmazonPackageName:"com.mywebsite.myapp",
  preferredAndroidMarket:AndroidMarket.Amazon,
  preferInApp:true,
}
Options Example4
// targets iOS, Google Play, and Amazon. Also targets Windows, so has a specific URL if Platform isn't ios or android. Like example 2, custom build tools are used to check if built for Google Play or Amazon. Prefers not using InApp rating for iOS.
import {androidPlatform} from './buildConstants/androidPlatform' // this is a hypothetical constant created at build time
const options = {
  AppleAppID:"2193813192",
  GooglePackageName:"com.mywebsite.myapp",
  AmazonPackageName:"com.mywebsite.myapp",
  preferredAndroidMarket: androidPlatform == 'google' ? AndroidMarket.Google : AndroidMarket.Amazon,
  fallbackPlatformURL:"ms-windows-store:review?PFN:com.mywebsite.myapp",
}
Options Example5
// targets 4 different android stores: Google Play, Amazon, and 2 fake hypothetical stores: CoolApps and Andrule
import {androidPlatform} from './buildConstants/androidPlatform' // this is a hypothetical constant created at build time
const options = {
  GooglePackageName:"com.mywebsite.myapp",
  AmazonPackageName:"com.mywebsite.myapp",
  preferredAndroidMarket: (androidPlatform == 'google') ? AndroidMarket.Google : (androidPlatform == 'amazon' ? AndroidMarket.Amazon : AndroidMarket.Other),
  OtherAndroidURL:(androidPlatform == 'CoolApps') ? "http://www.coolapps.net/apps/31242342" : "http://www.andrule.com/apps/dev/21312"
}
Options Example6
// Tries to open the SKStoreReviewController in app for iOS only, but if it fails, nothing happens instead of opening the App Store app after 5.0s. Technically, you do not need to add inAppDelay in options below because it has a default value. I am only writing it below to show the difference between openAppStoreIfInAppFails true/false values and what would happen after the inAppDelay.
const options = {
  AppleAppID:"2193813192",
  preferInApp:true,
  inAppDelay:5.0,
  openAppStoreIfInAppFails:false,
}

About Package Names (Google Play & Android) and Bundle Identifiers (Apple):

If you want to keep the same package name and bundle identifier everywhere, we suggest the following:

I’m new to mobile development. Why is rating important?

Though this isn’t specific to this module, some new developers are not quite sure why rating is important.

First off, rating and reviews are technically two different things. Rating being typically a 1-5 star rating, and a review being text that a user writes. Both are important for different reasons.

A higher rating increases your app’s chance of being shown in search results. Some even think that ANY rating will increase your app’s chance, though I don’t know the algorithm. Some users also look at stars and weigh their decision to download or not partially on this metric.

Likewise, reviews give both developers and users good feedback on how the app is doing. Developers can use these reviews as quotes in their app description, and in some stores even reply to reviews (iOS, Google Play, Amazon, and possibly others).

Getting good reviews and good ratings will increase your app’s popularity and downloads. Of course, getting a user to rate your app is mainly about maximizing your probability of success, vs annoying them. There are a lot of articles online on how best to get users to rate your app, but we won’t go into them here.

Your job as the developer, using this module, is to create an experience for the user, and at the right time, ask them to rate. This can be in the form of a pop up, a perpetual button on a settings menu, or after being a level in a game. It’s up to you.

What does this module do when you call rate()

For those that don’t want to read through the code, this module will open a link to the App Store of your choosing based on your options and user’s device. The App Store will be on your app’s page. If possible, it will be on the Ratings/Reviews section.

If possible, the App Store will be opened in the native app for the Store (ie the App Store app). If not possible, it will be opened from the user’s browser.

The only time when the above is not true is for iOS when you setup your options to use the SKStoreReviewController. In this case, a native UI pop up (created by Apple) is displayed from within you app.

Rate.rate() success?

Success in most cases is self explanatory. But for the iOS SKStoreReviewController case:

--- success !success
{preferInApp:true} and the SKStoreReviewController successfully opens ---
{preferInApp:true, openAppStoreIfInAppFails:true} and the SKStoreReviewController fails to open, but opens the App Store App ---
{preferInApp:true, openAppStoreIfInAppFails:false} and the SKStoreReviewController fails to open, and does not open the App Store App ---

This used to work, now I'm getting an error message with react-native-rate v1.2.0

I moved the podspec file outside of the ios directory. If you use pods before this version, you may have set paths to ios/RNRate.podspec. You may need to change that back.

preferInApp works in iOS development, but not via TestFlight!

True. According to Apple's documentation, the SKStoreReviewController should work as expected while in development and production modes, but not one that is distributed via TestFlight.

Future Plans

I plan to add default support for Windows, but haven't personally built any windows app for a few years now. So will do it when it's actually relevant.