diff --git a/README.md b/README.md index edeaa90c..aec271a6 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ $ npm run storybook ``` we also use storyshot to do snapshot test with stories, make sure to run: ``` -$ npm test -- -u +$ npm test -- -u ``` before pushing to update stories snapshots. Storybook will be available under /storybook/index.html after build. @@ -84,6 +84,14 @@ Also, it will push the following custom variable to `dataLayer`; - `GA_TRACKING_ID` - see `PUBLIC_GA_TRACKING_ID` - `CURRENT_USER` - Current user object, set by `useCurrentUser`. +Lastly, in Google Tag Manager we use `data-ga` property to track clicks. +If user clicks a decendant of an React element with `data-ga` property, +a click event will be sent to Google analytics with the written `data-ga`. +(It doesn't even need to be rendered, we [setup the Google Tag Manager](https://github.com/cofacts/rumors-site/pull/254) to read private React instance) + +Also, if a component has its `displayName` set, +a click event with that `displayName` is also sent to Google Analytics when any of its decendant is clicked. + ## Design and Mockups * [真的假的 hackfoldr](http://beta.hackfoldr.org/rumors) diff --git a/components/ArticleItem.js b/components/ArticleItem.js index 4b280c40..f10e0b6d 100644 --- a/components/ArticleItem.js +++ b/components/ArticleItem.js @@ -147,7 +147,7 @@ export default function ArticleItem({ content )} {isLink || ( -
+
{t`Bust Hoaxes`} @@ -162,6 +162,8 @@ export default function ArticleItem({ ); } +ArticleItem.displayName = 'ArticleItem'; + ArticleItem.fragments = { ArticleItem: gql` fragment ArticleItem on Article { diff --git a/components/ArticlePageLayout.js b/components/ArticlePageLayout.js index 3b094030..e6d3040e 100644 --- a/components/ArticlePageLayout.js +++ b/components/ArticlePageLayout.js @@ -265,6 +265,7 @@ const FilterGroup = ({ filters: filters.join(','), }) } + data-ga="Filter(filter)" /> )} @@ -293,6 +294,7 @@ const FilterGroup = ({ .join(','), }) } + data-ga="Filter(category)" /> )} @@ -444,6 +446,7 @@ function ArticlePageLayout({ {lastCursorOfPage !== lastCursor && (
{expandable && (
- @@ -298,10 +299,11 @@ function ReplyFeedback({ className={cx(classes.vote, ownVote === 'DOWNVOTE' && classes.voted)} type="button" onClick={e => openVotePopover(e, 'DOWNVOTE')} + data-ga="Downvote" > -
+