Adds AB Testing support (ExPlat)#155
Conversation
|
@mokagio I removed your private specs because the build was failing on the CI machine. Just want to double-check if this will not cause any unintended issue. |
astralbodies
left a comment
There was a problem hiding this comment.
It probably makes sense to tie the ExPlat service into the Tracks service somehow so it can respond to auth/de-auth scenarios already set up in the host app.
Methods used by the host app to track auth: https://github.com/Automattic/Automattic-Tracks-iOS/blob/trunk/Automattic-Tracks-iOS/Services/TracksService.h#L29
Those two methods are already hooked in somewhere in the host app based on the auth lifecycle. The only thing this doesn't give you is the OAuth bearer token, of course. Just figured since we already deal with going from anon -> logged in -> anon with Tracks.
|
Also, consider adding the OAuth Bearer token to the methods tracking authentication state. Since that token changes at the same time (usually), the TracksService could be the owner of that data, and then later inject that into the ExPlat service for use. Does ExPlat work without a Bearer token? Wonder how that affects anonymous users / users not yet logged in. |
|
Hey @leandroalonso, sorry for the long time it took me to get to this 😞 🙏 You did well. I'm pretty sure I added them in there only because the CDN didn't seem to find the |
|
@astralbodies ready for another review! ExPlat is now coupled with I have one question: I kept both the old method and the new one with a |
|
@leandroalonso I'm terribly sorry for missing this code review. I will be reviewing it today! |
| @@ -27,6 +27,7 @@ extern NSString *const TrackServiceDidSendQueuedEventsNotification; | |||
| - (NSDictionary *)dictionaryForTracksEvent:(TracksEvent *)tracksEvent withParentCommonProperties:(NSDictionary *)parentCommonProperties; | |||
|
|
|||
| - (void)switchToAuthenticatedUserWithUsername:(NSString *)username userID:(NSString *)userID skipAliasEventCreation:(BOOL)skipEvent; | |||
There was a problem hiding this comment.
I was thinking about maybe having you add a deprecation warning here... But then I think Simplenote uses this client as well, and they don't use WordPress.com logins. Now that has me wondering if we should name the token in the new method to be a wpcom bearer token for clarity.
There was a problem hiding this comment.
Do you mean something like that?
- (void)switchToAuthenticatedUserWithUsername:(NSString *)username userID:(NSString *)userID wpComToken:(NSString *)token skipAliasEventCreation:(BOOL)skipEvent;
astralbodies
left a comment
There was a problem hiding this comment.
This looks good! I didn't test out the functionality with the backend system. I did suggest maybe changing the parameter name a bit for clarity's sake.
|
@leandroalonso Ah crap, I didn't notice this PR was targeting @jkmassel can we fix that? |
|
@astralbodies I already fixed. 😅 |
| public func experiment(_ name: String) -> Variation { | ||
| guard let assignments = UserDefaults.standard.object(forKey: assignmentsKey) as? [String: String?], | ||
| case let variation?? = assignments[name] else { | ||
| return .unknown |
There was a problem hiding this comment.
It may be better to consider returning .control instead of .unknown so that an old client can properly fall back to the control experience if the experiment is no longer available.
| @@ -0,0 +1,6 @@ | |||
| { | |||
| "variations": { | |||
| "experiment": "control" | |||
There was a problem hiding this comment.
Explat will never return the name of the control variation, For control, it always returns null and/or it won't exist in the response. It only returns the name of treatment variations. Right now, we only support a singular treatment, but multi-variate experiments are in the works.
This PR adds AB Testing support.
Configuration
(WPiOS PR here: wordpress-mobile/WordPress-iOS#15236)
Before having fun with AB testing, the app needs to configure the ExPlat instance. To do so, the
switchToAuthenticatedUserWithUsernamemethod was changed and now it requires atokenparameter.An example from WPiOS:
Then, you need to call the method
refreshIfNeeded()indidFinishLaunchingWithOptions.And that's all. :)
Usage
Once it's configured you can use like this:
Or, more simpler: