Add app rate feature

I am trying to add app rate feature in my app using the code in controllers.js:

/* RATE APP */
    $scope.rateApp = function(){
        document.addEventListener("deviceready", function () {
            AppRate.preferences.useLanguage = 'en';
            var popupInfo = {};
            popupInfo.title = Shop.name;
            popupInfo.message = "You like "+Shop.name+" We would be glad if you share your experience with others on playstore. Thanks for your shopping with us";
            popupInfo.cancelButtonLabel = "No, thanks";
            popupInfo.laterButtonLabel = "Remind Me Later";
            popupInfo.rateButtonLabel = "Rate Now";
            AppRate.preferences.customLocale = popupInfo;

            AppRate.preferences.usesUntilPrompt = 3;
            AppRate.preferences.promptAgainForEachNewVersion = true;
            AppRate.preferences.openStoreInApp = true;
            AppRate.preferences.storeAppURL.ios = '849930087';
            AppRate.preferences.storeAppURL.android = 'market://details?id=app.anyapp.com';

            AppRate.promptForRating(true);

        }, false);
    }

    /* END RATE APP */

and in app.js calling AppRate.promptForRating(true);

i get the popup but when i click on Rate Now nothing happens, it should be redirected to playstore but it doesnt, can anyone guide me whats wrong with this

In iOnic 2 I write it like that.

this.appRate.preferences = {
  openStoreInApp: true,
  displayAppName: 'Alloca',
  usesUntilPrompt: 2,
  promptAgainForEachNewVersion: true,
  storeAppURL: {
    ios: '1222926795',
    android: 'market://details?id=com.mytech.alloca'
  },
  customLocale: {
    title: "Bewerten Sie Alloca",
    message: "Sagen Sie uns Ihre Meinung um Alloca in Zukunft noch besser zu machen!",
    cancelButtonLabel: "Nein, Danke",
    laterButtonLabel: "Später",
    rateButtonLabel: "Jetzt bewerten"
  }
};

Should work like on Angular 1/iOnic 1

should i add this in controllers.js???

Try this:

AppRate.preferences = {
  openStoreInApp: true,
  displayAppName: 'Alloca',
  usesUntilPrompt: 2,
  promptAgainForEachNewVersion: true,
  storeAppURL: {
    ios: '1222926795',
    android: 'market://details?id=com.mytech.alloca'
  },
  customLocale: {
    title: "Bewerten Sie Alloca",
    message: "Sagen Sie uns Ihre Meinung um Alloca in Zukunft noch besser zu machen!",
    cancelButtonLabel: "Nein, Danke",
    laterButtonLabel: "Später",
    rateButtonLabel: "Jetzt bewerten"
  }
}; AppRate.promptForRating(false); // Open after the 3rd start

I had that previous code in controllers.js so should i put it there??? or direct to app.js?

In your app.js I guess

// Ionic Starter App

// angular.module is a global place for creating, registering and retrieving Angular modules
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
// the 2nd parameter is an array of 'requires'
angular.module('starter', ['ionic'])

.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {
if(window.cordova && window.cordova.plugins.Keyboard) {
  cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
  cordova.plugins.Keyboard.disableScroll(true);
}
if(window.StatusBar) {
  StatusBar.styleDefault();
}
AppRate.preferences = {
  openStoreInApp: true,
  displayAppName: 'Alloca',
  usesUntilPrompt: 2,
  promptAgainForEachNewVersion: true,
  storeAppURL: {
    ios: '1222926795',
    android: 'market://details?id=com.mytech.alloca'
  },
  customLocale: {
    title: "Bewerten Sie Alloca",
    message: "Sagen Sie uns Ihre Meinung um Alloca in Zukunft noch besser zu machen!",
    cancelButtonLabel: "Nein, Danke",
    laterButtonLabel: "Später",
    rateButtonLabel: "Jetzt bewerten"
  }
}; 
AppRate.promptForRating(false); // Open after the 3rd start
  });
})
1 Like

Thanks it worked like a charm.

Good to hear :slight_smile:

Can u help me to obfuscate the codes if possible

Hi @LoLStats

Thanks for the nice tipps!
I am using ionic1 and trying to install that as well, but it is not working :frowning:
Have I done sth wrong?

Thanks in advance! :slight_smile:

export function onReady($ionicPlatform, $window) {
	$ionicPlatform.ready(function() {
		console.log('ionicPlatform');
		// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
		// for form inputs)
		if ($window.cordova && $window.cordova.plugins && $window.cordova.plugins.Keyboard) {
			cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
			cordova.plugins.Keyboard.disableScroll(true);
		}
		if ($window.Keyboard) {
			$window.Keyboard.shrinkView(true);
		}
		if ($window.StatusBar) {
			// org.apache.cordova.statusbar required
			StatusBar.styleDefault();
		}

		$window.AppRate.preferences = {
			openStoreInApp: true,
			language: 'de',
			displayAppName: '',
			usesUntilPrompt: 2,
			promptAgainForEachNewVersion: true,
			storeAppURL: {
				ios: '',
				android: ''
			},
			customLocale: {
				title: "Bewerten Sie Alloca",
				message: "Sagen Sie uns Ihre Meinung um Alloca in Zukunft noch besser zu machen!",
				cancelButtonLabel: "Nein, Danke",
				laterButtonLabel: "Später",
				rateButtonLabel: "Jetzt bewerten"
			}
		};

		$window.AppRate.promptForRating(false); // Open after the 3rd start
	});
}

HI ALL,
I am writing this piece of code and no matter what i do, the preference object that i am creating is not getting reflected. i am only seeing the default template. After some debugging, i found out that apprate.ready.then, in my case, this flow is getting skipped. not sure if that is the reason, can someone please help.

    this.$cordovaAppRate.preferences = 
    {
        openStoreInApp: false,
        displayAppName: 'TO DO',
        usesUntilPrompt: 4,
        promptAgainForEachNewVersion: true,
        storeAppUrl: {
            ios: '951726789',
            android: '4976462110923858976'
        },
        customLocale: {
            title: 'Do you Enjoy %@?',
            message: 'If you Enjoy %@. would you mind taking a moment to rate it',
            cancelButtonLabel: 'No Thanks',
            laterButtonLabel: 'Remind Me Later',
            rateButtonLabel: 'Rate It Now'
        },
        callbacks: {
            onRateDialogShow: function(callback) {
                console.log('Rate Shown');
            },
            onButtonClicked: function(buttonindex) {
                console.log('button index', +buttonindex);
            }
        }
    }

    this.$cordovaAppRate.promptForRating(true);