Paywalls: Store paywall events on disk and API (1)#1436
Conversation
| * Used by `RevenueCatUI` to keep track of [PaywallEvent]s. | ||
| */ | ||
| @ExperimentalPreviewRevenueCatPurchasesAPI | ||
| @JvmSynthetic |
There was a problem hiding this comment.
Made this synthetic since this is really only meant for our use in RevenueCatUI which uses Kotlin.
| val dispatcher = Dispatcher(createDefaultExecutor(), runningIntegrationTests) | ||
| val backendDispatcher = Dispatcher(service ?: createDefaultExecutor(), runningIntegrationTests) | ||
| val diagnosticsDispatcher = Dispatcher(createDiagnosticsExecutor(), runningIntegrationTests) | ||
| val eventsDispatcher = Dispatcher(createEventsExecutor(), runningIntegrationTests) |
There was a problem hiding this comment.
I decided to share the dispatcher between diagnostics and paywall events, so I renamed a few things.
| identityManager: IdentityManager, | ||
| eventsDispatcher: Dispatcher, | ||
| ): PaywallEventsManager? { | ||
| return if (isAndroidNOrNewer()) { |
There was a problem hiding this comment.
This shouldn't be a problem since revenuecatui already is N+. But since the main SDK isn't and we're using streams, I had to add this.
There was a problem hiding this comment.
Maybe add a comment mentioning that?
| /** | ||
| * Types of paywall events. Meant for RevenueCatUI use. | ||
| */ | ||
| @ExperimentalPreviewRevenueCatPurchasesAPI |
There was a problem hiding this comment.
I added experimental annotations on these classes for now. I think we can remove them once paywalls is completely final.
| data class PaywallEvent( | ||
| val creationData: CreationData, | ||
| val data: Data, | ||
| val type: PaywallEventType, |
There was a problem hiding this comment.
I thought about using a sealed class to mimick what we do in iOS... But that was slightly trickier to serialize using kotlin serializers, and I didn't think it was worth the hassle, specially for now where all events have the same data. If we have events with different data in the future, we can revisit this.
| } | ||
|
|
||
| @Synchronized | ||
| fun readFile(streamBlock: ((Stream<PaywallStoredEvent>) -> Unit)) { |
There was a problem hiding this comment.
This is currently unused, but will be used in a followup PR. Partially copied from DiagnosticsFileHelper.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1436 +/- ##
==========================================
- Coverage 84.13% 83.99% -0.14%
==========================================
Files 197 203 +6
Lines 6649 6717 +68
Branches 965 975 +10
==========================================
+ Hits 5594 5642 +48
- Misses 684 698 +14
- Partials 371 377 +6 ☔ View full report in Codecov by Sentry. |
| * Used by `RevenueCatUI` to keep track of [PaywallEvent]s. | ||
| */ | ||
| @ExperimentalPreviewRevenueCatPurchasesAPI | ||
| @JvmSynthetic |
| identityManager: IdentityManager, | ||
| eventsDispatcher: Dispatcher, | ||
| ): PaywallEventsManager? { | ||
| return if (isAndroidNOrNewer()) { |
There was a problem hiding this comment.
Maybe add a comment mentioning that?
| @Test | ||
| fun `can encode paywall event correctly`() { | ||
| val eventString = PaywallEventsManager.json.encodeToString(event) | ||
| assertThat(eventString).isEqualTo( |
There was a problem hiding this comment.
I imagine you compared these with iOS 👍🏻
There was a problem hiding this comment.
These are different than in iOS, but it's the way they are stored in disk, so it shouldn't matter if they are different I think. In iOS, the encoding is pretty different, but all the data is there.
There was a problem hiding this comment.
Oh yeah of course never mind
**This is an automatic release.** ### RevenueCatUI * `PaywallActivityLauncher`: new constructor for a generic `ActivityResultCaller` (#1441) via NachoSoto (@NachoSoto) * Improve fullscreen templates in landscape orientation (#1435) via Toni Rico (@tonidero) * `Paywalls`: improve Japanese localization (#1439) via NachoSoto (@NachoSoto) ### Other Changes * Remove side effect from setting purchasesUpdatedListener (#1443) via Cesar de la Vega (@vegaro) * Paywalls: Store paywall events on disk and API (1) (#1436) via Toni Rico (@tonidero) --------- Co-authored-by: revenuecat-ops <ops@revenuecat.com> Co-authored-by: NachoSoto <ignaciosoto90@gmail.com>
### Description This follows up on #1436. Here we are adding the code to send paywall events to our servers. This is not connected with the work done in #1436 yet. That will be done in followup PRs. - [ ] Actually read events from disk and use this to send them to servers. - [ ] Use paywall events to detect whether a purchase came from a paywall.
Description
This adds support for storing paywall events into disk. In followup PRs, we will send these events to our servers for analytics and use these events to indicate whether a purchase came from our paywalls.