From 3afce17a32b558fc222ceb9bb00d9329d02fd650 Mon Sep 17 00:00:00 2001 From: Ahtisham Shahid Date: Tue, 21 Feb 2023 16:30:30 +0500 Subject: [PATCH] feat: added event tracking on load more response (#442) * feat: added event tracking on load more response --- src/discussions/post-comments/data/hooks.js | 26 +++++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/discussions/post-comments/data/hooks.js b/src/discussions/post-comments/data/hooks.js index bc467bc7..5f704975 100644 --- a/src/discussions/post-comments/data/hooks.js +++ b/src/discussions/post-comments/data/hooks.js @@ -2,6 +2,8 @@ import { useEffect } from 'react'; import { useDispatch, useSelector } from 'react-redux'; +import { sendTrackEvent } from '@edx/frontend-platform/analytics'; + import { EndorsementStatus } from '../../../data/constants'; import { useDispatchWithState } from '../../../data/hooks'; import { selectThread } from '../../posts/data/selectors'; @@ -11,6 +13,16 @@ import { } from './selectors'; import { fetchThreadComments } from './thunks'; +function trackLoadMoreEvent(postId, params) { + sendTrackEvent( + 'edx.forum.responses.loadMore', + { + postId, + params, + }, + ); +} + export function usePost(postId) { const dispatch = useDispatch(); const thread = useSelector(selectThread(postId)); @@ -31,11 +43,15 @@ export function usePostComments(postId, endorsed = null) { const hasMorePages = useSelector(selectThreadHasMorePages(postId, endorsed)); const currentPage = useSelector(selectThreadCurrentPage(postId, endorsed)); - const handleLoadMoreResponses = async () => dispatch(fetchThreadComments(postId, { - endorsed, - page: currentPage + 1, - reverseOrder, - })); + const handleLoadMoreResponses = async () => { + const params = { + endorsed, + page: currentPage + 1, + reverseOrder, + }; + await dispatch(fetchThreadComments(postId, params)); + trackLoadMoreEvent(postId, params); + }; useEffect(() => { dispatch(fetchThreadComments(postId, {