diff --git a/.env b/.env index 55937a86..cc640094 100644 --- a/.env +++ b/.env @@ -25,7 +25,7 @@ SEARCH_CATALOG_URL='' DISABLE_ENTERPRISE_LOGIN='' ENABLE_DYNAMIC_REGISTRATION_FIELDS='' ENABLE_PROGRESSIVE_PROFILING_ON_AUTHN='' -ENABLE_PERSONALIZED_RECOMMENDATIONS='' +ENABLE_POPULAR_AND_TRENDING_RECOMMENDATIONS='' MARKETING_EMAILS_OPT_IN='' SHOW_CONFIGURABLE_EDX_FIELDS='' # ***** Zendesk related keys ***** diff --git a/src/config/index.js b/src/config/index.js index d7511d51..5b84e461 100644 --- a/src/config/index.js +++ b/src/config/index.js @@ -6,7 +6,7 @@ const configuration = { DISABLE_ENTERPRISE_LOGIN: process.env.DISABLE_ENTERPRISE_LOGIN || '', ENABLE_DYNAMIC_REGISTRATION_FIELDS: process.env.ENABLE_DYNAMIC_REGISTRATION_FIELDS || false, ENABLE_PROGRESSIVE_PROFILING_ON_AUTHN: process.env.ENABLE_PROGRESSIVE_PROFILING_ON_AUTHN || false, - ENABLE_PERSONALIZED_RECOMMENDATIONS: process.env.ENABLE_PERSONALIZED_RECOMMENDATIONS || false, + ENABLE_POPULAR_AND_TRENDING_RECOMMENDATIONS: process.env.ENABLE_POPULAR_AND_TRENDING_RECOMMENDATIONS || false, MARKETING_EMAILS_OPT_IN: process.env.MARKETING_EMAILS_OPT_IN || '', SHOW_CONFIGURABLE_EDX_FIELDS: process.env.SHOW_CONFIGURABLE_EDX_FIELDS || false, // Links diff --git a/src/progressive-profiling/ProgressiveProfiling.jsx b/src/progressive-profiling/ProgressiveProfiling.jsx index d8296f50..c40f1ed1 100644 --- a/src/progressive-profiling/ProgressiveProfiling.jsx +++ b/src/progressive-profiling/ProgressiveProfiling.jsx @@ -39,7 +39,7 @@ import { import { getAllPossibleQueryParams, isHostAvailableInQueryParams } from '../data/utils'; import { FormFieldRenderer } from '../field-renderer'; import { - activateRecommendationsExperiment, RECOMMENDATIONS_EXP_VARIATION, trackRecommendationViewedOptimizely, + activateRecommendationsExperiment, RECOMMENDATIONS_EXP_VARIATION, } from '../recommendations/optimizelyExperiment'; import { trackRecommendationsGroup, trackRecommendationsViewed } from '../recommendations/track'; @@ -58,7 +58,7 @@ const ProgressiveProfiling = (props) => { const queryParams = getAllPossibleQueryParams(); const authenticatedUser = getAuthenticatedUser(); const DASHBOARD_URL = getConfig().LMS_BASE_URL.concat(DEFAULT_REDIRECT_URL); - const enablePersonalizedRecommendations = getConfig().ENABLE_PERSONALIZED_RECOMMENDATIONS; + const enablePopularAndTrendingRecommendations = getConfig().ENABLE_POPULAR_AND_TRENDING_RECOMMENDATIONS; const [registrationResult, setRegistrationResult] = useState({ redirectUrl: '' }); const [formFieldData, setFormFieldData] = useState({ fields: {}, extendedProfile: [] }); @@ -116,20 +116,19 @@ const ProgressiveProfiling = (props) => { useEffect(() => { if (registrationResult.redirectUrl && authenticatedUser?.userId) { const redirectQueryParams = getAllPossibleQueryParams(registrationResult.redirectUrl); - if (enablePersonalizedRecommendations && !('enrollment_action' in redirectQueryParams)) { + if (enablePopularAndTrendingRecommendations && !('enrollment_action' in redirectQueryParams) && !queryParams?.next) { const userIdStr = authenticatedUser.userId.toString(); const variation = activateRecommendationsExperiment(userIdStr); const showRecommendations = variation === RECOMMENDATIONS_EXP_VARIATION; trackRecommendationsGroup(variation, authenticatedUser.userId); - trackRecommendationViewedOptimizely(userIdStr); setShowRecommendationsPage(showRecommendations); if (!showRecommendations) { trackRecommendationsViewed([], true, authenticatedUser.userId); } } } - }, [authenticatedUser, enablePersonalizedRecommendations, registrationResult]); + }, [authenticatedUser, enablePopularAndTrendingRecommendations, registrationResult, queryParams]); if ( !(location.state?.registrationResult || registrationEmbedded) diff --git a/src/progressive-profiling/tests/ProgressiveProfiling.test.jsx b/src/progressive-profiling/tests/ProgressiveProfiling.test.jsx index 01b7a13e..c2cc689c 100644 --- a/src/progressive-profiling/tests/ProgressiveProfiling.test.jsx +++ b/src/progressive-profiling/tests/ProgressiveProfiling.test.jsx @@ -18,6 +18,7 @@ import { FAILURE_STATE, RECOMMENDATIONS, } from '../../data/constants'; +import { activateRecommendationsExperiment } from '../../recommendations/optimizelyExperiment'; import { saveUserProfile } from '../data/actions'; import ProgressiveProfiling from '../ProgressiveProfiling'; @@ -39,7 +40,7 @@ jest.mock('@edx/frontend-platform/logging', () => ({ getLoggingService: jest.fn(), })); jest.mock('../../recommendations/optimizelyExperiment.js', () => ({ - activateRecommendationsExperiment: jest.fn().mockImplementation(() => 'welcome_page_recommendations_enabled'), + activateRecommendationsExperiment: jest.fn(), trackRecommendationViewedOptimizely: jest.fn(), RECOMMENDATIONS_EXP_VARIATION: 'welcome_page_recommendations_enabled', })); @@ -207,7 +208,7 @@ describe('ProgressiveProfilingTests', () => { describe('Recommendations test', () => { mergeConfig({ - ENABLE_PERSONALIZED_RECOMMENDATIONS: true, + ENABLE_POPULAR_AND_TRENDING_RECOMMENDATIONS: true, }); it('should redirect to recommendations page if recommendations are enabled', async () => { @@ -218,6 +219,7 @@ describe('ProgressiveProfilingTests', () => { success: true, }, }); + activateRecommendationsExperiment.mockImplementation(() => 'welcome_page_recommendations_enabled'); getAuthenticatedUser.mockReturnValue({ userId: 3, username: 'abc123' }); const progressiveProfilingPage = await getProgressiveProfilingPage(); @@ -226,6 +228,34 @@ describe('ProgressiveProfilingTests', () => { expect(history.location.pathname).toEqual(RECOMMENDATIONS); }); + it('should fire segments recommendations viewed and variation group events', async () => { + const viewedEventProperties = { + page: 'authn_recommendations', + course_key_array: [], + amplitude_recommendations: false, + is_control: true, + user_id: 3, + }; + const groupEventProperties = { + page: 'authn_recommendations', + variation: 'control', + user_id: 3, + }; + activateRecommendationsExperiment.mockImplementation(() => 'control'); + store = mockStore({ + ...initialState, + welcomePage: { + ...initialState.welcomePage, + success: true, + }, + }); + + getAuthenticatedUser.mockReturnValue({ userId: 3, username: 'abc123' }); + await getProgressiveProfilingPage(); + expect(sendTrackEvent).toHaveBeenCalledWith('edx.bi.user.recommendations.group', groupEventProperties); + expect(sendTrackEvent).toHaveBeenCalledWith('edx.bi.user.recommendations.viewed', viewedEventProperties); + }); + it('should not redirect to recommendations page if user is on its way to enroll in a course', async () => { const redirectUrl = `${getConfig().LMS_BASE_URL}${DEFAULT_REDIRECT_URL}?enrollment_action=1`; props = { diff --git a/src/recommendations/optimizelyExperiment.js b/src/recommendations/optimizelyExperiment.js index daa820b5..f9af744a 100644 --- a/src/recommendations/optimizelyExperiment.js +++ b/src/recommendations/optimizelyExperiment.js @@ -1,7 +1,7 @@ import optimizelyInstance from '../data/optimizely'; -const RECOMMENDATIONS_EXP_KEY = 'welcome_page_recommendations_exp'; -const RECOMMENDATIONS_EXP_VARIATION = 'welcome_page_recommendations_enabled'; +const RECOMMENDATIONS_EXP_KEY = 'popular_and_trending_recommendations_exp'; +const RECOMMENDATIONS_EXP_VARIATION = 'popular_and_trending_recommendations'; export const eventNames = { recommendedCourseClicked: 'welcome_page_recommendation_card_click',