Skip to content

Paywalls: add identifier to events#3332

Merged
joshdholtz merged 27 commits into
mainfrom
paywalls-events-add-id
Oct 26, 2023
Merged

Paywalls: add identifier to events#3332
joshdholtz merged 27 commits into
mainfrom
paywalls-events-add-id

Conversation

@joshdholtz

@joshdholtz joshdholtz commented Oct 24, 2023

Copy link
Copy Markdown
Member

Motivation

Send a unique id on each paywall event

Description

  • Added id: ID? to PaywallEvent.Data
    • Optional so its backwards compatible with events recorded before this change (see actual tests from below)
  • Add withNewID() function that will mutate the id when tracked for cancel and close

Events recored before id changes but posted with id changes

Screenshot 2023-10-25 at 9 33 27 AM

Events recorded and posted with id changes

Screenshot 2023-10-25 at 9 37 53 AM

@joshdholtz joshdholtz force-pushed the paywalls-events-add-id branch 2 times, most recently from fd7f872 to 71acd2b Compare October 24, 2023 11:16
@NachoSoto

Copy link
Copy Markdown
Contributor

How are you thinking of this not being backwards compatible? Just drop previous unsent events?

@joshdholtz

Copy link
Copy Markdown
Member Author

How are you thinking of this not being backwards compatible? Just drop previous unsent events?

@NachoSoto The backend has this event id being optional so that its backwards compatible 🤷‍♂️ I could have made new "version 2" validation models on the backend but it wouldn't provide that much value and more code to maintain

@NachoSoto

Copy link
Copy Markdown
Contributor

What i mean is that PaywallStoredEvent/PaywallEvent now has a new mandatory field, so PaywallEventStore.fetch will not decode them anymore.

Comment thread Sources/Paywalls/Events/PaywallEvent.swift Outdated
Comment thread Sources/Paywalls/Events/PaywallEvent.swift Outdated
Base automatically changed from paywalls-only-track-impression-and-close-once to main October 24, 2023 20:21
@joshdholtz joshdholtz force-pushed the paywalls-events-add-id branch from 78eb666 to e4ba124 Compare October 24, 2023 20:31
NachoSoto and others added 18 commits October 25, 2023 09:00
The current API only provided a `CustomerInfo`.
Note that this does not include `userCanceled`. We can expose separately with another `.onPurchaseCancelled` modifier in the future.
These were failing in some of the earlier Xcode 15 betas, but they all seem to be passing now.
`PresentIfNeededTests` are still not working though. But I just manually verified that these modifiers do work correctly on iOS 17 on an app.
The current API only provided a `CustomerInfo`.
Note that this does not include `userCanceled`. We can expose separately with another `.onPurchaseCancelled` modifier in the future.
…3335)

Requested by @joshdholtz for
[paywalls-events-add-id](https://github.com/RevenueCat/purchases-ios/tree/paywalls-events-add-id)

Co-authored-by: Distiller <distiller@static.38.39.183.26.cyberlynk.net>
…3336)

Requested by @joshdholtz for
[paywalls-events-add-id](https://github.com/RevenueCat/purchases-ios/tree/paywalls-events-add-id)

Co-authored-by: Distiller <distiller@static.38.39.184.242.cyberlynk.net>
…3337)

Requested by @joshdholtz for
[paywalls-events-add-id](https://github.com/RevenueCat/purchases-ios/tree/paywalls-events-add-id)

Co-authored-by: distiller <distiller@static.38.23.41.34.cyberlynk.net>
@joshdholtz joshdholtz force-pushed the paywalls-events-add-id branch from c1e0b1a to e8cf052 Compare October 25, 2023 14:23
@joshdholtz joshdholtz force-pushed the paywalls-events-add-id branch from e8cf052 to 07fa54a Compare October 25, 2023 14:25
}

self.track(.close(data.withCurrentDate()))
self.track(.close(data.withNewID().withCurrentDate()))

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need this otherwise the id was the same for each event in the session 😅

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a smell in how we're using the type.

I think to prevent this we should put the Event.ID inside of PaywallEvent not PaywallEvent.Data. What do you think?

public struct Data {

// swiftlint:disable missing_docs
public var id: ID?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional to make backwards compatible with previously stored events

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's leave a comment explaining that.

@joshdholtz joshdholtz requested a review from NachoSoto October 25, 2023 15:02
@joshdholtz joshdholtz marked this pull request as ready for review October 25, 2023 15:02
@codecov

codecov Bot commented Oct 25, 2023

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 96.55172% with 1 line in your changes missing coverage. Please review.

Project coverage is 86.00%. Comparing base (50bd457) to head (37a328b).
Report is 499 commits behind head on main.

Files with missing lines Patch % Lines
Sources/Paywalls/Events/PaywallEvent.swift 93.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3332      +/-   ##
==========================================
+ Coverage   85.98%   86.00%   +0.02%     
==========================================
  Files         237      237              
  Lines       17086    17097      +11     
==========================================
+ Hits        14691    14704      +13     
+ Misses       2395     2393       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@NachoSoto NachoSoto left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost ready, a few comments:

  • Re-using event data and having to change IDs
  • Test for posting events with no ID
  • Also can you add a test in PaywallEventStoreTests that verifies that we can fetch events with no ID?

}

self.track(.close(data.withCurrentDate()))
self.track(.close(data.withNewID().withCurrentDate()))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a smell in how we're using the type.

I think to prevent this we should put the Event.ID inside of PaywallEvent not PaywallEvent.Data. What do you think?

public struct Data {

// swiftlint:disable missing_docs
public var id: ID?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's leave a comment explaining that.

let data = storedEvent.event.data

self.init(
id: data.id?.uuidString,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a test verifying that we can send events with no ID.

@NachoSoto

Copy link
Copy Markdown
Contributor

Nit: I'd mark this as a "refactor" since it's not a user facing change that users need to know about in the release notes IMO.

}

self.track(.cancel(data.withCurrentDate()))
self.track(.cancel(.init(), data))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much better 👍🏻

@joshdholtz joshdholtz merged commit 38b4e3b into main Oct 26, 2023
@joshdholtz joshdholtz deleted the paywalls-events-add-id branch October 26, 2023 01:26
NachoSoto added a commit that referenced this pull request Oct 26, 2023
**This is an automatic release.**

### New Features
* `PaywallColor`: change visibility of `Color.init(light:dark:)` to
`private` (#3345) via NachoSoto (@NachoSoto)
### RevenueCatUI
* `Paywalls`: new `.onPurchaseCompleted` overload with
`StoreTransaction` (#3323) via NachoSoto (@NachoSoto)
* `Paywalls`: finished template 5 (#3340) via NachoSoto (@NachoSoto)
* `Paywalls`: new `onDismiss` parameter for `presentPaywallIfNeeded`
(#3342) via NachoSoto (@NachoSoto)
* `Paywalls`: disable shimmering on footer loading view (#3324) via
NachoSoto (@NachoSoto)
### Bugfixes
* `ErrorUtils.purchasesError(withSKError:)`: handle `URLError`s (#3346)
via NachoSoto (@NachoSoto)
### Other Changes
* `Paywalls`: add identifier to events (#3332) via Josh Holtz
(@joshdholtz)
* `Paywalls`: create new event session when paywall appears (#3330) via
Josh Holtz (@joshdholtz)
* `HTTPClient`: verbose logs for request IDs (#3320) via NachoSoto
(@NachoSoto)
* `Paywalls Tester`: fix `macOS` build (#3341) via NachoSoto
(@NachoSoto)
* `ProductFetcherSK1`: enable `TimingUtil` log (#3327) via NachoSoto
(@NachoSoto)
* `Paywall Tester`: fixed paywall presentation (#3339) via NachoSoto
(@NachoSoto)
* `CI`: replace Carthage build jobs with `xcodebuild` (#3338) via
NachoSoto (@NachoSoto)
* `Integration Tests`: use repetition count from test plan (#3329) via
NachoSoto (@NachoSoto)
* `Integration Tests`: new logs for troubleshooting flaky tests (#3328)
via NachoSoto (@NachoSoto)
* `CircleCI`: change iOS 17 job to use M1 Large resource (#3322) via
NachoSoto (@NachoSoto)
* `Paywalls Tester`: fix release build (#3321) via NachoSoto
(@NachoSoto)
* `Paywalls`: enable all iOS 17 tests (#3331) via NachoSoto (@NachoSoto)
* `CI`: added workaround for Snapshots in `Xcode Cloud` (#2857) via
NachoSoto (@NachoSoto)
* `StoreKit 1`: disabled `finishTransactions` log on observer mode
(#3314) via NachoSoto (@NachoSoto)

---------

Co-authored-by: NachoSoto <ignaciosoto90@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants