From 02b5830138547b6bebbf7608509dfd7f72509c70 Mon Sep 17 00:00:00 2001 From: "Luiz R. Rodrigues" Date: Thu, 30 Apr 2020 11:41:17 -0300 Subject: [PATCH 1/7] #4309: Move notifications tracking from topcoder-react-lib to community-app --- .../Header/__snapshots__/index.jsx.snap | 16 +++++++ config/default.js | 3 ++ config/production.js | 1 + package.json | 5 +- src/shared/actions/index.js | 3 ++ src/shared/actions/tracking.js | 46 +++++++++++++++++++ src/shared/components/Header/index.jsx | 4 +- src/shared/components/Notifications/index.jsx | 2 +- 8 files changed, 76 insertions(+), 4 deletions(-) create mode 100644 src/shared/actions/tracking.js diff --git a/__tests__/shared/components/Header/__snapshots__/index.jsx.snap b/__tests__/shared/components/Header/__snapshots__/index.jsx.snap index 03831a507a..8f8fa0afc8 100644 --- a/__tests__/shared/components/Header/__snapshots__/index.jsx.snap +++ b/__tests__/shared/components/Header/__snapshots__/index.jsx.snap @@ -182,10 +182,26 @@ exports[`Default render 1`] = ` "title": "Switch to BUSINESS", } } + tracking={ + Object { + "default": undefined, + "event": [Function], + "init": [Function], + "pageView": [Function], + } + } /> } setOpenMore={[Function]} theme="light" + tracking={ + Object { + "default": undefined, + "event": [Function], + "init": [Function], + "pageView": [Function], + } + } /> `; \ No newline at end of file diff --git a/config/default.js b/config/default.js index 87e727e9ba..7de679aec0 100644 --- a/config/default.js +++ b/config/default.js @@ -96,6 +96,9 @@ module.exports = { SWIFT_PROGRAM_ID: 3445, + /* Google Analytics tracking ID */ + GOOGLE_ANALYTICS_ID: 'UA-161803421-1', + /* Various URLs. Most of them lead to different segments of Topcoder * platform. */ URL: { diff --git a/config/production.js b/config/production.js index 026bfd4de6..a9875d52f5 100644 --- a/config/production.js +++ b/config/production.js @@ -17,6 +17,7 @@ module.exports = { }, LOG_ENTRIES_TOKEN: '', SERVER_API_KEY: 'aa9ccf36-3936-450c-9983-097ddba51bef', + GOOGLE_ANALYTICS_ID: 'UA-6340959-1', URL: { ARENA: 'https://arena.topcoder.com', APP: 'https://community-app.topcoder.com', diff --git a/package.json b/package.json index dfc7e769a1..723ebb90cd 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "test": "npm run lint && npm run --runInBand jest", "commitlint": "commitlint -E HUSKY_GIT_PARAMS", "release:changelog": "npm run conventional-changelog -- -p angular -i CHANGELOG.md -s", - "postinstall": "rimraf node_modules/navigation-component/node_modules/topcoder-react-utils && rimraf node_modules/navigation-component/node_modules/topcoder-react-lib && rimraf node_modules/topcoder-react-ui-kit/node_modules/topcoder-react-utils" + "postinstall": "rimraf node_modules/navigation-component/node_modules/topcoder-react-utils && rimraf node_modules/topcoder-react-ui-kit/node_modules/topcoder-react-utils" }, "repository": { "type": "git", @@ -62,6 +62,7 @@ "filestack-react": "^2.0.0", "flag-icon-css": "^3.3.0", "focus-trap-react": "^6.0.0", + "react-ga": "^2.7.0", "helmet": "^3.12.1", "highlight.js": "^9.18.1", "html-to-text": "^5.1.1", @@ -81,7 +82,7 @@ "moment-timezone": "^0.5.21", "money": "^0.2.0", "morgan": "^1.9.0", - "navigation-component": "topcoder-platform/navigation-component#develop", + "navigation-component": "topcoder-platform/navigation-component#ga-hotfix", "node-forge": "^0.7.5", "nuka-carousel": "^4.5.3", "postcss": "^6.0.23", diff --git a/src/shared/actions/index.js b/src/shared/actions/index.js index c8ef70d154..4b9dea938f 100644 --- a/src/shared/actions/index.js +++ b/src/shared/actions/index.js @@ -6,6 +6,9 @@ import { actions } from 'topcoder-react-lib'; import pageActions from './page'; +import * as tracking from './tracking'; + +export { tracking }; export default { ...pageActions, diff --git a/src/shared/actions/tracking.js b/src/shared/actions/tracking.js new file mode 100644 index 0000000000..dfac3113d9 --- /dev/null +++ b/src/shared/actions/tracking.js @@ -0,0 +1,46 @@ +/* global window */ + +import ReactGA from 'react-ga'; +import { config } from 'topcoder-react-utils'; + +const TRACKING_NAME = 'tracking'; + +/** + * init - Init Google Analytics tracking + * @param {string} userId + */ +export const init = (userId) => { + ReactGA.initialize([{ + trackingId: config.GOOGLE_ANALYTICS_ID, + gaOptions: { + name: TRACKING_NAME, + userId, + }, + }], { + alwaysSendToDefaultTracker: false, + }); +}; + +/** + * pageView - Track page view + */ +export const pageView = () => { + ReactGA.pageview(window.location.pathname + + window.location.search, [TRACKING_NAME]); +}; + +/** + * event - Add custom tracking event. + * @param {string} category + * @param {string} action + * @param {string} label + */ +export const event = (category, action, label) => { + ReactGA.event({ + category, + action, + label, + }, [TRACKING_NAME]); +}; + +export default undefined; diff --git a/src/shared/components/Header/index.jsx b/src/shared/components/Header/index.jsx index 87d1c14c29..8d20d10f2d 100644 --- a/src/shared/components/Header/index.jsx +++ b/src/shared/components/Header/index.jsx @@ -2,8 +2,8 @@ import _ from 'lodash'; import React, { useState, useEffect } from 'react'; import PT from 'prop-types'; import { config } from 'topcoder-react-utils'; -import { tracking } from 'topcoder-react-lib'; import Logo from 'assets/images/tc-logo.svg'; +import { tracking } from '../../actions'; let TopNavRef; let LoginNavRef; @@ -95,6 +95,7 @@ const Header = ({ auth={auth} profile={normalizedProfile} authURLs={config.HEADER_AUTH_URLS} + tracking={tracking} /> )} logo={} @@ -106,6 +107,7 @@ const Header = ({ setOpenMore={handleChangeOpenMore} loggedIn={!_.isEmpty(profile)} profileHandle={profile ? profile.handle : ''} + tracking={tracking} /> ); diff --git a/src/shared/components/Notifications/index.jsx b/src/shared/components/Notifications/index.jsx index 358380c760..c263e559f2 100644 --- a/src/shared/components/Notifications/index.jsx +++ b/src/shared/components/Notifications/index.jsx @@ -4,8 +4,8 @@ import cn from 'classnames'; import _ from 'lodash'; import moment from 'moment'; import { Link } from 'topcoder-react-utils'; -import { tracking } from 'topcoder-react-lib'; import IconArrow from 'assets/images/notifications/arrow.svg'; +import { tracking } from '../../actions'; import styles from './style.scss'; import TabsPanel from './TabsPanel'; From 182aaf104e584a0671b4ae9c7ffefe31ca72a5c1 Mon Sep 17 00:00:00 2001 From: "Luiz R. Rodrigues" Date: Fri, 8 May 2020 00:39:38 -0300 Subject: [PATCH 2/7] Fix loadNotifications and Google Analytics Init (useEffect) --- src/shared/components/Header/index.jsx | 27 +++++++++++--------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/src/shared/components/Header/index.jsx b/src/shared/components/Header/index.jsx index 8d20d10f2d..28f85b0051 100644 --- a/src/shared/components/Header/index.jsx +++ b/src/shared/components/Header/index.jsx @@ -54,23 +54,18 @@ const Header = ({ }, []); /* - * Reload notificaitons if token was changed - * This prevent to use expired token in API call - */ - if (auth) { - useEffect(() => { - loadNotifications(auth.tokenV3); - }, [auth.tokenV3]); - } - - /* - * Init Google Analytics + * Load Notifications and Init Google Analytics */ - if (auth && auth.user) { - useEffect(() => { - tracking.init(auth.user.handle); - }, [auth.user.handle]); - } + useEffect(() => { + if (auth) { + if (auth.tokenV3) { + loadNotifications(auth.tokenV3); + } + if (auth.user) { + tracking.init(auth.user.handle); + } + } + }, []); if (TopNavRef) { return ( From 97f11d6762ae7334307fc038e5b15fea5db85769 Mon Sep 17 00:00:00 2001 From: "Luiz R. Rodrigues" Date: Fri, 8 May 2020 00:40:59 -0300 Subject: [PATCH 3/7] CircleCI - Deply ga-hotfix to Test env --- .circleci/config.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 23019f1e68..5ab5bbe812 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -182,6 +182,7 @@ workflows: branches: only: - develop + - ga-hotfix # This is beta env for production soft releases - "build-prod-beta": context : org-global From 630b75a4dd44744f5ce5ae3a6a6f2b4faedd91aa Mon Sep 17 00:00:00 2001 From: "Luiz R. Rodrigues" Date: Fri, 8 May 2020 02:54:16 -0300 Subject: [PATCH 4/7] CircleCI - Deploy ga-hotfix to Beta env --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 5ab5bbe812..5f3651b66c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -189,8 +189,8 @@ workflows: filters: branches: only: - - hot-fix-hall-of-fame - develop + - ga-hotfix # Production builds are exectuted # when PR is merged to the master # Don't change anything in this configuration From db9603cb8f2f3a558da4bd965c304ffc433482b5 Mon Sep 17 00:00:00 2001 From: Luiz Ricardo Rodrigues Date: Sat, 9 May 2020 00:59:53 -0300 Subject: [PATCH 5/7] Update topcoder-react-lib version to v.0.17.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 723ebb90cd..be64f827e3 100644 --- a/package.json +++ b/package.json @@ -134,7 +134,7 @@ "tc-accounts": "git+https://github.com/appirio-tech/accounts-app.git#dev", "tc-core-library-js": "github:appirio-tech/tc-core-library-js#v2.6.3", "tc-ui": "^1.0.12", - "topcoder-react-lib": "v0.17.0", + "topcoder-react-lib": "v0.17.1", "topcoder-react-ui-kit": "^1.0.11", "topcoder-react-utils": "0.7.8", "turndown": "^4.0.2", From 6f03b6665a09b1c6b2ef1e33bbd3147919b2f7d6 Mon Sep 17 00:00:00 2001 From: Luiz Ricardo Rodrigues Date: Sat, 9 May 2020 01:05:23 -0300 Subject: [PATCH 6/7] Point navigation-component to develop --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index be64f827e3..f575c2c4d2 100644 --- a/package.json +++ b/package.json @@ -82,7 +82,7 @@ "moment-timezone": "^0.5.21", "money": "^0.2.0", "morgan": "^1.9.0", - "navigation-component": "topcoder-platform/navigation-component#ga-hotfix", + "navigation-component": "topcoder-platform/navigation-component#develop", "node-forge": "^0.7.5", "nuka-carousel": "^4.5.3", "postcss": "^6.0.23", From 38e8b029186fc53bdcc9cf4d595d5ee789de92c9 Mon Sep 17 00:00:00 2001 From: Luiz Ricardo Rodrigues Date: Sat, 9 May 2020 02:19:53 -0300 Subject: [PATCH 7/7] CircleCI - Removed ga-hotfix --- .circleci/config.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 5f3651b66c..c8c19b8760 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -182,7 +182,6 @@ workflows: branches: only: - develop - - ga-hotfix # This is beta env for production soft releases - "build-prod-beta": context : org-global @@ -190,7 +189,6 @@ workflows: branches: only: - develop - - ga-hotfix # Production builds are exectuted # when PR is merged to the master # Don't change anything in this configuration