-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Google Analytics & feedback component (#120 by @Jpoliachik)
* Initial approach for feedback component * Added url to config. Got the Reaction Widget working * install gtag plugin * use gtag in feedback widget, use custom ui * add yes / no text to buttons * remove happyreact script * comment * add privacy policy link to footer * use live GA id --------- Co-authored-by: Dan Edwards <[email protected]>
- Loading branch information
1 parent
5576dcc
commit 310381f
Showing
10 changed files
with
213 additions
and
1 deletion.
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