Rewrite AnalyticsTrackerAutomatticTracks in Swift - #24399
Conversation
Generated by 🚫 Danger |
| let name: String | ||
| var properties: [String: Any]? | ||
|
|
||
| switch stat { |
There was a problem hiding this comment.
There was no AI used – only search&replace, so there is no need to verify it.
|
| App Name | Jetpack | |
| Configuration | Release-Alpha | |
| Build Number | 27202 | |
| Version | PR #24399 | |
| Bundle ID | com.jetpack.alpha | |
| Commit | 84ffe73 | |
| Installation URL | 553blrmomqeo8 |
|
| App Name | WordPress | |
| Configuration | Release-Alpha | |
| Build Number | 27202 | |
| Version | PR #24399 | |
| Bundle ID | org.wordpress.alpha | |
| Commit | 84ffe73 | |
| Installation URL | 6l24ajbfe7uh0 |
| var mergedProperties: [AnyHashable: Any] = event.properties ?? [:] | ||
| for (key, value) in properties ?? [:] { | ||
| mergedProperties[key] = value | ||
| } |
There was a problem hiding this comment.
Nitpick: The above could be implemented in one line.
let mergedProperties = (event.properties ?? [:]).merging(properties ?? [:]) { (_, new) in new }
There was a problem hiding this comment.
Updated. I'm not sure why I keep avoiding merging. It is more clear and less code this way.
| track(stat, withProperties: nil) | ||
| } | ||
|
|
||
| public func track(_ stat: WPAnalyticsStat, withProperties properties: [AnyHashable: Any]?) { |
There was a problem hiding this comment.
Should the key of properties be String?
There was a problem hiding this comment.
It's how it's defined in the protocol. I would ideally update it to [String: EnumWithSupportedTypesOnly] to avoid any confusion.
| return | ||
| } | ||
|
|
||
| if currentUserID?.isEmpty == true { |
There was a problem hiding this comment.
The condition should be currentUserID?.isEmpty != false because currentUserID = nil should execute the if branch.
There was a problem hiding this comment.
The previous condition was the following:
if (self.loggedInID.length == 0) {The logic is that if you don't have any currentUserID saved, then call switchToAuthenticatedUser with skipAliasEventCreation: false. A != nil check should probably be enough, but I used isEmpty just for to be safe.
There was a problem hiding this comment.
Yeah, I added the comment because the condition check has changed. The previous condition is true if loggedInID is nil, but the new condition is false if currentUserID is nil.
There was a problem hiding this comment.
The condition should be
currentUserID?.isEmpty != false
It's the same as currentUserID?.isEmpty == true. It's true if currentUserID is empty.
There was a problem hiding this comment.
I don't think they are the same. currentUserID?.isEmpty has three possible values: Optional.some(true), .some(false), and Optional.none. If currentUserID is nil, currentUserID?.isEmpty would be nil and the if condition is false, which is the opssite of the original Objective-C code if (self.loggedInID.length == 0).
There was a problem hiding this comment.
Oh yeah you are totally right. I don't know who I missed that 🤦
I didn't want to move the conditions around, so I replaced this condition with the following (not great, but should be clear enough):
if (currentUserID ?? "").isEmptyIn the future, I feel like I'll just stop relying on these optional tricks.
479119b to
4181f81
Compare
ba6c0ef to
4d2b2ff
Compare
|
Hey, let's get this one merged folks, cc @mokagio , @crazytonyli |


This class had a lot of Swift APIs that it depended on. Prerequisite for Keystone. I carefully translated the code and compared it side-by-side multiple times. The risk of introducing user-facing regression is none because it's tracking.
To test:
Regression Notes
Potential unintended areas of impact
What I did to test those areas of impact (or what existing automated tests I relied on)
What automated tests I added (or what prevented me from doing so)
PR submission checklist:
RELEASE-NOTES.txtif necessary.Testing checklist: