Skip to content

Commit

Permalink
creates CustomerCenterEventDiscriminator
Browse files Browse the repository at this point in the history
  • Loading branch information
vegaro committed Dec 9, 2024
1 parent e33cb2a commit ed98ba6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
11 changes: 9 additions & 2 deletions Sources/CustomerCenter/Events/CustomerCenterEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ extension CustomerCenterEventType {

}

enum CustomerCenterEventDiscriminator: String {

case lifecycle = "lifecycle"
case answerSubmitted = "answer_submitted"

}

/// Data that represents a customer center event creation.
public struct CustomerCenterEventCreationData {

Expand All @@ -42,7 +49,7 @@ public struct CustomerCenterEventCreationData {
/// An event to be sent by the `RevenueCatUI` SDK.
public enum CustomerCenterEvent: FeatureEvent, CustomerCenterEventType {

var eventDiscriminator: String? { "lifecycle" }
var eventDiscriminator: String? { CustomerCenterEventDiscriminator.lifecycle.rawValue }

/// The Customer Center was displayed.
case impression(CustomerCenterEventCreationData, Data)
Expand All @@ -52,7 +59,7 @@ public enum CustomerCenterEvent: FeatureEvent, CustomerCenterEventType {
/// An event to be sent by the `RevenueCatUI` SDK.
public enum CustomerCenterAnswerSubmittedEvent: FeatureEvent, CustomerCenterEventType {

var eventDiscriminator: String? { "survey_option_chosen" }
var eventDiscriminator: String? { CustomerCenterEventDiscriminator.lifecycle.rawValue }

/// A feedback survey was completed with a particular option.
case answerSubmitted(CustomerCenterEventCreationData, Data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ extension EventsRequest {
private static let version: Int = 1
}

final class CustomerCenterEventSurveyOptionChosen {
final class CustomerCenterAnswerSubmitted {

let id: String?
let version: Int
Expand Down Expand Up @@ -155,7 +155,7 @@ extension EventsRequest {
}

@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
static func create(from storedEvent: StoredEvent) -> CustomerCenterEventSurveyOptionChosen? {
static func create(from storedEvent: StoredEvent) -> CustomerCenterAnswerSubmitted? {
guard let appSessionID = storedEvent.appSessionID else {
Logger.error(Strings.paywalls.event_missing_app_session_id)
return nil
Expand All @@ -174,7 +174,7 @@ extension EventsRequest {
let creationData = customerCenterEvent.creationData
let data = customerCenterEvent.data

return CustomerCenterEventSurveyOptionChosen(
return CustomerCenterAnswerSubmitted(
id: creationData.id.uuidString,
version: version,
appUserID: storedEvent.userID,
Expand Down Expand Up @@ -234,7 +234,7 @@ extension EventsRequest.CustomerCenterEventBase: Encodable {

}

extension EventsRequest.CustomerCenterEventSurveyOptionChosen: Encodable {
extension EventsRequest.CustomerCenterAnswerSubmitted: Encodable {

private enum CodingKeys: String, CodingKey {

Expand Down
4 changes: 2 additions & 2 deletions Sources/Events/Networking/EventsRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ struct EventsRequest {
return AnyEncodable(event)
case .customerCenter:
switch storedEvent.eventDiscriminator {
case "survey_option_chosen":
guard let event = CustomerCenterEventSurveyOptionChosen.create(from: storedEvent) else {
case CustomerCenterEventDiscriminator.answerSubmitted.rawValue:
guard let event = CustomerCenterAnswerSubmittedEvent.create(from: storedEvent) else {
return nil
}
return AnyEncodable(event)
Expand Down

0 comments on commit ed98ba6

Please sign in to comment.