@shopgate/engage 7.3.4-beta.6 → 7.4.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/app-rating/action-creators/appStart.js +7 -0
- package/app-rating/action-creators/ordersPlaced.js +7 -0
- package/app-rating/action-creators/popup.js +11 -0
- package/app-rating/action-creators/timer.js +7 -0
- package/app-rating/actions/showModal.js +19 -0
- package/app-rating/constants/index.js +2 -0
- package/app-rating/helpers/index.js +6 -0
- package/app-rating/reducers/index.js +6 -0
- package/app-rating/selectors/appRating.js +5 -0
- package/app-rating/subscriptions/index.js +28 -0
- package/package.json +7 -7
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import{RESET_APP_START_COUNT,INCREASE_APP_START_COUNT}from"../constants";/**
|
|
2
|
+
* Increment the app start count
|
|
3
|
+
* @return {Object} The dispatched action object.
|
|
4
|
+
*/export var increaseAppStartCount=function increaseAppStartCount(){return{type:INCREASE_APP_START_COUNT};};/**
|
|
5
|
+
* Reset the app start count, and increment reset counts
|
|
6
|
+
* @return {Object} The dispatched action object.
|
|
7
|
+
*/export var resetAppStartCount=function resetAppStartCount(){return{type:RESET_APP_START_COUNT};};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import{RESET_ORDERS_PLACED_COUNT,INCREASE_ORDERS_PLACED_COUNT}from"../constants";/**
|
|
2
|
+
* Increment the orders placed count
|
|
3
|
+
* @return {Object} The dispatched action object.
|
|
4
|
+
*/export var increaseOrdersPlacedCount=function increaseOrdersPlacedCount(){return{type:INCREASE_ORDERS_PLACED_COUNT};};/**
|
|
5
|
+
* Reset the orders placed count, and increment reset counts
|
|
6
|
+
* @return {Object} The dispatched action object.
|
|
7
|
+
*/export var resetOrdersPlacedCount=function resetOrdersPlacedCount(){return{type:RESET_ORDERS_PLACED_COUNT};};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import{INCREASE_REJECTION_COUNT,SET_ALREADY_RATED,SET_LAST_POPUP_TIMESTAMP}from"../constants";/**
|
|
2
|
+
* Sets the last popup timestamp
|
|
3
|
+
* @return {Object} The dispatched action object.
|
|
4
|
+
*/export var setLastPopupTimestamp=function setLastPopupTimestamp(){return{type:SET_LAST_POPUP_TIMESTAMP};};/**
|
|
5
|
+
* Sets the last popup timestamp
|
|
6
|
+
* @return {Object} The dispatched action object.
|
|
7
|
+
*/export var increaseRejectionCount=function increaseRejectionCount(){return{type:INCREASE_REJECTION_COUNT};};/**
|
|
8
|
+
* Sets the last popup timestamp
|
|
9
|
+
* @param {boolean} to the value to set the rated status
|
|
10
|
+
* @return {Object} The dispatched action object.
|
|
11
|
+
*/export var setAlreadyRated=function setAlreadyRated(to){return{type:SET_ALREADY_RATED,to:to};};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import{SET_TIMER_START_TIME,INCREASE_TIMER_REPEATS}from"../constants";/**
|
|
2
|
+
* Reset the orders placed count, and increment reset counts
|
|
3
|
+
* @return {Object} The dispatched action object.
|
|
4
|
+
*/export var resetTimerState=function resetTimerState(){return{type:INCREASE_TIMER_REPEATS};};/**
|
|
5
|
+
* Sets the timer start time
|
|
6
|
+
* @return {Object} The dispatched action object.
|
|
7
|
+
*/export var setTimerStartTime=function setTimerStartTime(){return{type:SET_TIMER_START_TIME};};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import _regeneratorRuntime from"@babel/runtime/regenerator";function asyncGeneratorStep(gen,resolve,reject,_next,_throw,key,arg){try{var info=gen[key](arg);var value=info.value;}catch(error){reject(error);return;}if(info.done){resolve(value);}else{Promise.resolve(value).then(_next,_throw);}}function _asyncToGenerator(fn){return function(){var self=this,args=arguments;return new Promise(function(resolve,reject){var gen=fn.apply(self,args);function _next(value){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"next",value);}function _throw(err){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"throw",err);}_next(undefined);});};}function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}import showModalAction from'@shopgate/pwa-common/actions/modal/showModal';import{getPlatform}from'@shopgate/pwa-common/selectors/client';import{historyPush}from'@shopgate/pwa-common/actions/router';import appConfig from'@shopgate/pwa-common/helpers/config';import{track}from'@shopgate/pwa-tracking/helpers';import{increaseRejectionCount,setAlreadyRated,setLastPopupTimestamp}from"../action-creators/popup";import{generateReviewLink}from"../helpers";import{TIMER_TIMESPAN}from"../constants";import{getAppRatingState}from"../selectors/appRating";var _appConfig$appRating=appConfig.appRating,bundleId=_appConfig$appRating.bundleId,minDaysBetweenPopups=_appConfig$appRating.minDaysBetweenPopups,askForFeedback=_appConfig$appRating.askForFeedback,feedbackLink=_appConfig$appRating.feedbackLink;/**
|
|
2
|
+
* to handle the user redirection
|
|
3
|
+
* @param {string} url the url to redirect to
|
|
4
|
+
* @param {boolean | null} setRated the url to redirect to
|
|
5
|
+
* @return {(function(*, *): void)|*}
|
|
6
|
+
*/function redirectTo(url){var setRated=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;return function(dispatch){if(!url){return;}if(setRated){dispatch(setAlreadyRated(setRated));}dispatch(historyPush(_extends({pathname:url},setRated&&{target:'_blank'})));};}/**
|
|
7
|
+
* shows the actual modal
|
|
8
|
+
* @param {Function} resetAction the reset action function
|
|
9
|
+
* @param {Function} increaseAction the function to increase the appropriate counter
|
|
10
|
+
* @param {boolean} mustShow if the modal must be shown
|
|
11
|
+
* @param {boolean} hasRepeats if the counters has repeats
|
|
12
|
+
* @return {(function(*, *): void)|*}
|
|
13
|
+
*/export function showModal(resetAction,increaseAction,mustShow,hasRepeats){return(/*#__PURE__*/function(){var _ref=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(dispatch,getState){var state,platform,reviewLink,appRatingState,isMinDaysBetweenPopupsElapsed,firstModalConfirmed,userGivesFeedback;return _regeneratorRuntime.wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:state=getState();platform=getPlatform(state);reviewLink=generateReviewLink(bundleId[platform],platform);// no review link for current platform found -> don't show modal
|
|
14
|
+
if(reviewLink){_context.next=5;break;}return _context.abrupt("return");case 5:if(!mustShow&&hasRepeats&&increaseAction){dispatch(increaseAction());}if(mustShow&&hasRepeats){_context.next=8;break;}return _context.abrupt("return");case 8:appRatingState=getAppRatingState(state);isMinDaysBetweenPopupsElapsed=Date.now()-appRatingState.lastPopupAt>=minDaysBetweenPopups*TIMER_TIMESPAN;if(isMinDaysBetweenPopupsElapsed){_context.next=12;break;}return _context.abrupt("return");case 12:dispatch(resetAction());dispatch(setLastPopupTimestamp());_context.next=16;return dispatch(showModalAction({confirm:'appRating.yes',dismiss:'appRating.no',title:'appRating.title',message:'appRating.message'}));case 16:firstModalConfirmed=_context.sent;track('customEvent',{eventCategory:'appReviewPrompt',eventAction:'decision',eventLabel:firstModalConfirmed?'yes':'no'},state);// user touched yes and we
|
|
15
|
+
// redirect to store
|
|
16
|
+
if(!firstModalConfirmed){_context.next=21;break;}dispatch(redirectTo(reviewLink,true));return _context.abrupt("return");case 21:// user doesn't want to rate
|
|
17
|
+
dispatch(increaseRejectionCount());// we approve for rejection
|
|
18
|
+
if(!askForFeedback){_context.next=29;break;}_context.next=25;return dispatch(showModalAction({confirm:'appRating.yes',dismiss:'appRating.no',title:'appRating.title',message:'appRating.rejectionApprovalMessage'}));case 25:userGivesFeedback=_context.sent;track('customEvent',{eventCategory:'appReviewPrompt',eventAction:'decision_feedback',eventLabel:userGivesFeedback?'yes':'no'},state);// user now wants to rate our app! yay :D
|
|
19
|
+
if(userGivesFeedback){dispatch(redirectTo(feedbackLink));}return _context.abrupt("return");case 29:dispatch(redirectTo(feedbackLink));case 30:case"end":return _context.stop();}}},_callee);}));return function(_x,_x2){return _ref.apply(this,arguments);};}());}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export var INCREASE_APP_START_COUNT='INCREASE_APP_START_COUNT';export var RESET_APP_START_COUNT='RESET_APP_START_COUNT';export var RESET_APP_START_STATE='RESET_APP_START_STATE';export var INCREASE_ORDERS_PLACED_COUNT='INCREASE_ORDERS_PLACED_COUNT';export var RESET_ORDERS_PLACED_COUNT='RESET_ORDERS_PLACED_COUNT';export var RESET_ORDERS_PLACED_STATE='RESET_ORDERS_PLACED_STATE';export var INCREASE_TIMER_REPEATS='INCREASE_TIMER_REPEATS';export var SET_TIMER_START_TIME='SET_TIMER_START_TIME';export var SET_LAST_POPUP_TIMESTAMP='SET_LAST_POPUP_TIMESTAMP';export var INCREASE_REJECTION_COUNT='INCREASE_REJECTION_COUNT';export var SET_ALREADY_RATED='SET_ALREADY_RATED';// currently the timespan is set to a day
|
|
2
|
+
export var TIMER_TIMESPAN=1000*60*60*24;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import{OS_ANDROID,OS_IOS}from'@shopgate/pwa-common/constants/Device';/**
|
|
2
|
+
* Generates a review app deep link based on the given provider
|
|
3
|
+
* @param {string} bundleId app bundle id
|
|
4
|
+
* @param {OS_ANDROID | OS_IOS} platform the name of the platform
|
|
5
|
+
* @return {string | null}
|
|
6
|
+
*/export function generateReviewLink(bundleId,platform){if(!bundleId){return null;}switch(platform){case OS_IOS:{return"https://itunes.apple.com/app/id".concat(bundleId,"?action=write-review");}case OS_ANDROID:{return"https://market.android.com/details?id=".concat(bundleId);}default:{return null;}}}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}import{INCREASE_APP_START_COUNT,RESET_APP_START_STATE,RESET_APP_START_COUNT,INCREASE_ORDERS_PLACED_COUNT,RESET_ORDERS_PLACED_COUNT,RESET_ORDERS_PLACED_STATE,INCREASE_TIMER_REPEATS,SET_TIMER_START_TIME,SET_LAST_POPUP_TIMESTAMP,INCREASE_REJECTION_COUNT,SET_ALREADY_RATED}from"../constants";var defaultState={appStartCount:0,appStartResetCount:0,ordersPlacedCount:0,ordersPlacedResetCount:0,timerRepeatsCount:0,timerStartTimestamp:null,lastPopupAt:null,rejectionCount:0,alreadyRated:false};/**
|
|
2
|
+
* Stores all the app rating states.
|
|
3
|
+
* @param {Object} [state] The current state.
|
|
4
|
+
* @param {Object} action The action object.
|
|
5
|
+
* @return {Object} The new state.
|
|
6
|
+
*/export default(function(){var state=arguments.length>0&&arguments[0]!==undefined?arguments[0]:defaultState;var action=arguments.length>1?arguments[1]:undefined;switch(action.type){case INCREASE_APP_START_COUNT:{return _extends({},state,{appStartCount:state.appStartCount+1});}case RESET_APP_START_COUNT:{return _extends({},state,{appStartCount:0,appStartResetCount:state.appStartResetCount+1});}case RESET_APP_START_STATE:{return _extends({},state,{appStartCount:0,appStartResetCount:0});}case INCREASE_ORDERS_PLACED_COUNT:{return _extends({},state,{ordersPlacedCount:state.ordersPlacedCount+1});}case RESET_ORDERS_PLACED_COUNT:{return _extends({},state,{ordersPlacedCount:0,ordersPlacedResetCount:state.ordersPlacedResetCount+1});}case RESET_ORDERS_PLACED_STATE:{return _extends({},state,{ordersPlacedCount:0,ordersPlacedResetCount:0});}case INCREASE_TIMER_REPEATS:{return _extends({},state,{timerRepeatsCount:state.timerRepeatsCount+1});}case SET_TIMER_START_TIME:{return _extends({},state,{timerStartTimestamp:Date.now()});}case SET_LAST_POPUP_TIMESTAMP:{return _extends({},state,{lastPopupAt:Date.now()});}case INCREASE_REJECTION_COUNT:{return _extends({},state,{rejectionCount:state.rejectionCount+1});}case SET_ALREADY_RATED:{return _extends({},state,{alreadyRated:action.to});}default:return state;}});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import _regeneratorRuntime from"@babel/runtime/regenerator";function asyncGeneratorStep(gen,resolve,reject,_next,_throw,key,arg){try{var info=gen[key](arg);var value=info.value;}catch(error){reject(error);return;}if(info.done){resolve(value);}else{Promise.resolve(value).then(_next,_throw);}}function _asyncToGenerator(fn){return function(){var self=this,args=arguments;return new Promise(function(resolve,reject){var gen=fn.apply(self,args);function _next(value){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"next",value);}function _throw(err){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"throw",err);}_next(undefined);});};}import appConfig from'@shopgate/pwa-common/helpers/config';import{appDidStart$}from'@shopgate/pwa-common/streams/app';import{checkoutSuccess$}from'@shopgate/engage/checkout/streams';import event from'@shopgate/pwa-core/classes/Event';import{hasWebBridge}from'@shopgate/engage/core';import{increaseAppStartCount,resetAppStartCount}from"../action-creators/appStart";import{increaseOrdersPlacedCount,resetOrdersPlacedCount}from"../action-creators/ordersPlaced";import{resetTimerState,setTimerStartTime}from"../action-creators/timer";import{TIMER_TIMESPAN}from"../constants";import{getAppRatingState}from"../selectors/appRating";import{showModal}from"../actions/showModal";/**
|
|
2
|
+
* App rating subscriptions
|
|
3
|
+
* @param {Function} subscribe The subscribe function
|
|
4
|
+
*/export default function appRating(subscribe){if(!hasWebBridge){return;}var _appConfig$appRating=appConfig.appRating,appStarts=_appConfig$appRating.appStarts,ordersPlaced=_appConfig$appRating.ordersPlaced,timeInterval=_appConfig$appRating.timeInterval,rejectionMaxCount=_appConfig$appRating.rejectionMaxCount,bundleId=_appConfig$appRating.bundleId;// even subscriber to handle app start ratings
|
|
5
|
+
// and also time interval ratings
|
|
6
|
+
subscribe(appDidStart$,/*#__PURE__*/function(){var _ref2=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref){var dispatch,getState,state,mustShowModal,hasRepeats,resetAction,increaseAction;return _regeneratorRuntime.wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:dispatch=_ref.dispatch,getState=_ref.getState;if(!(!bundleId||!bundleId.android||!bundleId.ios)){_context.next=3;break;}return _context.abrupt("return");case 3:// every time the app starts
|
|
7
|
+
// we increase the start count
|
|
8
|
+
dispatch(increaseAppStartCount());state=getAppRatingState(getState());// if the user has already rated the app
|
|
9
|
+
// we'll cancel the operations as we
|
|
10
|
+
// don't have to show the modal once more
|
|
11
|
+
if(!state.alreadyRated){_context.next=7;break;}return _context.abrupt("return");case 7:if(!(state.rejectionCount>=rejectionMaxCount)){_context.next=9;break;}return _context.abrupt("return");case 9:// initiate the first start time
|
|
12
|
+
if(state.timerStartTimestamp===null){dispatch(setTimerStartTime());}mustShowModal=false;hasRepeats=false;resetAction=null;increaseAction=null;if(Number(timeInterval.value)>0&&Number(state.timerStartTimestamp)>0&&Date.now()-state.timerStartTimestamp>=timeInterval.value*TIMER_TIMESPAN){mustShowModal=true;hasRepeats=timeInterval.repeats===null||state.timerRepeatsCount<=timeInterval.repeats;resetAction=resetTimerState;// since the time is elapsed
|
|
13
|
+
// we reset the starting time
|
|
14
|
+
increaseAction=setTimerStartTime;}else if(appStarts){mustShowModal=Number(appStarts.value)>0&&state.appStartCount>=appStarts.value;hasRepeats=appStarts.repeats===null||state.appStartResetCount<=appStarts.repeats;resetAction=resetAppStartCount;increaseAction=null;}// the actual show modal logic
|
|
15
|
+
dispatch(showModal(resetAction,increaseAction,mustShowModal,hasRepeats));case 16:case"end":return _context.stop();}}},_callee);}));return function(_x){return _ref2.apply(this,arguments);};}());/**
|
|
16
|
+
* Handle checkout success logic
|
|
17
|
+
* @param {Function} dispatch dispatch
|
|
18
|
+
* @param {Function} getState getState
|
|
19
|
+
*/var handleCheckoutSuccess=function handleCheckoutSuccess(dispatch,getState){if(!bundleId||!bundleId.android||!bundleId.ios){return;}var state=getAppRatingState(getState());// if the user has already rated the app
|
|
20
|
+
// we'll cancel the operations as we
|
|
21
|
+
// don't have to show the modal once more
|
|
22
|
+
if(state.alreadyRated){return;}// cancel the process if user has
|
|
23
|
+
// already rejected rating the app
|
|
24
|
+
// many times before
|
|
25
|
+
if(state.rejectionCount>=rejectionMaxCount){return;}if(!ordersPlaced){return;}// orders placed count starts from 0
|
|
26
|
+
var mustShowModal=state.ordersPlacedCount===ordersPlaced.value-1;var hasRepeats=ordersPlaced.repeats===null||state.ordersPlacedResetCount<=ordersPlaced.repeats;dispatch(showModal(resetOrdersPlacedCount,increaseOrdersPlacedCount,mustShowModal,hasRepeats));};// subscriber to handle order placed ratings from native checkout
|
|
27
|
+
subscribe(checkoutSuccess$,function(_ref3){var dispatch=_ref3.dispatch,getState=_ref3.getState;handleCheckoutSuccess(dispatch,getState);});// event subscriber to handle order placed ratings from webcheckout
|
|
28
|
+
subscribe(appDidStart$,function(_ref4){var dispatch=_ref4.dispatch,getState=_ref4.getState;event.addCallback('checkoutSuccess',function(){handleCheckoutSuccess(dispatch,getState);});});}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shopgate/engage",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.4.0-beta.1",
|
|
4
4
|
"description": "Shopgate's ENGAGE library.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Shopgate <support@shopgate.com>",
|
|
@@ -16,12 +16,12 @@
|
|
|
16
16
|
],
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@shopgate/native-modules": "1.0.0-beta.18",
|
|
19
|
-
"@shopgate/pwa-common": "7.
|
|
20
|
-
"@shopgate/pwa-common-commerce": "7.
|
|
21
|
-
"@shopgate/pwa-core": "7.
|
|
22
|
-
"@shopgate/pwa-ui-ios": "7.
|
|
23
|
-
"@shopgate/pwa-ui-material": "7.
|
|
24
|
-
"@shopgate/pwa-ui-shared": "7.
|
|
19
|
+
"@shopgate/pwa-common": "7.4.0-beta.1",
|
|
20
|
+
"@shopgate/pwa-common-commerce": "7.4.0-beta.1",
|
|
21
|
+
"@shopgate/pwa-core": "7.4.0-beta.1",
|
|
22
|
+
"@shopgate/pwa-ui-ios": "7.4.0-beta.1",
|
|
23
|
+
"@shopgate/pwa-ui-material": "7.4.0-beta.1",
|
|
24
|
+
"@shopgate/pwa-ui-shared": "7.4.0-beta.1",
|
|
25
25
|
"@stripe/react-stripe-js": "^1.1.2",
|
|
26
26
|
"@stripe/stripe-js": "^1.3.1",
|
|
27
27
|
"@virtuous/conductor": "~2.5.0",
|