Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add feedback survey option chosen event #4528

Merged
merged 16 commits into from
Dec 10, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ protocol CustomerCenterPurchasesType: Sendable {
promotionalOffer: PromotionalOffer
) async throws -> PurchaseResultData

func track(customerCenterEvent: CustomerCenterEvent)
func track(customerCenterEvent: any CustomerCenterEventType)

}
11 changes: 11 additions & 0 deletions RevenueCatUI/CustomerCenter/Data/CustomerCenterEnvironment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ struct SupportKey: EnvironmentKey {

}

struct CustomerCenterPresentationModeKey: EnvironmentKey {

static let defaultValue: CustomerCenterPresentationMode = .default

}

extension CustomerCenterConfigData.Localization {

/// Default ``CustomerCenterConfigData.Localization`` value for Environment usage
Expand Down Expand Up @@ -70,4 +76,9 @@ extension EnvironmentValues {
set { self[SupportKey.self] = newValue }
}

var customerCenterPresentationMode: CustomerCenterPresentationMode {
get { self[CustomerCenterPresentationModeKey.self] }
set { self[CustomerCenterPresentationModeKey.self] = newValue }
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ final class CustomerCenterPurchases: CustomerCenterPurchasesType {
)
}

func track(customerCenterEvent: CustomerCenterEvent) {
func track(customerCenterEvent: any CustomerCenterEventType) {
Purchases.shared.track(customerCenterEvent: customerCenterEvent)
}

Expand Down
3 changes: 3 additions & 0 deletions RevenueCatUI/CustomerCenter/Data/FeedbackSurveyData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@ import RevenueCat
class FeedbackSurveyData: ObservableObject {

var configuration: CustomerCenterConfigData.HelpPath.FeedbackSurvey
var path: CustomerCenterConfigData.HelpPath
var onOptionSelected: (() -> Void)

init(configuration: CustomerCenterConfigData.HelpPath.FeedbackSurvey,
path: CustomerCenterConfigData.HelpPath,
onOptionSelected: @escaping (() -> Void)) {
self.configuration = configuration
self.path = path
self.onOptionSelected = onOptionSelected
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ import RevenueCat
darkMode: darkMode,
isSandbox: isSandbox,
displayMode: displayMode)
let event = CustomerCenterEvent.impression(CustomerCenterEvent.CreationData(), eventData)
let event = CustomerCenterEvent.impression(CustomerCenterEventCreationData(), eventData)

purchasesProvider.track(customerCenterEvent: event)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,12 @@ class FeedbackSurveyViewModel: ObservableObject {

func handleAction(
for option: CustomerCenterConfigData.HelpPath.FeedbackSurvey.Option,
darkMode: Bool,
displayMode: CustomerCenterPresentationMode,
dismissView: () -> Void
) async {
if let customerCenterActionHandler = self.customerCenterActionHandler {
trackSurveyAnswerSubmitted(option: option, darkMode: darkMode, displayMode: displayMode)
customerCenterActionHandler(.feedbackSurveyCompleted(option.id))
}

Expand Down Expand Up @@ -105,4 +108,32 @@ extension FeedbackSurveyViewModel {
}
}

// MARK: - Events
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
@available(macOS, unavailable)
@available(tvOS, unavailable)
@available(watchOS, unavailable)
private extension FeedbackSurveyViewModel {

func trackSurveyAnswerSubmitted(option: CustomerCenterConfigData.HelpPath.FeedbackSurvey.Option,
darkMode: Bool,
displayMode: CustomerCenterPresentationMode) {
let isSandbox = purchasesProvider.isSandbox
let surveyOptionData = CustomerCenterAnswerSubmittedEvent.Data(locale: .current,
darkMode: darkMode,
isSandbox: isSandbox,
displayMode: displayMode,
path: feedbackSurveyData.path.type,
url: feedbackSurveyData.path.url,
surveyOptionID: option.id,
surveyOptionTitleKey: option.title,
additionalContext: nil,
revisionID: 0)
let event = CustomerCenterAnswerSubmittedEvent.answerSubmitted(CustomerCenterEventCreationData(),
surveyOptionData)
purchasesProvider.track(customerCenterEvent: event)
}

}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ class ManageSubscriptionsViewModel: ObservableObject {
func determineFlow(for path: CustomerCenterConfigData.HelpPath) async {
switch path.detail {
case let .feedbackSurvey(feedbackSurvey):
self.feedbackSurveyData = FeedbackSurveyData(configuration: feedbackSurvey) { [weak self] in
self.feedbackSurveyData = FeedbackSurveyData(configuration: feedbackSurvey,
path: path) { [weak self] in
Task {
await self?.onPathSelected(path: path)
}
Expand Down
1 change: 1 addition & 0 deletions RevenueCatUI/CustomerCenter/Views/CustomerCenterView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public struct CustomerCenterView: View {
.environment(\.localization, configuration.localization)
.environment(\.appearance, configuration.appearance)
.environment(\.supportInformation, configuration.support)
.environment(\.customerCenterPresentationMode, self.mode)
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions RevenueCatUI/CustomerCenter/Views/FeedbackSurveyView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ struct FeedbackSurveyView: View {
private var appearance: CustomerCenterConfigData.Appearance
@Environment(\.colorScheme)
private var colorScheme
@Environment(\.customerCenterPresentationMode)
private var mode: CustomerCenterPresentationMode

@Binding
private var isPresented: Bool
Expand All @@ -57,6 +59,8 @@ struct FeedbackSurveyView: View {
onOptionSelected: { option in
await self.viewModel.handleAction(
for: option,
darkMode: self.colorScheme == .dark,
displayMode: self.mode,
dismissView: self.dismissView
)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,8 @@ struct ManageSubscriptionsView: View {

if let purchaseInformation = self.viewModel.purchaseInformation {
Section {
SubscriptionDetailsView(
purchaseInformation: purchaseInformation,
refundRequestStatus: self.viewModel.refundRequestStatus)
SubscriptionDetailsView(purchaseInformation: purchaseInformation,
refundRequestStatus: self.viewModel.refundRequestStatus)
}
Section {
ManageSubscriptionsButtonsView(viewModel: self.viewModel,
Expand Down
2 changes: 2 additions & 0 deletions Sources/CustomerCenter/CustomerCenterConfigData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -553,3 +553,5 @@ extension CustomerCenterConfigData.Support {
}

}

extension CustomerCenterConfigData.HelpPath.PathType: Sendable, Codable {}
Loading