From fc74c91fe8c2774048c91134892edb3562f32e3c Mon Sep 17 00:00:00 2001 From: Roman Chyla Date: Mon, 19 Oct 2020 19:22:50 -0400 Subject: [PATCH] Changes to encode differently no-recommendations signal; and also avoid sending it multiple times (status code of the request doesn't work to debounce calls) (#2075) --- .../components/RecommendedList.jsx.js | 60 ++++++++++--------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/src/js/react/Recommender/components/RecommendedList.jsx.js b/src/js/react/Recommender/components/RecommendedList.jsx.js index 9a6dfeeb9..480039e27 100644 --- a/src/js/react/Recommender/components/RecommendedList.jsx.js +++ b/src/js/react/Recommender/components/RecommendedList.jsx.js @@ -1,15 +1,8 @@ -define([ - 'react', - 'react-prop-types', - 'react-redux', - 'react-bootstrap', - '../actions', -], function( +define(['react', 'react-prop-types', 'react-redux', '../actions'], function( React, PropTypes, { useSelector, useDispatch }, - { Button }, - { getRecommendations, getFullList, emitAnalytics } + { getRecommendations, emitAnalytics } ) { const Paper = ({ title, bibcode, author, totalAuthors, onClick }) => { const el = React.useRef(null); @@ -71,11 +64,13 @@ define([ var executed = 0; var userName = null; + var reported = false; const selector = (state) => { // reset if it is a different user if (state.userName !== userName) { executed = 0; userName = state.userName; + reported = false; } return { @@ -83,49 +78,51 @@ define([ getDocsRequest: state.requests.GET_DOCS, docs: state.docs, queryParams: state.queryParams, - executed: executed + executed: executed, + reported: reported, }; }; const RecommendedList = () => { const dispatch = useDispatch(); + /* const onGetMore = () => { dispatch(getFullList()); }; + */ + const { getRecommendationsRequest, getDocsRequest, docs, queryParams, - userName + userName // eslint-disable-line } = useSelector(selector); React.useEffect(() => { - if ((executed + 12*60*60*1000) < Date.now()) { + if (executed + 12 * 60 * 60 * 1000 < Date.now()) { // the hook gets called too many times even with [docs] in the args to useEffect // (and oracle returns 404 when nothing is found; which is IMHO wrong) but we can't // rely on status.failure for that reason executed = Date.now(); dispatch(getRecommendations()); - } - else { - if (executed && getDocsRequest && getDocsRequest.status && docs.length === 0) { - // we are rendered (send the signal everytime -- even if it was sent already) - dispatch( - emitAnalytics([ - 'send', - 'event', - 'interaction.recommendation', // category - 'no-useful-recommendations', // action - '', // label, - 0, // value - ]) - ); - } + reported = false; + } else if (executed && docs.length === 0 && !reported) { + // we are rendered (send the signal everytime -- even if it was sent already) + dispatch( + emitAnalytics([ + 'send', + 'event', + 'interaction.no-recommendation', // category + 'no-useful-recommendations', // action + '', // label, + 0, // value + ]) + ); + reported = true; } }); - const onPaperSelect = ({ bibcode }, index) => { dispatch( emitAnalytics([ @@ -173,7 +170,12 @@ define([ if (docs.length === 0) { return ( - Sorry, we don't have any recommendations for you just yet! ADS provides users recommendations based on their reading history, and we suggest that you create an ADS account to take advantage of this feature. If you already have an account, then be sure you are logged in while searching and reading papers. In due time we will be able to provide you with suggestions based on your inferred interests. + Sorry, we do not have any recommendations for you just yet! ADS + provides users recommendations based on their reading history, and we + suggest that you create an ADS account to take advantage of this + feature. If you already have an account, then be sure you are logged + in while searching and reading papers. In due time we will be able to + provide you with suggestions based on your inferred interests. ); }