Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Optimizely refactor #57

Merged
merged 7 commits into from
Jul 18, 2024
Merged

fix: Optimizely refactor #57

merged 7 commits into from
Jul 18, 2024

Conversation

rijuma
Copy link
Member

@rijuma rijuma commented Jul 16, 2024

This PR is a refactor of a bad first approach on integrating Optimizely to the repo.

Since this PR reverts some of the old code and adds the fixes it's a bit complicated to see. I'ts easier to look at it if we look at a compare of this branch with tag v2.1.4 to see all changes without the reverts.

@rijuma rijuma changed the title fix: Removing useDecision() to get the experiment states from Optimizely fix: Removing useDecision() to get the experiment states from Optimizely [WIP] Jul 16, 2024
@rijuma rijuma force-pushed the rijuma/optimizely-context-fix branch from 696e411 to 3de26cf Compare July 16, 2024 15:36
@rijuma rijuma changed the title fix: Removing useDecision() to get the experiment states from Optimizely [WIP] fix: Removing useDecision() to get the experiment states from Optimizely Jul 17, 2024
@rijuma rijuma force-pushed the rijuma/optimizely-context-fix branch from 676ee05 to 1b28cf5 Compare July 17, 2024 16:37
@rijuma rijuma changed the title fix: Removing useDecision() to get the experiment states from Optimizely fix: Optimizely refactor Jul 17, 2024
@rijuma rijuma marked this pull request as ready for review July 17, 2024 18:54
@@ -17,6 +19,11 @@ const MessageForm = ({ courseId, shouldAutofocus, unitId }) => {
const dispatch = useDispatch();
const inputRef = useRef();

const { userId } = getAuthenticatedUser();
const [decision] = useDecision(OPTIMIZELY_PROMPT_EXPERIMENT_KEY, { autoUpdate: true }, { id: userId.toString() });
Copy link
Member

Choose a reason for hiding this comment

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

Could you explain why autoUpdate is true here? I believe the default is false. Reading the documentation, I don't exactly understand why we'd want to set this to true.

Copy link
Member

Choose a reason for hiding this comment

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

Should the id override have the name overrideUserId?

Copy link
Member

Choose a reason for hiding this comment

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

If you send the userId via the OptimizelyProvider, which you do via the ExperimentsProvider component, you shouldn't need to send a user ID override, because that user ID will already be available to Optimizely throughout the component tree. Is there a reason we need to override the ID here? I have the same question for src/components/Sidebar/index.jsx.

Copy link
Member Author

@rijuma rijuma Jul 18, 2024

Choose a reason for hiding this comment

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

Could you explain why autoUpdate is true here? I believe the default is false. Reading the documentation, I don't exactly understand why we'd want to set this to true.

I understood that having the autoUpdate: true would react to changes on the experiment immediately while the user is in the experiment. I think it's a good thing to have in cases where we detect a bug and want to remove the experiment. I thought it was an useful thing to use to be able to react in real time.

Should the id override have the name overrideUserId?

Indeed. Good catch. I've made a small refactor on the useDecision() hook into its own usePromptExperimentDecision() hook to avoid repetition.

If you send the userId via the OptimizelyProvider, which you do via the ExperimentsProvider component, you shouldn't need to send a user ID override, because that user ID will already be available to Optimizely throughout the component tree. Is there a reason we need to override the ID here? I have the same question for src/components/Sidebar/index.jsx.

I was worried if for some reason the user changed after the initialization. Since the getAuthenticatedUser() is a getter, the provider might not update if this happens. The override would have the updated userId when the call is made, so I thought it was more accurate.

Copy link
Member

Choose a reason for hiding this comment

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

That makes sense. I don't think those cases are likely to occur in the experiment, but I don't see a good reason not have these options set this way because, as you said, it's safer. I think my main concern is it makes it a little more difficult to understand. The user override, for example, feels like it's serving to perform an override, but the user ID is exactly the same. But that's why I asked the question, and I appreciate you explaining their function! I don't have any concerns with leaving them in.

Copy link
Member Author

Choose a reason for hiding this comment

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

Same thing. I saw the usage in some examples in Optimizely's documentation and saw no reason to exclude it. I've added a short inline comment on each prop to explain the usage.

Copy link
Member

@MichaelRoytman MichaelRoytman left a comment

Choose a reason for hiding this comment

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

This looks good to me! I left a few questions and recommendations for small fixes.

I won't have time to review the tests today, but I can come back to it tomorrow.

@@ -17,6 +19,11 @@ const MessageForm = ({ courseId, shouldAutofocus, unitId }) => {
const dispatch = useDispatch();
const inputRef = useRef();

const { userId } = getAuthenticatedUser();
const [decision] = useDecision(OPTIMIZELY_PROMPT_EXPERIMENT_KEY, { autoUpdate: true }, { id: userId.toString() });
Copy link
Member

Choose a reason for hiding this comment

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

Should the id override have the name overrideUserId?

@@ -17,6 +19,11 @@ const MessageForm = ({ courseId, shouldAutofocus, unitId }) => {
const dispatch = useDispatch();
const inputRef = useRef();

const { userId } = getAuthenticatedUser();
const [decision] = useDecision(OPTIMIZELY_PROMPT_EXPERIMENT_KEY, { autoUpdate: true }, { id: userId.toString() });
Copy link
Member

Choose a reason for hiding this comment

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

If you send the userId via the OptimizelyProvider, which you do via the ExperimentsProvider component, you shouldn't need to send a user ID override, because that user ID will already be available to Optimizely throughout the component tree. Is there a reason we need to override the ID here? I have the same question for src/components/Sidebar/index.jsx.

src/mocks/optimizely/index.jsx Outdated Show resolved Hide resolved
src/data/optimizely.js Outdated Show resolved Hide resolved
Copy link
Member

@MichaelRoytman MichaelRoytman left a comment

Choose a reason for hiding this comment

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

Looks good! Thank you for incorporating my feedback.

@rijuma rijuma force-pushed the rijuma/optimizely-context-fix branch from 9cc2269 to 9d9504e Compare July 18, 2024 21:11
@rijuma rijuma merged commit 7bf56c6 into main Jul 18, 2024
5 checks passed
@rijuma rijuma deleted the rijuma/optimizely-context-fix branch July 18, 2024 21:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants