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

Create CustomerCenterEvent #4392

Merged
merged 17 commits into from
Dec 2, 2024
40 changes: 40 additions & 0 deletions RevenueCat.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@
351B51C126D450E800BD2BD7 /* OfferingsManagerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F575859126C08E3F00C12B97 /* OfferingsManagerTests.swift */; };
351B51C226D450E800BD2BD7 /* ProductRequestDataTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37E350E57B0A393455A72B40 /* ProductRequestDataTests.swift */; };
351B51C326D450F200BD2BD7 /* InMemoryCachedObjectTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37E35E3250FBBB03D92E06EC /* InMemoryCachedObjectTests.swift */; };
352137322CDBA2AA00FE961B /* FeatureEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 352137312CDBA2A700FE961B /* FeatureEvent.swift */; };
3525D8A42C4AB3D600C21D99 /* CustomerCenterEnvironment.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3525D8A32C4AB3D500C21D99 /* CustomerCenterEnvironment.swift */; };
35272E1B26D0029300F22C3B /* DeviceCacheSubscriberAttributesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37E35C4A795A0F056381A1B3 /* DeviceCacheSubscriberAttributesTests.swift */; };
35272E2226D0048D00F22C3B /* HTTPClientTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37E353CBE9CF2572A72A347F /* HTTPClientTests.swift */; };
Expand Down Expand Up @@ -275,6 +276,9 @@
354895D6267BEDE3001DC5B1 /* ReservedSubscriberAttributes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 354895D5267BEDE3001DC5B1 /* ReservedSubscriberAttributes.swift */; };
3551E39D2C4A6A1400D27C25 /* TintedProgressView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3551E39C2C4A6A1400D27C25 /* TintedProgressView.swift */; };
35549323269E298B005F9AE9 /* OfferingsFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35549322269E298B005F9AE9 /* OfferingsFactory.swift */; };
356523A82CF7719C00B6E3EA /* CustomerCenterPresentationMode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 356523A72CF7719B00B6E3EA /* CustomerCenterPresentationMode.swift */; };
356523AA2CF885D300B6E3EA /* MockCustomerCenterPurchases.swift in Sources */ = {isa = PBXBuildFile; fileRef = 356523A92CF885CE00B6E3EA /* MockCustomerCenterPurchases.swift */; };
356523AC2CF890F400B6E3EA /* CustomerCenterEventsRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 356523AB2CF890EA00B6E3EA /* CustomerCenterEventsRequestTests.swift */; };
356979E02CCFDAA100EE6A9E /* CustomerInfoFixtures.swift in Sources */ = {isa = PBXBuildFile; fileRef = 356979DF2CCFDA9C00EE6A9E /* CustomerInfoFixtures.swift */; };
356E2DE82CD3CF930055AABB /* StoredEventTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 356E2DE72CD3CF8F0055AABB /* StoredEventTests.swift */; };
357349012C3BEB5C000EEB86 /* CustomerCenterConfigDataTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 357348FF2C3BEB0A000EEB86 /* CustomerCenterConfigDataTests.swift */; };
Expand Down Expand Up @@ -315,6 +319,8 @@
35F249CC2C493DCC0058993A /* CustomerCenterPurchasesType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35F249CB2C493DCC0058993A /* CustomerCenterPurchasesType.swift */; };
35F249CE2C493E3D0058993A /* CustomerCenterPurchases.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35F249CD2C493E3D0058993A /* CustomerCenterPurchases.swift */; };
35F38B482C30104E00CD29FD /* BackendGetCustomerCenterConfigTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35F38B472C30104E00CD29FD /* BackendGetCustomerCenterConfigTests.swift */; };
35F7884B2CC68F5300080F32 /* CustomerCenterEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35F7884A2CC68F4C00080F32 /* CustomerCenterEvent.swift */; };
35F788F62CC6B62600080F32 /* EventsRequest+CustomerCenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35F788F52CC6B62400080F32 /* EventsRequest+CustomerCenter.swift */; };
35F82BAB26A84E130051DF03 /* Dictionary+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35F82BAA26A84E130051DF03 /* Dictionary+Extensions.swift */; };
35F82BB226A98EC50051DF03 /* AttributionDataMigratorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35F82BB126A98EC50051DF03 /* AttributionDataMigratorTests.swift */; };
35F82BB426A9A74D0051DF03 /* HTTPClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35F82BB326A9A74D0051DF03 /* HTTPClient.swift */; };
Expand Down Expand Up @@ -1498,6 +1504,7 @@
351B517126D44EF300BD2BD7 /* MockInMemoryCachedOfferings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockInMemoryCachedOfferings.swift; sourceTree = "<group>"; };
351B517326D44F4B00BD2BD7 /* MockPaymentDiscount.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockPaymentDiscount.swift; sourceTree = "<group>"; };
351B517926D44FF000BD2BD7 /* MockRequestFetcher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockRequestFetcher.swift; sourceTree = "<group>"; };
352137312CDBA2A700FE961B /* FeatureEvent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeatureEvent.swift; sourceTree = "<group>"; };
3525D8A32C4AB3D500C21D99 /* CustomerCenterEnvironment.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CustomerCenterEnvironment.swift; sourceTree = "<group>"; };
352B7D7827BD919B002A47DD /* DangerousSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DangerousSettings.swift; sourceTree = "<group>"; };
3530C18822653E8F00D6DF52 /* AdSupport.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AdSupport.framework; path = System/Library/Frameworks/AdSupport.framework; sourceTree = SDKROOT; };
Expand Down Expand Up @@ -1530,6 +1537,9 @@
354895D5267BEDE3001DC5B1 /* ReservedSubscriberAttributes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReservedSubscriberAttributes.swift; sourceTree = "<group>"; };
3551E39C2C4A6A1400D27C25 /* TintedProgressView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TintedProgressView.swift; sourceTree = "<group>"; };
35549322269E298B005F9AE9 /* OfferingsFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OfferingsFactory.swift; sourceTree = "<group>"; };
356523A72CF7719B00B6E3EA /* CustomerCenterPresentationMode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomerCenterPresentationMode.swift; sourceTree = "<group>"; };
356523A92CF885CE00B6E3EA /* MockCustomerCenterPurchases.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockCustomerCenterPurchases.swift; sourceTree = "<group>"; };
356523AB2CF890EA00B6E3EA /* CustomerCenterEventsRequestTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomerCenterEventsRequestTests.swift; sourceTree = "<group>"; };
356979DF2CCFDA9C00EE6A9E /* CustomerInfoFixtures.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomerInfoFixtures.swift; sourceTree = "<group>"; };
356E2DE72CD3CF8F0055AABB /* StoredEventTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StoredEventTests.swift; sourceTree = "<group>"; };
357348FF2C3BEB0A000EEB86 /* CustomerCenterConfigDataTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomerCenterConfigDataTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1571,6 +1581,8 @@
35F249CB2C493DCC0058993A /* CustomerCenterPurchasesType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomerCenterPurchasesType.swift; sourceTree = "<group>"; };
35F249CD2C493E3D0058993A /* CustomerCenterPurchases.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomerCenterPurchases.swift; sourceTree = "<group>"; };
35F38B472C30104E00CD29FD /* BackendGetCustomerCenterConfigTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BackendGetCustomerCenterConfigTests.swift; sourceTree = "<group>"; };
35F7884A2CC68F4C00080F32 /* CustomerCenterEvent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomerCenterEvent.swift; sourceTree = "<group>"; };
35F788F52CC6B62400080F32 /* EventsRequest+CustomerCenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "EventsRequest+CustomerCenter.swift"; sourceTree = "<group>"; };
35F82BAA26A84E130051DF03 /* Dictionary+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Dictionary+Extensions.swift"; sourceTree = "<group>"; };
35F82BB126A98EC50051DF03 /* AttributionDataMigratorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AttributionDataMigratorTests.swift; sourceTree = "<group>"; };
35F82BB326A9A74D0051DF03 /* HTTPClient.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HTTPClient.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3548,6 +3560,7 @@
353DE0042CCA4EA600A8F632 /* Events */ = {
isa = PBXGroup;
children = (
352137312CDBA2A700FE961B /* FeatureEvent.swift */,
4FE6FEE42AA940B700780B45 /* StoredEvent.swift */,
4FD368B52AA7D09C00F63354 /* StoredEventSerializer.swift */,
353DE0052CCA4EAE00A8F632 /* Networking */,
Expand Down Expand Up @@ -3636,6 +3649,7 @@
3544DA6B2C2C848E00704E9D /* CustomerCenter */ = {
isa = PBXGroup;
children = (
356523A92CF885CE00B6E3EA /* MockCustomerCenterPurchases.swift */,
35A99C822CCB95950074AB41 /* SubscriptionInformationFixtures.swift */,
3544DA692C2C848E00704E9D /* CustomerCenterViewModelTests.swift */,
3544DA6A2C2C848E00704E9D /* ManageSubscriptionsViewModelTests.swift */,
Expand All @@ -3657,6 +3671,14 @@
path = SubscriberAttributes;
sourceTree = "<group>";
};
356523AD2CF8916700B6E3EA /* Events */ = {
isa = PBXGroup;
children = (
356523AB2CF890EA00B6E3EA /* CustomerCenterEventsRequestTests.swift */,
);
path = Events;
sourceTree = "<group>";
};
35653BD32C46803A009E8ADB /* Abstractions */ = {
isa = PBXGroup;
children = (
Expand All @@ -3677,6 +3699,7 @@
357348FE2C3BEAF8000EEB86 /* CustomerCenter */ = {
isa = PBXGroup;
children = (
356523AD2CF8916700B6E3EA /* Events */,
357348FF2C3BEB0A000EEB86 /* CustomerCenterConfigDataTests.swift */,
);
path = CustomerCenter;
Expand All @@ -3685,6 +3708,8 @@
3592E8892C2ED54A00D7F91D /* CustomerCenter */ = {
isa = PBXGroup;
children = (
356523A72CF7719B00B6E3EA /* CustomerCenterPresentationMode.swift */,
35F7884C2CC68F5F00080F32 /* Events */,
3592E8882C2ED54A00D7F91D /* CustomerCenterConfigData.swift */,
);
path = CustomerCenter;
Expand Down Expand Up @@ -3764,6 +3789,15 @@
path = Locale;
sourceTree = "<group>";
};
35F7884C2CC68F5F00080F32 /* Events */ = {
isa = PBXGroup;
children = (
35F788F52CC6B62400080F32 /* EventsRequest+CustomerCenter.swift */,
35F7884A2CC68F4C00080F32 /* CustomerCenterEvent.swift */,
);
path = Events;
sourceTree = "<group>";
};
35F82BBB26A9BFA60051DF03 /* FoundationExtensions */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -5721,6 +5755,7 @@
2C0B98CD2797070B00C5874F /* PromotionalOffer.swift in Sources */,
57DC9F4627CC2E4900DA6AF9 /* HTTPRequest.swift in Sources */,
2DC5623024EC63730031F69B /* OperationDispatcher.swift in Sources */,
352137322CDBA2AA00FE961B /* FeatureEvent.swift in Sources */,
35D159CB2BC4396F004D8061 /* DiagnosticsPostOperation.swift in Sources */,
575642B62910116900719219 /* EligibilityStrings.swift in Sources */,
4F87610F2A5C9E490006FA14 /* PaywallData.swift in Sources */,
Expand All @@ -5747,6 +5782,7 @@
B34605C5279A6E380031CA74 /* CustomerInfoResponseHandler.swift in Sources */,
5796A3A927D7C43500653165 /* Deprecations.swift in Sources */,
4F0201C42A13C85500091612 /* Assertions.swift in Sources */,
35F7884B2CC68F5300080F32 /* CustomerCenterEvent.swift in Sources */,
5753ED8E294A662400CBAB54 /* DateFormatter+Extensions.swift in Sources */,
4F174F472B07EA7E00FE538E /* StorefrontProvider.swift in Sources */,
B3AA6238268B926F00894871 /* SystemInfo.swift in Sources */,
Expand All @@ -5770,6 +5806,7 @@
FDAC7B532CD3D67600DFC0D9 /* WinBackOfferEligibilityCalculatorType.swift in Sources */,
B34605C0279A6E380031CA74 /* CustomerInfoCallback.swift in Sources */,
B33CEAA0268CDCC9008A3144 /* ISOPeriodFormatter.swift in Sources */,
356523A82CF7719C00B6E3EA /* CustomerCenterPresentationMode.swift in Sources */,
4FBBC5682A61E42F0077281F /* NonEmptyStringDecodable.swift in Sources */,
2DDF41A324F6F331005BC22D /* PurchasesReceiptParser.swift in Sources */,
2CB8CF9327BF538F00C34DE3 /* PlatformInfo.swift in Sources */,
Expand Down Expand Up @@ -5931,6 +5968,7 @@
B34D2AA0269606E400D88C3A /* IntroEligibility.swift in Sources */,
F516BD29282434070083480B /* StoreKit2StorefrontListener.swift in Sources */,
4D6ABB102AF13FBD00BB2A08 /* SK2AppTransaction.swift in Sources */,
35F788F62CC6B62600080F32 /* EventsRequest+CustomerCenter.swift in Sources */,
5766AAB0283D8CDC00FA6091 /* CacheFetchPolicy.swift in Sources */,
4FD368B42AA7CFED00F63354 /* PaywallEventStore.swift in Sources */,
B302206E2728B798008F1A0D /* BackendErrorStrings.swift in Sources */,
Expand Down Expand Up @@ -6099,6 +6137,7 @@
57544C28285FA94B004E54D5 /* MockAttributeSyncing.swift in Sources */,
4F34AEEC2A5DCCBA00F4BCB0 /* VerificationResultTests.swift in Sources */,
FD2046832CB833CD00166727 /* MockStoreKit2PurchaseIntentListenerDelegate.swift in Sources */,
356523AC2CF890F400B6E3EA /* CustomerCenterEventsRequestTests.swift in Sources */,
1EFA95102CDB7FAA00CA5951 /* WebPurchaseRedemptionHelperTests.swift in Sources */,
35AAEB4C2BBC39D100A12548 /* DiagnosticsFileHandlerTests.swift in Sources */,
57DE80802807529F008D6C6F /* MockStorefront.swift in Sources */,
Expand Down Expand Up @@ -6559,6 +6598,7 @@
3544DA6F2C2C848E00704E9D /* ManageSubscriptionsViewModelTests.swift in Sources */,
887A63382C1D177800E1A461 /* PurchaseHandlerTests.swift in Sources */,
887A63392C1D177800E1A461 /* OtherPaywallViewTests.swift in Sources */,
356523AA2CF885D300B6E3EA /* MockCustomerCenterPurchases.swift in Sources */,
3544DA6D2C2C848E00704E9D /* CustomerCenterViewModelTests.swift in Sources */,
887A633A2C1D177800E1A461 /* PaywallViewDynamicTypeTests.swift in Sources */,
35A99C832CCB95950074AB41 /* SubscriptionInformationFixtures.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import RevenueCat
@available(watchOS, unavailable)
protocol CustomerCenterPurchasesType: Sendable {

var isSandbox: Bool { get }

@Sendable
func customerInfo() async throws -> CustomerInfo

Expand All @@ -34,4 +36,6 @@ protocol CustomerCenterPurchasesType: Sendable {
promotionalOffer: PromotionalOffer
) async throws -> PurchaseResultData

func track(customerCenterEvent: CustomerCenterEvent)

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ import RevenueCat
@available(watchOS, unavailable)
final class CustomerCenterPurchases: CustomerCenterPurchasesType {

var isSandbox: Bool {
return Purchases.shared.isSandbox
}

func customerInfo() async throws -> RevenueCat.CustomerInfo {
try await Purchases.shared.customerInfo()
}
Expand All @@ -43,4 +47,9 @@ final class CustomerCenterPurchases: CustomerCenterPurchasesType {
promotionalOffer: promotionalOffer
)
}

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

}
20 changes: 0 additions & 20 deletions RevenueCatUI/CustomerCenter/View+PresentCustomerCenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,6 @@ import SwiftUI

#if os(iOS)

/// Warning: This is currently in beta and subject to change.
///
/// Presentation options to use with the [presentCustomerCenter](x-source-tag://presentCustomerCenter) View modifiers.
public enum CustomerCenterPresentationMode {

/// Customer center presented using SwiftUI's `.sheet`.
case sheet

/// Customer center presented using SwiftUI's `.fullScreenCover`.
case fullScreen

}

extension CustomerCenterPresentationMode {

// swiftlint:disable:next missing_docs
public static let `default`: Self = .sheet

}

@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
@available(macOS, unavailable, message: "RevenueCatUI does not support macOS yet")
@available(tvOS, unavailable, message: "RevenueCatUI does not support tvOS yet")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import RevenueCat
// We fail open.
private static let defaultAppIsLatestVersion = true

typealias CustomerInfoFetcher = @Sendable () async throws -> CustomerInfo
typealias CurrentVersionFetcher = () -> String?

private lazy var currentAppVersion: String? = currentVersionFetcher()
Expand All @@ -37,6 +36,7 @@ import RevenueCat
private(set) var hasAppleEntitlement: Bool = false
@Published
private(set) var appIsLatestVersion: Bool = defaultAppIsLatestVersion
private(set) var purchasesProvider: CustomerCenterPurchasesType

// @PublicForExternalTesting
@Published
Expand Down Expand Up @@ -68,26 +68,22 @@ import RevenueCat
return state != .notLoaded && configuration != nil
}

private var customerInfoFetcher: CustomerInfoFetcher
private let currentVersionFetcher: CurrentVersionFetcher
internal let customerCenterActionHandler: CustomerCenterActionHandler?

private var error: Error?

init(
customerCenterActionHandler: CustomerCenterActionHandler?,
customerInfoFetcher: @escaping CustomerInfoFetcher = {
guard Purchases.isConfigured else { throw PaywallError.purchasesNotConfigured }
return try await Purchases.shared.customerInfo()
},
currentVersionFetcher: @escaping CurrentVersionFetcher = {
Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String
}
},
purchasesProvider: CustomerCenterPurchasesType = CustomerCenterPurchases()
) {
self.state = .notLoaded
self.customerInfoFetcher = customerInfoFetcher
self.currentVersionFetcher = currentVersionFetcher
self.customerCenterActionHandler = customerCenterActionHandler
self.purchasesProvider = purchasesProvider
}

#if DEBUG
Expand All @@ -106,7 +102,7 @@ import RevenueCat

func loadHasActivePurchases() async {
do {
let customerInfo = try await self.customerInfoFetcher()
let customerInfo = try await purchasesProvider.customerInfo()
self.hasActiveProducts = customerInfo.activeSubscriptions.count > 0 ||
customerInfo.nonSubscriptions.count > 0
self.hasAppleEntitlement = customerInfo.entitlements.active.contains { entitlement in
Expand Down Expand Up @@ -139,6 +135,17 @@ import RevenueCat
}
}

func trackImpression(darkMode: Bool, displayMode: CustomerCenterPresentationMode) {
let isSandbox = purchasesProvider.isSandbox
let eventData = CustomerCenterEvent.Data(locale: .current,
darkMode: darkMode,
isSandbox: isSandbox,
displayMode: displayMode)
let event = CustomerCenterEvent.impression(CustomerCenterEvent.CreationData(), eventData)

purchasesProvider.track(customerCenterEvent: event)
}

}

fileprivate extension String {
Expand Down
Loading