Paywalls: Support sending paywall events to servers (2)#1442
Conversation
db7f1b9 to
3575c2d
Compare
| @Volatile var diagnosticsCallbacks = mutableMapOf<CallbackCacheKey, MutableList<DiagnosticsCallback>>() | ||
|
|
||
| @get:Synchronized @set:Synchronized | ||
| @Volatile var paywallEventsCallbacks = mutableMapOf<CallbackCacheKey, MutableList<PaywallEventsCallback>>() |
There was a problem hiding this comment.
We might want to think about refactoring the backend class. It's pretty huge now, and it has a lot of duplicated logic for each request... For now, I created a Linear ticket for this.
There was a problem hiding this comment.
👍🏻 yeah long overdue separation as we did in iOS
| backend.postPaywallEvents( | ||
| request, | ||
| onSuccessHandler = { | ||
| latch.countDown() |
There was a problem hiding this comment.
Here we're basically only making sure the request succeeds, since there is not much to check otherwise I think
There was a problem hiding this comment.
We use snapshot tests in iOS to verify the request format. Would it be possible to at least verify the body of the request?
There was a problem hiding this comment.
I do this in the unit tests, not the backend integration tests: https://github.com/RevenueCat/purchases-android/pull/1442/files#diff-611e526013c5cd77f7141eb4ece99c74f81ecd9477bf84bf0f528e506ad40199R95. Lmk if you think we should still do that here... Might be tricky to intercept though, so I kinda think this is enough
3f175fb to
d0e558c
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1442 +/- ##
==========================================
- Coverage 83.99% 83.67% -0.33%
==========================================
Files 203 206 +3
Lines 6717 6816 +99
Branches 975 990 +15
==========================================
+ Hits 5642 5703 +61
- Misses 698 727 +29
- Partials 377 386 +9 ☔ View full report in Codecov by Sentry. |
…ark events as synced or not
316e913 to
de9b279
Compare
| @Volatile var diagnosticsCallbacks = mutableMapOf<CallbackCacheKey, MutableList<DiagnosticsCallback>>() | ||
|
|
||
| @get:Synchronized @set:Synchronized | ||
| @Volatile var paywallEventsCallbacks = mutableMapOf<CallbackCacheKey, MutableList<PaywallEventsCallback>>() |
There was a problem hiding this comment.
👍🏻 yeah long overdue separation as we did in iOS
| ) | ||
| } | ||
|
|
||
| override fun onError(error: PurchasesError) { |
There was a problem hiding this comment.
Also outside the scope of this PR, but there is a lot of repetition on how we make requests as well that would be useful to abstract.
| appConfig.paywallEventsURL, | ||
| Endpoint.PostPaywallEvents, |
There was a problem hiding this comment.
It took me a while to find where this was defined. I feel like paywallEventsURL should be part of the Endpoint configuration. What do you think? Otherwise it would be possible (at compile time) to make a request to conflicting endpoints / domains.
There was a problem hiding this comment.
Hmm we could certainly move it there, but I also feel with the upcoming work for adding fallback base URLs, it might be better to keep separate... Honestly, I could see it going either way.
There was a problem hiding this comment.
I'm gonna hold on this until we actually rewrite the networking code to not increase the size of this PR even more.
There was a problem hiding this comment.
Sounds good, and that's a good point.
| // Note: this means that all 4xx (except 404) are considered as successfully synced. | ||
| // The reason is because it's likely due to a client error, so continuing to retry | ||
| // won't yield any different results and instead kill pandas. | ||
| fun isSynced(statusCode: Int) = isSuccessful(statusCode) || !(isServerError(statusCode) || statusCode == NOT_FOUND) |
There was a problem hiding this comment.
I'm surprised this didn't exist yet. We use it in iOS for marking attributes as synced.
There was a problem hiding this comment.
Hmm that's slightly different in Android for subscriber attributes... There, we would mark them as synced if it's not a server error and we receive a backend error code 24 (UnsupportedError), but we don't mark them as synced with 404... I guess we could add that as well?
| import kotlinx.serialization.json.jsonPrimitive | ||
| import kotlinx.serialization.json.longOrNull | ||
|
|
||
| fun JsonElement.asMap(): Map<String, Any?>? { |
| backend.postPaywallEvents( | ||
| request, | ||
| onSuccessHandler = { | ||
| latch.countDown() |
There was a problem hiding this comment.
We use snapshot tests in iOS to verify the request format. Would it be possible to at least verify the body of the request?
| @Test | ||
| fun `Paywall events has correct path`() { | ||
| val endpoint = Endpoint.PostPaywallEvents | ||
| val expectedPath = "/events" | ||
| assertThat(endpoint.getPath()).isEqualTo(expectedPath) | ||
| } | ||
|
|
There was a problem hiding this comment.
Ideally this verifies the domain too if/when that's part of Endpoint.
| every { baseURL } returns URL("https://api.revenuecat.com") | ||
| every { paywallEventsURL } returns URL("https://api-paywalls.revenuecat.com/") |
There was a problem hiding this comment.
This could use AppConfig instead of duplicating it?
There was a problem hiding this comment.
Yeah, just have to expose it, but might be better.
**This is an automatic release.** ### RevenueCatUI * `Paywalls`: improve error log when images fail to load (#1454) via NachoSoto (@NachoSoto) ### Other Changes * Paywall events: Send paywall data with post receipt requests (#1452) via Toni Rico (@tonidero) * Paywalls: Track paywall events (#1447) via Toni Rico (@tonidero) * Paywall events: Handle errors parsing specific paywall event lines (#1451) via Toni Rico (@tonidero) * Paywalls: Move logic for events file helper to common generic class (4) (#1446) via Toni Rico (@tonidero) * Paywalls: Add paywall events flush logic and tests (3) (#1445) via Toni Rico (@tonidero) * Paywalls: Support sending paywall events to servers (2) (#1442) via Toni Rico (@tonidero) * `CircleCI`: fix `record-revenuecatui-snapshots` (#1455) via NachoSoto (@NachoSoto) * Lower request jitter log level from warning to debug (#1453) via Toni Rico (@tonidero) Co-authored-by: revenuecat-ops <ops@revenuecat.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.