Skip to content

Conversation

@selanthiraiyan
Copy link
Contributor

@selanthiraiyan selanthiraiyan commented Feb 2, 2023

Closes: #8782

Description

Raising this PR based on the solution we reached after discussions in this PR - #8788

We are caching the variation values of logged-out experiments to try to address the high crossovers that we see in Explat.

As this PR targets the release branch, I have cherry-picked commits from this PR #8769. This is done to import ABTestVariationProvider

Testing instructions

  • Install and launch the app. Log out if needed.
  • Launch and skip onboarding.
  • If you don't see the "Continue With WordPress.com" button to log in you have been assigned treatment variation for the woocommerceios_login_rest_api_project_202301_v2 experiment and you can test this PR (If not, you need to use a sandbox to force a variation. You can follow the instructions from this PR to assign a variation to your device.)
  • Login into the app using site creds.
  • Go to settings and log out.
  • You will be navigated to the login screen and ensure that you still don't see the "Continue With WordPress.com" button. i.e. You are still assigned the treatment variation.

Screenshots

NA


  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

@selanthiraiyan selanthiraiyan added type: bug A confirmed bug. feature: login Related to any part of the log in or sign in flow, or authentication. labels Feb 2, 2023
@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Feb 2, 2023

You can test the changes from this Pull Request by:
  • Clicking here or scanning the QR code below to access App Center
  • Then installing the build number pr8806-d6df1c6 on your iPhone

If you need access to App Center, please ask a maintainer to add you.

@selanthiraiyan selanthiraiyan marked this pull request as ready for review February 2, 2023 04:30
@itsmeichigo itsmeichigo self-assigned this Feb 2, 2023
}

public func variation(for abTest: ABTest) -> Variation {
guard abTest.context == .loggedOut else {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: should we leave a comment on why we are caching only for the logged-out context.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure if we need to restrict to logged-out experiments only 🤔 We are requesting only experiments for specific contexts so it should be safe to apply this for all contexts right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We are requesting only experiments for specific contexts so it should be safe to apply this for all contexts right?

I hope you mean that we only request experiments for current contexts from the server. Yes, I agree.

But, I would still prefer only to cache logged-out experiments to minimize the impact of this change. Also, we don't face any crossover issues with logged-in experiments.

WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense, please go ahead with this solution 👍

let cache = VariationCache(userDefaults: userDefaults)

// When
try cache.assign(variation: .treatment, for: .applicationPasswordAuthentication)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: should we create mock tests instead to avoid having to update this test when the experiment is removed?

Copy link
Contributor Author

@selanthiraiyan selanthiraiyan Feb 2, 2023

Choose a reason for hiding this comment

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

Good point. Done in e0d9ee5 and 737ee32

let cache = VariationCache(userDefaults: userDefaults)

// When
XCTAssertThrowsError(try cache.assign(variation: .treatment, for: .aaTestLoggedIn))
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Same comment as above about mocking A/B test.

Copy link
Contributor Author

@selanthiraiyan selanthiraiyan Feb 2, 2023

Choose a reason for hiding this comment

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

Done in e0d9ee5 and 737ee32

Comment on lines 18 to 25
if let cachedVariation = cache.variation(for: abTest) {
return cachedVariation
} else if let variation = abTest.variation {
try? cache.assign(variation: variation, for: abTest)
return variation
} else {
return .control
}
Copy link
Contributor

@itsmeichigo itsmeichigo Feb 2, 2023

Choose a reason for hiding this comment

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

I think we should prioritize fresh values, i.e. getting the variation from abTest and only use cache as the fallback. That way we always get the latest values:

Suggested change
if let cachedVariation = cache.variation(for: abTest) {
return cachedVariation
} else if let variation = abTest.variation {
try? cache.assign(variation: variation, for: abTest)
return variation
} else {
return .control
}
if let variation = abTest.variation {
try? cache.assign(variation: variation, for: abTest)
return variation
} else if let cachedVariation = cache.variation(for: abTest) {
return cachedVariation
} else {
return .control
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in c0708bf

Earlier, I prioritised cached value to display that we return the cached value if it is available. Because, for a logged-out experiment, it is perfectly valid to get the variation value only once and use it without refresh.

Copy link
Contributor

@itsmeichigo itsmeichigo left a comment

Choose a reason for hiding this comment

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

🚀

@peril-woocommerce
Copy link

Warnings
⚠️ This PR is assigned to a milestone which is closing in less than 2 days Please, make sure to get it merged by then or assign it to a later expiring milestone

Generated by 🚫 dangerJS

@selanthiraiyan selanthiraiyan merged commit a20f9b7 into release/12.1 Feb 3, 2023
@selanthiraiyan selanthiraiyan deleted the bugfix/8782-cache-logged-out-ab-tests branch February 3, 2023 08:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature: login Related to any part of the log in or sign in flow, or authentication. type: bug A confirmed bug.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants