Skip to content

Commit

Permalink
avoid multiple events on same rating
Browse files Browse the repository at this point in the history
  • Loading branch information
dhasilva committed Dec 19, 2024
1 parent 3373ae1 commit e5dd2f3
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions projects/js-packages/ai-client/src/components/ai-feedback/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,6 @@ export default function AiFeedbackThumbs( {
const [ itemsRated, setItemsRated ] = useState( {} );
const { tracks } = useAnalytics();

const rateAI = ( isThumbsUp: boolean ) => {
const aiRating = isThumbsUp ? 'thumbs-up' : 'thumbs-down';

setItemsRated( {
...itemsRated,
[ ratedItem ]: aiRating,
} );

tracks.recordEvent( 'jetpack_ai_feedback', {
type: feature,
rating: aiRating,
} );
};

const checkThumb = ( thumbValue: string ) => {
if ( ! itemsRated[ ratedItem ] ) {
return false;
Expand All @@ -77,6 +63,22 @@ export default function AiFeedbackThumbs( {
return itemsRated[ ratedItem ] === thumbValue;
};

const rateAI = ( isThumbsUp: boolean ) => {
const aiRating = isThumbsUp ? 'thumbs-up' : 'thumbs-down';

if ( ! checkThumb( aiRating ) ) {
setItemsRated( {
...itemsRated,
[ ratedItem ]: aiRating,
} );

tracks.recordEvent( 'jetpack_ai_feedback', {
type: feature,
rating: aiRating,
} );
}
};

return (
<div className="ai-assistant-feedback__selection">
<Tooltip text={ __( 'I like this', 'jetpack-ai-client' ) }>
Expand Down

0 comments on commit e5dd2f3

Please sign in to comment.