-
Notifications
You must be signed in to change notification settings - Fork 316
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
Paywalls
: added Purchases.track(paywallEvent:)
#3160
Changes from 4 commits
f0fdf57
0fd3b32
d7d0f99
1eaa1db
10da09b
aea4214
f5d4d37
f4da78c
6cab9ac
1674106
ceb68b2
a450211
008eb88
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -246,6 +246,7 @@ public typealias StartPurchaseBlock = (@escaping PurchaseCompletedBlock) -> Void | |
private let offlineEntitlementsManager: OfflineEntitlementsManager | ||
private let productsManager: ProductsManagerType | ||
private let customerInfoManager: CustomerInfoManager | ||
private let paywallEventsManager: PaywallEventsManagerType? | ||
private let trialOrIntroPriceEligibilityChecker: CachingTrialOrIntroPriceEligibilityChecker | ||
private let purchasedProductsFetcher: PurchasedProductsFetcherType? | ||
private let purchasesOrchestrator: PurchasesOrchestrator | ||
|
@@ -339,6 +340,7 @@ public typealias StartPurchaseBlock = (@escaping PurchaseCompletedBlock) -> Void | |
transactionFetcher: StoreKit2TransactionFetcher(), | ||
transactionPoster: transactionPoster, | ||
systemInfo: systemInfo) | ||
|
||
let attributionDataMigrator = AttributionDataMigrator() | ||
let subscriberAttributesManager = SubscriberAttributesManager(backend: backend, | ||
deviceCache: deviceCache, | ||
|
@@ -351,6 +353,24 @@ public typealias StartPurchaseBlock = (@escaping PurchaseCompletedBlock) -> Void | |
attributeSyncing: subscriberAttributesManager, | ||
appUserID: appUserID) | ||
|
||
let paywallEventsManager: PaywallEventsManagerType? | ||
do { | ||
if #available(iOS 15.0, tvOS 15.0, macOS 12.0, watchOS 8.0, *) { | ||
paywallEventsManager = PaywallEventsManager( | ||
internalAPI: backend.internalAPI, | ||
userProvider: identityManager, | ||
store: try PaywallEventStore.createDefault() | ||
) | ||
Logger.verbose(Strings.paywalls.event_manager_initialized) | ||
} else { | ||
Logger.verbose(Strings.paywalls.event_manager_not_initialized_not_available) | ||
paywallEventsManager = nil | ||
} | ||
} catch { | ||
Logger.verbose(Strings.paywalls.event_manager_failed_to_initialize(error)) | ||
paywallEventsManager = nil | ||
} | ||
|
||
let attributionPoster = AttributionPoster(deviceCache: deviceCache, | ||
currentUserProvider: identityManager, | ||
backend: backend, | ||
|
@@ -453,6 +473,7 @@ public typealias StartPurchaseBlock = (@escaping PurchaseCompletedBlock) -> Void | |
subscriberAttributes: subscriberAttributes, | ||
operationDispatcher: operationDispatcher, | ||
customerInfoManager: customerInfoManager, | ||
paywallEventsManager: paywallEventsManager, | ||
productsManager: productsManager, | ||
offeringsManager: offeringsManager, | ||
offlineEntitlementsManager: offlineEntitlementsManager, | ||
|
@@ -479,6 +500,7 @@ public typealias StartPurchaseBlock = (@escaping PurchaseCompletedBlock) -> Void | |
subscriberAttributes: Attribution, | ||
operationDispatcher: OperationDispatcher, | ||
customerInfoManager: CustomerInfoManager, | ||
paywallEventsManager: PaywallEventsManagerType?, | ||
productsManager: ProductsManagerType, | ||
offeringsManager: OfferingsManager, | ||
offlineEntitlementsManager: OfflineEntitlementsManager, | ||
|
@@ -526,6 +548,7 @@ public typealias StartPurchaseBlock = (@escaping PurchaseCompletedBlock) -> Void | |
self.attribution = subscriberAttributes | ||
self.operationDispatcher = operationDispatcher | ||
self.customerInfoManager = customerInfoManager | ||
self.paywallEventsManager = paywallEventsManager | ||
self.productsManager = productsManager | ||
self.offeringsManager = offeringsManager | ||
self.offlineEntitlementsManager = offlineEntitlementsManager | ||
|
@@ -1031,6 +1054,30 @@ public extension Purchases { | |
|
||
// swiftlint:enable missing_docs | ||
|
||
// MARK: - Paywalls | ||
|
||
@available(iOS 15.0, tvOS 15.0, macOS 12.0, watchOS 8.0, *) | ||
public extension Purchases { | ||
|
||
/// Used by `RevenueCatUI` to keep track of ``PaywallEvent``s. | ||
func track(paywallEvent: PaywallEvent) async { | ||
switch paywallEvent { | ||
case let .view(data): | ||
self.purchasesOrchestrator.cachePresentedPaywall(data) | ||
|
||
case .close: | ||
self.purchasesOrchestrator.clearPresentedPaywall() | ||
NachoSoto marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
case .cancel: | ||
// No special handling, simply track the event below. | ||
break | ||
} | ||
|
||
await self.paywallEventsManager?.track(paywallEvent: paywallEvent) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we be moving this to the orchestrator layer? Ideally we do as little as possible at the Facade layer There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This has nothing to do with purchases though. |
||
} | ||
|
||
} | ||
|
||
// MARK: Configuring Purchases | ||
|
||
public extension Purchases { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
man I wish we could use
package
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We used to use objective-c headers added to the dependency for this kind of thing. I can't think of any clean way of doing this without having to expose the method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah...