From 7f68ddb3e45f09b3dd01127b6d22e34ad5c9823a Mon Sep 17 00:00:00 2001 From: Maham Date: Fri, 22 Nov 2024 15:14:08 +0500 Subject: [PATCH] feat: add segment event to track the selected value for learning type dropdown --- .../src/LearningTypeRadioFacet.jsx | 18 ++++++++++++++++-- packages/catalog-search/src/data/constants.js | 1 + 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/packages/catalog-search/src/LearningTypeRadioFacet.jsx b/packages/catalog-search/src/LearningTypeRadioFacet.jsx index fc9254b5..ce5d5e76 100644 --- a/packages/catalog-search/src/LearningTypeRadioFacet.jsx +++ b/packages/catalog-search/src/LearningTypeRadioFacet.jsx @@ -3,17 +3,25 @@ import PropTypes from 'prop-types'; import classNames from 'classnames'; import { Dropdown, Input, Badge } from '@openedx/paragon'; import { FormattedMessage } from '@edx/frontend-platform/i18n'; +import { sendTrackEvent } from '@edx/frontend-platform/analytics'; import { SearchContext } from './SearchContext'; +import { SEARCH_EVENT_NAME_PREFIX } from './SearchBox'; import { setRefinementAction, } from './data/actions'; import { features } from './config'; import { - LEARNING_TYPE_COURSE, LEARNING_TYPE_PROGRAM, LEARNING_TYPE_PATHWAY, LEARNING_TYPE_VIDEO, + LEARNING_TYPE_COURSE, + LEARNING_TYPE_PROGRAM, + LEARNING_TYPE_PATHWAY, + LEARNING_TYPE_VIDEO, + LEARNING_TYPE_SELECTED_EVENT, } from './data/constants'; const LearningTypeRadioFacet = ({ enablePathways }) => { - const { refinements, dispatch, enableVideos } = useContext(SearchContext); + const { + refinements, dispatch, enableVideos, trackingName, + } = useContext(SearchContext); // only bold the dropdown title if the learning type is Course or Program const typeCourseSelected = refinements.content_type && refinements.content_type.includes(LEARNING_TYPE_COURSE); @@ -28,6 +36,12 @@ const LearningTypeRadioFacet = ({ enablePathways }) => { } else { dispatch(setRefinementAction('content_type', [type])); } + if (trackingName) { + const learningType = type || 'any'; + sendTrackEvent(`${SEARCH_EVENT_NAME_PREFIX}.${trackingName}.${LEARNING_TYPE_SELECTED_EVENT}`, { + learningType, + }); + } }; return ( diff --git a/packages/catalog-search/src/data/constants.js b/packages/catalog-search/src/data/constants.js index 7119a4d9..72bec49e 100644 --- a/packages/catalog-search/src/data/constants.js +++ b/packages/catalog-search/src/data/constants.js @@ -107,6 +107,7 @@ export const LEARNING_TYPE_PROGRAM = 'program'; export const LEARNING_TYPE_PATHWAY = 'learnerpathway'; export const LEARNING_TYPE_VIDEO = 'video'; export const LEARNING_TYPE_EXECUTIVE_EDUCATION = 'Executive Education'; +export const LEARNING_TYPE_SELECTED_EVENT = 'catalog_search.learning_type_selected'; export const COURSE_TYPE_EXECUTIVE_EDUCATION = 'executive-education-2u';