-
Notifications
You must be signed in to change notification settings - Fork 3
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
Conversation
696e411
to
3de26cf
Compare
676ee05
to
1b28cf5
Compare
src/components/MessageForm/index.jsx
Outdated
@@ -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() }); |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
src/components/MessageForm/index.jsx
Outdated
@@ -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() }); |
There was a problem hiding this comment.
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
?
src/components/MessageForm/index.jsx
Outdated
@@ -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() }); |
There was a problem hiding this comment.
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
.
Co-authored-by: Michael Roytman <[email protected]>
Co-authored-by: Michael Roytman <[email protected]>
There was a problem hiding this 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.
9cc2269
to
9d9504e
Compare
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.