Skip to content

Commit

Permalink
MOB-309 : add additional logic to rate app flow where requestReview
Browse files Browse the repository at this point in the history
… API is called without pre-prompt IF the pre-prompt has been answer "yes" in the past (#107)

* disable pre-prompt for subsequent app review requests

* Update dydxPointsRating.swift
  • Loading branch information
mike-dydx authored Mar 7, 2024
1 parent f054cc2 commit f9e7810
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private class dydxRateAppViewBuilderPresenter: HostedViewPresenter<dydxRateAppVi
#else
SKStoreReviewController.requestReview()
#endif
dydxRatingService.shared?.disablePrompting()
dydxRatingService.shared?.disablePreprompting()
Router.shared?.navigate(to: RoutingRequest(path: "/action/dismiss"), animated: true, completion: nil)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ open class dydxPointsRating: NSObject, dydxRatingProtocol {
case lastPromptedTimestamp
case hasEverConnectedWallet
case hasSharedOrScreenshottedSinceLastPrompt
case shouldStopPrompting
case shouldStopPreprompting

var storeKey: String { "\(String(describing: dydxPointsRating.self)).\(self.rawValue)Key" }
}
Expand All @@ -38,7 +38,7 @@ open class dydxPointsRating: NSObject, dydxRatingProtocol {
"last_prompted_timestamp": lastPromptedTimestamp,
"has_ever_connected_wallet": hasEverConnectedWallet,
"has_shared_or_screenshotted": hasSharedOrScreenshottedSinceLastPrompt,
"should_stop_prompting": shouldStopPrompting
"should_stop_preprompting": shouldStopPreprompting
]}

public func connectedWallet() {
Expand Down Expand Up @@ -73,8 +73,8 @@ open class dydxPointsRating: NSObject, dydxRatingProtocol {
}
}

public func disablePrompting() {
shouldStopPrompting = true
public func disablePreprompting() {
shouldStopPreprompting = true
}

/// this is maintained as a set for easier order count de-duping
Expand Down Expand Up @@ -117,16 +117,25 @@ open class dydxPointsRating: NSObject, dydxRatingProtocol {
}

/// whether the user has continued to app store review after pre-prompt
var shouldStopPrompting: Bool {
get { UserDefaults.standard.bool(forKey: Key.shouldStopPrompting.storeKey) }
set { UserDefaults.standard.set(newValue, forKey: Key.shouldStopPrompting.storeKey) }
var shouldStopPreprompting: Bool {
get { UserDefaults.standard.bool(forKey: Key.shouldStopPreprompting.storeKey) }
set { UserDefaults.standard.set(newValue, forKey: Key.shouldStopPreprompting.storeKey) }
}

public func promptForRating() {
// feature flag in case the prompt has issues
if !dydxBoolFeatureFlag.enable_app_rating.isEnabled { return }
Tracking.shared?.log(event: "PrepromptedForRating", data: stateData)
Router.shared?.navigate(to: RoutingRequest(path: "/rate_app"), animated: true, completion: nil)
guard dydxBoolFeatureFlag.enable_app_rating.isEnabled else { return }
if shouldStopPreprompting {
#if DEBUG
Console.shared.log("Simulate SKStoreReviewController.requestReview")
#else
SKStoreReviewController.requestReview()
#endif
} else {
Tracking.shared?.log(event: "PrepromptedForRating", data: stateData)
Router.shared?.navigate(to: RoutingRequest(path: "/rate_app"), animated: true, completion: nil)
reset()
}
}

/// See discussion below:
Expand All @@ -148,14 +157,12 @@ open class dydxPointsRating: NSObject, dydxRatingProtocol {
/// - trader has shared a screenshot or the app
/// - trader has created 8 or more orders
open func tryPromptForRating() {
guard !shouldStopPrompting else { return }
let shouldPrompt =
hasSharedOrScreenshottedSinceLastPrompt
|| (hasEverConnectedWallet && (uniqueDayAppOpensCount >= 8 || transfersCreatedSinceLastPrompt.count >= 2 || ordersCreatedSinceLastPrompt.count >= 8))
|| (!hasEverConnectedWallet && uniqueDayAppOpensCount >= 4)
if shouldPrompt {
promptForRating()
reset()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public protocol dydxRatingProtocol {
func orderCreated(orderId: String, orderCreatedTimestampMillis: TimeInterval)
func transferCreated(transferId: String, transferCreatedTimestampMillis: TimeInterval)
func capturedScreenshotOrShare()
func disablePrompting()
func disablePreprompting()

func promptForRating()
func tryPromptForRating()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ private class TestPointsRating: dydxPointsRating {
var promptWasReached: Bool = false

override func promptForRating() {
guard !shouldStopPreprompting else { return }
promptWasReached = true
reset()
}

}

final class dydxPointsRatingTests: XCTestCase {
Expand Down Expand Up @@ -62,7 +63,7 @@ final class dydxPointsRatingTests: XCTestCase {
XCTAssertEqual(testPointRating.promptWasReached, false)
}

func testConnectedWalletAndMultipleAppLaunchesAndDisablePrompting() {
func testConnectedWalletAndMultipleAppLaunchesAndDisablePreprompting() {
testPointRating.connectedWallet()
for i in 1...8 {
Thread.sleep(forTimeInterval: testPointRating.secondsInADay)
Expand All @@ -80,7 +81,7 @@ final class dydxPointsRatingTests: XCTestCase {
}
testPointRating.promptWasReached = false

testPointRating.disablePrompting()
testPointRating.disablePreprompting()
for i in 1...8 {
Thread.sleep(forTimeInterval: testPointRating.secondsInADay)
testPointRating.launchedApp()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,19 +205,19 @@
<CommandLineArguments>
<CommandLineArgument
argument = "-FIRAnalyticsDebugEnabled"
isEnabled = "NO">
isEnabled = "YES">
</CommandLineArgument>
<CommandLineArgument
argument = "-FIRAnalyticsVerboseLoggingEnabled"
isEnabled = "NO">
isEnabled = "YES">
</CommandLineArgument>
<CommandLineArgument
argument = "-noFIRAnalyticsDebugEnabled"
isEnabled = "YES">
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "-FIRAnalyticsVerboseLoggingDisabled"
isEnabled = "YES">
isEnabled = "NO">
</CommandLineArgument>
</CommandLineArguments>
<EnvironmentVariables>
Expand Down

0 comments on commit f9e7810

Please sign in to comment.