Skip to content

Commit

Permalink
feat: track interaction with comment events
Browse files Browse the repository at this point in the history
  • Loading branch information
thisislawatts committed Jan 14, 2022
1 parent 031256d commit c9acb4c
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 3 deletions.
36 changes: 35 additions & 1 deletion src/components/Comment/Comment.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useState } from 'react'
import ReactGA from 'react-ga'
import { FaTrash, FaRegEdit } from 'react-icons/fa'
import { Flex } from 'rebass/styled-components'
import { useCommonStores } from 'src/index'
Expand Down Expand Up @@ -45,7 +46,14 @@ export const Comment: React.FC<IProps> = ({
}}
mr={2}
fontSize="12px"
onClick={async () => setShowEditModal(true)}
onClick={async () => {
ReactGA.event({
category: 'Comments',
action: 'Edit existing comment',
label: stores.howtoStore.activeHowto?.title,
})
return setShowEditModal(true)
}}
>
edit <FaRegEdit />
</Text>
Expand All @@ -61,6 +69,19 @@ export const Comment: React.FC<IProps> = ({
)
if (confirmation) {
await stores.howtoStore.deleteComment(_id)
ReactGA.event({
category: 'Comments',
action: 'Deleted',
label: stores.howtoStore.activeHowto?.title,
})
logger.debug(
{
category: 'Comments',
action: 'Deleted',
label: stores.howtoStore.activeHowto?.title,
},
'comment deleted',
)
}
}}
>
Expand Down Expand Up @@ -106,6 +127,19 @@ export const Comment: React.FC<IProps> = ({
<Button
small
onClick={async () => {
ReactGA.event({
category: 'Comments',
action: 'Update',
label: stores.howtoStore.activeHowto?.title,
})
logger.debug(
{
category: 'Comments',
action: 'Update',
label: stores.howtoStore.activeHowto?.title,
},
'comment edited',
)
await stores.howtoStore.editComment(_id, values.comment)
setShowEditModal(false)
}}
Expand Down
28 changes: 26 additions & 2 deletions src/pages/Howto/Content/Howto/HowToComments/HowToComments.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import React, { useState } from 'react'
import { useState } from 'react'
import ReactGA from 'react-ga'
import { Box, Flex } from 'rebass/styled-components'
import { useCommonStores } from 'src/index'
import { Button } from 'src/components/Button'
import { Comment } from 'src/components/Comment/Comment'
import { CommentTextArea } from 'src/components/Comment/CommentTextArea'
import { IComment } from 'src/models'
import styled from 'styled-components'
import { logger } from 'src/logger'

const MAX_COMMENTS = 5

Expand Down Expand Up @@ -36,8 +38,23 @@ export const HowToComments = ({ comments }: IProps) => {
await stores.howtoStore.addComment(comment)
setLoading(false)
setComment('')

ReactGA.event({
category: 'Comments',
action: 'Submitted',
label: stores.howtoStore.activeHowto?.title,
})
logger.debug(
{
category: 'Comments',
action: 'Submitted',
label: stores.howtoStore.activeHowto?.title,
},
'comment submitted',
)
} catch (err) {
// Error: Comment could not be posted
logger.error({ err }, 'failed to submit comment')
}
}

Expand Down Expand Up @@ -65,7 +82,14 @@ export const HowToComments = ({ comments }: IProps) => {
<Button
width="max-content"
variant="outline"
onClick={() => setMoreComments(moreComments + 1)}
onClick={() => {
ReactGA.event({
category: 'Comments',
action: 'Show more',
label: stores.howtoStore.activeHowto?.title,
})
return setMoreComments(moreComments + 1)
}}
>
show more comments
</Button>
Expand Down

0 comments on commit c9acb4c

Please sign in to comment.