-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
feat: send content feedback plausible events #12400
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
84910b9
feat: send content feedback plausible events
a-hariti db3d320
clearer buttons
a-hariti 54cdff0
collect content feedback using Sentry User Feedbak
a-hariti 89c80fa
improve spacing
a-hariti 3efa2c7
dedupe classanme
a-hariti dce9496
make ui reflect reception of feedback
a-hariti b43503d
adjust feedback modal copy
a-hariti 766ac4e
auto close feedback modal after submission
a-hariti 4c707c3
capture feedback submission error
a-hariti f8261af
move content feedback below next/prev navigation
a-hariti 3a392a3
change emojies
a-hariti 0f70b5e
capture feedback comments for both types of feedback in an inline form
a-hariti 4e96a48
improve styles
a-hariti File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
'use client'; | ||
import {Fragment, useEffect, useState} from 'react'; | ||
import {CheckIcon as Check} from '@radix-ui/react-icons'; | ||
import {Button} from '@radix-ui/themes'; | ||
import * as Sentry from '@sentry/browser'; | ||
|
||
import {usePlausibleEvent} from 'sentry-docs/hooks/usePlausibleEvent'; | ||
|
||
type Props = { | ||
pathname: string; | ||
}; | ||
|
||
export function DocFeedback({pathname}: Props) { | ||
const {emit} = usePlausibleEvent(); | ||
const [showFeedback, setShowFeedback] = useState(false); | ||
const [feedbackSubmitted, setFeedbackSubmitted] = useState(false); | ||
const [feedbackType, setFeedbackType] = useState<'helpful' | 'not_helpful' | null>( | ||
null | ||
); | ||
|
||
// Initialize feedback state from sessionStorage | ||
useEffect(() => { | ||
const storedFeedback = sessionStorage.getItem(`feedback_${pathname}`); | ||
if (storedFeedback === 'submitted') { | ||
setFeedbackSubmitted(true); | ||
} | ||
}, [pathname]); | ||
|
||
const handleFeedback = (helpful: boolean) => { | ||
emit('Doc Feedback', {props: {page: pathname, helpful}}); | ||
setFeedbackType(helpful ? 'helpful' : 'not_helpful'); | ||
setShowFeedback(true); | ||
}; | ||
|
||
const handleSubmitFeedback = (e: React.FormEvent<HTMLFormElement>) => { | ||
e.preventDefault(); | ||
const formData = new FormData(e.currentTarget); | ||
const comments = formData.get('comments') as string; | ||
|
||
try { | ||
Sentry.captureFeedback( | ||
{ | ||
message: comments, | ||
}, | ||
{captureContext: {tags: {page: pathname, type: feedbackType}}} | ||
); | ||
setFeedbackSubmitted(true); | ||
sessionStorage.setItem(`feedback_${pathname}`, 'submitted'); | ||
} catch (error) { | ||
if (process.env.NODE_ENV === 'development') { | ||
// eslint-disable-next-line no-console | ||
console.error('Failed to submit feedback:', error); | ||
} | ||
Sentry.captureException(error); | ||
} | ||
}; | ||
|
||
return ( | ||
<Fragment> | ||
<div className="space-y-4 py-4 border-[var(--gray-6)]"> | ||
{feedbackSubmitted ? ( | ||
<div className="flex items-center gap-2 text-sm text-[var(--gray-11)]"> | ||
<Check className="w-4 h-4" /> Thanks for your feedback | ||
</div> | ||
) : ( | ||
<Fragment> | ||
<div className="flex items-center gap-4 text-sm mt-8"> | ||
<span className="font-medium">Was this helpful?</span> | ||
<div className="flex"> | ||
<button | ||
onClick={() => handleFeedback(true)} | ||
className="py-1 px-2 gap-4 hover:bg-[var(--gray-3)] rounded flex items-center justify-center" | ||
aria-label="Yes, this was helpful" | ||
> | ||
Yes 👍 | ||
</button> | ||
<button | ||
onClick={() => handleFeedback(false)} | ||
className="py-1 px-2 gap-4 hover:bg-[var(--gray-3)] rounded flex items-center justify-center" | ||
aria-label="No, this wasn't helpful" | ||
> | ||
No 👎 | ||
</button> | ||
</div> | ||
</div> | ||
|
||
<div | ||
className={`overflow-hidden transition-all duration-300 ease-in-out ${ | ||
showFeedback ? 'max-h-[300px] opacity-100' : 'max-h-0 opacity-0' | ||
}`} | ||
> | ||
<form onSubmit={handleSubmitFeedback} className="space-y-4"> | ||
<div> | ||
<label htmlFor="comments" className="block text-sm font-medium mb-4"> | ||
{feedbackType === 'helpful' | ||
? 'What did you like about this page?' | ||
: 'How can we improve this page?'} | ||
</label> | ||
<textarea | ||
id="comments" | ||
name="comments" | ||
required | ||
rows={2} | ||
className="w-[calc(100%-4px)] ml-[2px] px-3 py-2 border border-[var(--gray-6)] rounded-lg focus:outline-none focus:ring-2 focus:ring-[var(--accent)] bg-transparent text-sm" | ||
placeholder="Please share your thoughts..." | ||
/> | ||
</div> | ||
<Button | ||
type="submit" | ||
className="px-4 py-2 text-sm rounded-lg bg-[var(--accent-purple)]" | ||
size={'3'} | ||
> | ||
Submit feedback | ||
</Button> | ||
</form> | ||
</div> | ||
</Fragment> | ||
)} | ||
</div> | ||
</Fragment> | ||
); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.