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

feat: Implemented product recommendations experiment #174

Merged

Conversation

JodyBaileyy
Copy link
Contributor

@JodyBaileyy JodyBaileyy commented Jul 8, 2023

Description

  • Added api call to new recommendations_context endpoint which gathers the user's country code
  • Implemented experiment related code for cross product recommendations experiment. This makes use of an experimentContext which both makes the api call to fetch the user's country code and stores the stateful values for activating our experiment and which widget container to render based on the variant the user is bucketed into.
  • Made adjustment to segment events properties
  • Updated redirect links when clicking on a course card and header
  • Updated courses to have prop courseRunKey which comes from our product_recommendations endpoint enhancement

JIRA Ticket

PTECH-3282

@codecov
Copy link

codecov bot commented Jul 8, 2023

Codecov Report

Patch coverage: 98.23% and project coverage change: +0.09 🎉

Comparison is base (58c3720) 96.20% compared to head (85e98ab) 96.29%.

❗ Current head 85e98ab differs from pull request most recent head 410dccd. Consider uploading reports for the commit 410dccd to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #174      +/-   ##
==========================================
+ Coverage   96.20%   96.29%   +0.09%     
==========================================
  Files         180      182       +2     
  Lines        1606     1699      +93     
  Branches      286      300      +14     
==========================================
+ Hits         1545     1636      +91     
- Misses         56       58       +2     
  Partials        5        5              
Impacted Files Coverage Δ
src/widgets/ProductRecommendations/utils.js 100.00% <ø> (ø)
src/experimentContext.jsx 90.90% <90.90%> (ø)
src/App.jsx 64.00% <100.00%> (ø)
...ontainers/WidgetContainers/LoadedSidebar/index.jsx 100.00% <100.00%> (ø)
...ainers/WidgetContainers/NoCoursesSidebar/index.jsx 100.00% <100.00%> (ø)
...containers/WidgetContainers/WidgetFooter/index.jsx 100.00% <100.00%> (ø)
src/widgets/ProductRecommendations/api.js 100.00% <100.00%> (ø)
.../ProductRecommendations/components/ProductCard.jsx 100.00% <100.00%> (ø)
...ecommendations/components/ProductCardContainer.jsx 100.00% <100.00%> (ø)
...ctRecommendations/components/ProductCardHeader.jsx 100.00% <100.00%> (ø)
... and 5 more

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@JodyBaileyy JodyBaileyy force-pushed the jodybaileyy/recommendations-experiment-implementation branch from cdb34db to 4790bf4 Compare July 8, 2023 12:06
@JodyBaileyy JodyBaileyy marked this pull request as ready for review July 8, 2023 12:12

export const useCountryCode = (setCountryCode) => {
React.useEffect(() => {
let isMounted = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this important?

Copy link
Contributor

Choose a reason for hiding this comment

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

React.useEffect should be part of the component. useCountryCode should just do the fetching in this case. Then useEffect(fn, []) should run only once. There won't be need for isMounted.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True, I can't really think of a scenario where the component will be unmounted, I'll adjust it

Comment on lines 13 to 25
export const useCountryCode = (setCountryCode) => {
React.useEffect(() => {
api
.fetchRecommendationsContext()
.then((response) => {
setCountryCode(response.data.countryCode);
})
.catch(() => {
setCountryCode('');
});
/* eslint-disable */
}, []);
};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Keeping the useEffect for setting the country code in it's own hook because it makes the ExperimentProvider less bloated and it's much easier to test

Copy link
Contributor

Choose a reason for hiding this comment

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

+100%. Honestly, for this, having all of the hooks be as separated as possible is valuable, because they are less for-a-single-purpose. I would almost break the useIsMobile, but is small enough it doesn't make a huge difference.

@@ -0,0 +1,64 @@
import React from 'react';
Copy link
Contributor

Choose a reason for hiding this comment

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

My one request here is that this file get renamed to ExperimentContext, as is exporting a component provider.

@JodyBaileyy JodyBaileyy merged commit 103a676 into master Jul 11, 2023
3 checks passed
@JodyBaileyy JodyBaileyy deleted the jodybaileyy/recommendations-experiment-implementation branch July 11, 2023 14:45
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.

3 participants