Git Product home page Git Product logo

react-native-rating-requestor's Introduction

react-native-rating-requestor

A React Native component to prompt users for a rating after positive interactions

The Rating Requestor is a very simple JS module that you simply instantiate and call from time to time, as your user performs actions that result in a "happy path." For example, maybe your users get a smile on their face every time they save money with your app, beat a level, or clear out their inbox. After a certain number of these positive events, it might be a good time to ask the user for a review.

Installation

npm i --save react-native-rating-requestor

You'll probably also want to install the peer dependencies as well:

npm i --save @react-native-async-storage/async-storage react-native-store-review

You may also need to link in or pod install the native modules from the peer dependencies, which varies depending on the version of React Native you are using.

(If anyone has a better way of managing the native modules of these peer dependencies, definitely open an issue and let me know!)

Usage

Import and create a new instantiation of the Rating Requestor somewhere in the main portion of your application:

    import RatingRequestor from 'react-native-rating-requestor';
    const RatingTracker = new RatingRequestor('[your apps store ID]');

    const MyApp = () => {...};

When a positive UX event occurs, let the Rating Requestor know so that it can keep track of these:

if (user_saved_the_world) {
  RatingTracker.handlePositiveEvent();
}

The example above is used without callback. A callback can be provided that reports on result of the handling. The callback accepts two parameters: the first indicates whether the request dialog appeared (boolean), and the second returns the user decision (string: 'decline', 'delay', or 'accept').

if (user_saved_the_world) {
  RatingTracker.handlePositiveEvent(function (didAppear, userDecision) {
    if (didAppear) {
      switch (userDecision) {
        case "decline":
          console.log("User declined to rate");
          break;
        case "delay":
          console.log("User delayed rating, will be asked later");
          break;
        case "accept":
          console.log(
            "User accepted invitation to rate, redirected to app store"
          );
          break;
      }
    } else {
      console.log(
        "Request popup did not pop up. May appear on future positive events."
      );
    }
  });
}

If enough positive events have occurred (defined by the timingFunction, see "Configuration") then a rating dialog will appear. The user can rate the app or decline to rate, in which case they won't be bothered again, or can choose to maybe do so later, in which case the Rating Requestor will keep on tracking positive event counts.

You can also trigger the rating dialog to appear immediately by invoking RatingTracker.showRatingDialog([callback]). If you have a "Rate this App" button or link in an about page or something in your app, this would be a good place to use that.

iOS Native Dialog

When on iOS 10.3+, if the user agrees to leave a review then it will trigger the native star picker dialog (SKStoreReviewController) built in to iOS. This is a definite improvement! However it's not foolproof. Because iOS ultimately makes the decision whether to show the dialog or not, there is a small chance that the user may agree to review the app, but because they've already seen the dialog recently, it may not appear. Caveat emptor. In most cases, though, this should work out better than before, because it immediately shows the star buttons instead of linking to the store first.

This is accompished by using react-native-store-review, a peer dependency of this package.

Configuration

All configuration occurs on the construction of a new RatingRequestor.

const myRR = new RatingRequestor(appStoreId, [options]);

You must pass in a string as the first parameter, which is the app store ID of your application. Optionally, but highly suggested, is a second parameter: a set of options to customize the request dialog and the timing of the dialog. This object follows this pattern:

  {
    title: {string},
    message: {string},
    actionLabels: {
      decline: {string},
      delay: {string},
      accept: {string}
    },
    buttonOrder: {
      ios: [buttonTypes],
      android: [buttonTypes],
    },
    shouldBoldLastButton: {boolean},
    storeAppName: {string},
    storeCountry: {string},
    timingFunction: {func(currentCount) => boolean}
  }
  • title: A string used as the title for the dialog (e.g., "Please rate me!")
  • message: The message you'd like to show the user (e.g., "If you are loving [my app's name], would you please leave me a positive review?")
  • actionLabels: An object with three properties (all required if you don't want weird blanks or OKs):
    • decline: The "no thanks, I don't want to ever rate this" button label
    • delay: The "maybe I'll rate this later if I'm feeling charitable" button label
    • accept: The "oh my gosh I love this app so much so I'll rate it right now" button label
  • buttonOrder: An object with platform keys (ios and android or others), with the value of each key being an array of length 3 containing buttonType values, which can be imported from the package. This defines the order the buttons will appear on the dialog. The default order for both platforms is as follows:
    • [buttonTypes.NEGATIVE_DECLINE, buttonTypes.NEUTRAL_DELAY, buttonTypes.POSITIVE_ACCEPT]
  • shouldBoldLastButton: If passed as true, the third button of the modal will have a more prominent style. This option currently only modifies iOS styling
  • storeAppName: iOS only, the slug that Apple uses in the URL to the app listing. Anything seems to work here, including the default appName, but might as well make it match what Apple has, right?
  • storeCountry: Target a specific coutry's store, defaults to us.
  • timingFunction: A method that takes the current total count of positive events recorded for the app, and returns if the Requestor should display the dialog or not. By default, the timingFunction evaluates as 3^n, and if 3^n == currentCount then it returns true/shows the dialog. Source looks like this:
timingFunction: function(currentCount) {
    return currentCount > 1 && Math.log(currentCount) / Math.log(3) % 1 == 0;
}

Notes

As of version 2.0.0 this package is compatible with both iOS and Android.

Peer dependencies and linking may be required, depending on your app and version of React Native.

Releases

For more details, see CHANGELOG.md.

  • 4.3.0 - Remove call to StoreReview.isAvailable on iOS (props to @jforaker)
  • 4.2.0 - async-storage changed homes, so updated the dependency source (props to @taylora123)
  • 4.1.0 - Add TypeScript .d.ts file (props to @randomBrainstormer)
  • 4.0.1 - Fix for missing storeUrl.
  • 4.0.0 - Minimum RN version compatibility now at 0.57+, use community AsyncStorage (props to @imranariffin), use iOS native review request dialog (props to @jasonlfunk)
  • 3.2.1 - Remove unnecessary console.log call. Props to @nlively
  • 3.2.0 - Allow iOS country store and app name to be set. Props to @andreleon
  • 3.1.0 - Formalize the shouldBoldLastButton option. Props to @ttargo1
  • 3.0.0 - Allow changing the order of the buttons on different platforms. Impetus and help from @yihanseattle, @olzhasipsy, and @kesha-antonov, and update the minimum RN dep to v0.26.
  • 2.1.0 - Update the iOS store URL for iOS 11 compatibility thanks to @rodrigopk
  • 2.0.0 - Supports Android, requires RN v0.20.0+, and added showRatingDialog() thanks to @maximilianhurl.
  • 1.1.0 - Added an optional callback to handlePositiveEvent() that reports on the result of the handling. Props to @sercanov.
  • 1.0.0 - Initial release

Questions?

Feel free to contact me:

react-native-rating-requestor's People

Contributors

alexanderwallin avatar andreleon avatar dependabot[bot] avatar imranariffin avatar jasonlfunk avatar jlyman avatar randombrainstormer avatar rodrigopk avatar sercanov avatar skv-headless avatar taylora123 avatar ttargo1 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

react-native-rating-requestor's Issues

Link for Appstore no longer working on iOS 11

The url used on the showRatingDialog is outdated and no longer works on iOS 11.

showRatingDialog(callback = () => {}) {
		let storeUrl = Platform.OS === 'ios' ?
			'http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?id=' + _config.appStoreId + '&pageNumber=0&sortOrdering=2&type=Purple+Software&mt=8' :
			'market://details?id=' + _config.appStoreId;
.
.
.

Following this discussion on stack overflow, we should update the iOS url to follow the following format:
https://itunes.apple.com/us/app/appName/idAPP_ID?mt=8&action=write-review.
So far as I could test it, this format works on both iOS 11 and 10.
If it's ok, I'm creating a PR with this change

In-app reviews for iOS

I cannot tell whether this plugin supports iOS 10.3+ feature of in-app reviews. If not, can we have this support?

Swap to using SKStore​Review​Controller on iOS

Apple is mandating all apps to drop custom rating dialogs in iOS 11 and use SKStore​Review​Controller, so we'll need to switch to using that on iOS. This would be a net positive anyway (though slightly less flexible than what's already in place).

RatingRequestor is not a constructor

Hi,
I'm getting an error when I try to initialize RatingRequestor. I'm putting the following code in my index.ios.js

import RatingRequestor from 'react-native-rating-requestor'
let RatingTracker = new RatingRequestor('[my app id]')

And I get the following error when trying to run my app:
RatingRequestor is not a constructor

Any help is greatly appreciated. Thanks!

timingFunction is not working?

Hello,

I try to call timingFunction, but it's not working. Please see code below.

import RatingRequestor from "react-native-rating-requestor";

const RatingTracker = new RatingRequestor(
Platform.select({
ios: 'xxxxxxxxx',
android: 'app.xxx',
}), {
shouldBoldLastButton: true,
timingFunction: function(currentCount) {
return currentCount > 1 && Math.log(currentCount) / Math.log(3) % 1 == 0;
}
});

does not work? [ios]

Hi,

I'm trying this component on ios and it does not seem to work.

When I click on "Sure!" In the popup, Safari opens but gives me an error:

image

is not the repo updated?

Thanks

Will not work in IOS due to peerDependency change

There is a peerDependency for https://github.com/oblador/react-native-store-review set to

"react-native-store-review": "^0.1.5"

But in the latest version, that library has deprecated an all important method used by the current version of this library, called StoreReview.isAvailable

if (Platform.OS === 'ios' && StoreReview.isAvailable) {
   StoreReview.requestReview();
}

In 0.3.0 they removed the method:

BREAKING CHANGE: Drop support for Android <21 & iOS < 12.4, and remove isAvailable constant.

So StoreReview.isAvailable will return undefined, and that "if" statement will never succeed. Therefore, this never gets called:

StoreReview.requestReview();

For me, the fix was to do a patch and remove the call to isAvailable:

diff --git a/node_modules/react-native-rating-requestor/index.js b/node_modules/react-native-rating-requestor/index.js
index 7f87cc3..3dfded5 100644
--- a/node_modules/react-native-rating-requestor/index.js
+++ b/node_modules/react-native-rating-requestor/index.js
@@ -121,7 +121,7 @@ export default class RatingRequestor {
           RatingsData.recordRated();
           callback(true, "accept");
           // This API is only available on iOS 10.3 or later
-					if (Platform.OS === 'ios' && StoreReview.isAvailable) {
+					if (Platform.OS === 'ios') {
 						StoreReview.requestReview();
 					} else {
 						Linking.openURL(this.storeUrl);

How to config it for iOS and android at the same time?

Hi!

I see that this lib supports iOS and android but fail to see how to use both in the docs. I just want to confirm that the lib expects me to have some sort of platform specific code for iOS and android and call the lib separately (?). It's what I'd understand atm.

Also, since I assume that by default the lib will redirect to the app store / g play sites, is there any way to take the user immediately to the rating section instead of just the product page?

Thanks again for working on this :-)
Joan

Is it possible to use a custom prompt/dialog?

This looks like a great module. I would like to keep the style of my app and want to use my own prompt/dialog. Is there a way to know when it's time to show my own dialog and methods I can call depending on which button the user presses?

Android

Nice, would be great to see Android support!

iOS vs Android button ordering

The code uses button ordering for Android ie. [bottom, middle, top]. On iOS the button ordering for alert is [top, middle, bottom] so the accept button is at the bottom which doesn't make much sense from a UX point of view. You want the desirable button to be at the top and the least desirable at the bottom.

There should be a platform check to reverse the order of buttons based on iOS vs Android.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.