-
Notifications
You must be signed in to change notification settings - Fork 17
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
feat: Google Analytics & feedback component #120
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
aecb779
Initial approach for feedback component
cdanwards 143c956
Added url to config. Got the Reaction Widget working
cdanwards 9cfb983
Merged updates from main and fixed conflicts
cdanwards e1f78a4
Merge branch 'main' into feat/feedback-component
Jpoliachik 94b32f5
install gtag plugin
Jpoliachik 24a6a4a
use gtag in feedback widget, use custom ui
Jpoliachik 7af3a77
add yes / no text to buttons
Jpoliachik e536cb3
remove happyreact script
Jpoliachik 30b9cd2
comment
Jpoliachik 72c67ba
add privacy policy link to footer
Jpoliachik e91b192
use live GA id
Jpoliachik 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 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 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 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,69 @@ | ||
import React, { useEffect, useState } from "react"; | ||
import ExecutionEnvironment from "@docusaurus/ExecutionEnvironment"; | ||
import styles from "./styles.module.css"; | ||
|
||
import * as ThumbsUp from "@site/static/img/thumbs-up.svg"; | ||
import * as ThumbsDown from "@site/static/img/thumbs-down.svg"; | ||
|
||
const VotedYes = () => { | ||
return ( | ||
<span>Thanks for your feedback! We hope this recipe has been helpful.</span> | ||
); | ||
}; | ||
|
||
const VotedNo = () => { | ||
return ( | ||
<span> | ||
Thanks for your feedback. We will update this recipe as soon as we can. | ||
</span> | ||
); | ||
}; | ||
|
||
export default function Feedback({ resource }) { | ||
const [reaction, setReaction] = useState(null); | ||
|
||
const isReacted = reaction === "yes" || reaction === "no"; | ||
|
||
const handleReaction = (reaction: string) => { | ||
setReaction(reaction); | ||
|
||
// track using Google Analytics custom event | ||
// include the resource name and yes/no in the event name for tracking purposes | ||
gtag("event", `feedback_${resource}_${reaction}`, { | ||
event_category: "feedback", | ||
event_label: resource, | ||
}); | ||
}; | ||
|
||
return ( | ||
<div className={styles.root}> | ||
<h3 className={styles.title}> | ||
Is this page still up to date? Did it work for you? | ||
</h3> | ||
{!isReacted ? ( | ||
<div className={styles.grid}> | ||
<button | ||
className={styles.reactionButton} | ||
onClick={() => handleReaction("yes")} | ||
aria-label="Yes" | ||
> | ||
<ThumbsUp.default className={styles.reactionIcon} /> | ||
<div className={styles.reactionText}>Yes</div> | ||
</button> | ||
<button | ||
className={styles.reactionButton} | ||
onClick={() => handleReaction("no")} | ||
aria-label="No" | ||
> | ||
<ThumbsDown.default className={styles.reactionIcon} /> | ||
<div className={styles.reactionText}>No</div> | ||
</button> | ||
</div> | ||
) : reaction === "no" ? ( | ||
<VotedNo /> | ||
) : ( | ||
<VotedYes /> | ||
)} | ||
</div> | ||
); | ||
} |
This file contains 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,44 @@ | ||
.root { | ||
margin-top: 45px; | ||
} | ||
|
||
.grid { | ||
display: flex; | ||
flex-direction: row; | ||
justify-content: flex-start; | ||
gap: 8px; | ||
} | ||
|
||
.reactionButton { | ||
all: unset; | ||
cursor: pointer; | ||
padding: 8px; | ||
padding-top: 4px; | ||
padding-bottom: 4px; | ||
border: #d6d6d6 1px solid; | ||
border-radius: 4px; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
} | ||
|
||
.reactionButton:hover { | ||
background-color: #e3e3e3; | ||
} | ||
|
||
.reactionIcon { | ||
width: 20px; | ||
height: 20px; | ||
} | ||
|
||
.reactionText { | ||
margin-left: 6px; | ||
font-size: 14px; | ||
font-weight: 500; | ||
color: #4a4a4a; | ||
} | ||
|
||
.footer { | ||
margin-top: 10px; | ||
margin-left: 0; | ||
} |
This file contains 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,72 @@ | ||
import React from 'react'; | ||
import clsx from 'clsx'; | ||
import {ThemeClassNames} from '@docusaurus/theme-common'; | ||
import {useDoc} from '@docusaurus/theme-common/internal'; | ||
import LastUpdated from '@theme/LastUpdated'; | ||
import EditThisPage from '@theme/EditThisPage'; | ||
import TagsListInline from '@theme/TagsListInline'; | ||
import Feedback from '@site/src/components/Feedback'; | ||
import styles from './styles.module.css'; | ||
function TagsRow(props) { | ||
return ( | ||
<div | ||
className={clsx( | ||
ThemeClassNames.docs.docFooterTagsRow, | ||
'row margin-bottom--sm', | ||
)}> | ||
<div className="col"> | ||
<TagsListInline {...props} /> | ||
</div> | ||
</div> | ||
); | ||
} | ||
function EditMetaRow({ | ||
editUrl, | ||
lastUpdatedAt, | ||
lastUpdatedBy, | ||
formattedLastUpdatedAt, | ||
}) { | ||
return ( | ||
<div className={clsx(ThemeClassNames.docs.docFooterEditMetaRow, 'row')}> | ||
<div className="col">{editUrl && <EditThisPage editUrl={editUrl} />}</div> | ||
|
||
<div className={clsx('col', styles.lastUpdated)}> | ||
{(lastUpdatedAt || lastUpdatedBy) && ( | ||
<LastUpdated | ||
lastUpdatedAt={lastUpdatedAt} | ||
formattedLastUpdatedAt={formattedLastUpdatedAt} | ||
lastUpdatedBy={lastUpdatedBy} | ||
/> | ||
)} | ||
</div> | ||
</div> | ||
); | ||
} | ||
export default function DocItemFooter() { | ||
const {metadata} = useDoc(); | ||
const {editUrl, lastUpdatedAt, formattedLastUpdatedAt, lastUpdatedBy, tags, unversionedId} = | ||
metadata; | ||
const canDisplayTagsRow = tags.length > 0; | ||
const canDisplayEditMetaRow = !!(editUrl || lastUpdatedAt || lastUpdatedBy); | ||
const canDisplayFooter = canDisplayTagsRow || canDisplayEditMetaRow; | ||
if (!canDisplayFooter) { | ||
return null; | ||
} | ||
return ( | ||
<> | ||
<Feedback resource={unversionedId} /> | ||
<footer | ||
className={clsx(ThemeClassNames.docs.docFooter, 'docusaurus-mt-lg')}> | ||
{canDisplayTagsRow && <TagsRow tags={tags} />} | ||
{canDisplayEditMetaRow && ( | ||
<EditMetaRow | ||
editUrl={editUrl} | ||
lastUpdatedAt={lastUpdatedAt} | ||
lastUpdatedBy={lastUpdatedBy} | ||
formattedLastUpdatedAt={formattedLastUpdatedAt} | ||
/> | ||
)} | ||
</footer> | ||
</> | ||
); | ||
} |
This file contains 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,11 @@ | ||
.lastUpdated { | ||
margin-top: 0.2rem; | ||
font-style: italic; | ||
font-size: smaller; | ||
} | ||
|
||
@media (min-width: 997px) { | ||
.lastUpdated { | ||
text-align: right; | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we care about any type of persistence for this (local storage or beyond?)? probably not, but just adding an note.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good callout - I went with the easiest route, but that does allow users to full-refresh and vote again. didn't think it was worth the effort for now, but we can keep an eye on stats and add it later if needed.
FWIW I noticed that other docs sites (reactnative.dev, docs.expo.dev) do the same thing.