Skip to content

Commit 02b5830

Browse files
#4309: Move notifications tracking from topcoder-react-lib to community-app
1 parent 921aefb commit 02b5830

File tree

8 files changed

+76
-4
lines changed

8 files changed

+76
-4
lines changed

__tests__/shared/components/Header/__snapshots__/index.jsx.snap

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,26 @@ exports[`Default render 1`] = `
182182
"title": "Switch to BUSINESS",
183183
}
184184
}
185+
tracking={
186+
Object {
187+
"default": undefined,
188+
"event": [Function],
189+
"init": [Function],
190+
"pageView": [Function],
191+
}
192+
}
185193
/>
186194
}
187195
setOpenMore={[Function]}
188196
theme="light"
197+
tracking={
198+
Object {
199+
"default": undefined,
200+
"event": [Function],
201+
"init": [Function],
202+
"pageView": [Function],
203+
}
204+
}
189205
/>
190206
</div>
191207
`;

config/default.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ module.exports = {
9696

9797
SWIFT_PROGRAM_ID: 3445,
9898

99+
/* Google Analytics tracking ID */
100+
GOOGLE_ANALYTICS_ID: 'UA-161803421-1',
101+
99102
/* Various URLs. Most of them lead to different segments of Topcoder
100103
* platform. */
101104
URL: {

config/production.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module.exports = {
1717
},
1818
LOG_ENTRIES_TOKEN: '',
1919
SERVER_API_KEY: 'aa9ccf36-3936-450c-9983-097ddba51bef',
20+
GOOGLE_ANALYTICS_ID: 'UA-6340959-1',
2021
URL: {
2122
ARENA: 'https://arena.topcoder.com',
2223
APP: 'https://community-app.topcoder.com',

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"test": "npm run lint && npm run --runInBand jest",
1919
"commitlint": "commitlint -E HUSKY_GIT_PARAMS",
2020
"release:changelog": "npm run conventional-changelog -- -p angular -i CHANGELOG.md -s",
21-
"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"
21+
"postinstall": "rimraf node_modules/navigation-component/node_modules/topcoder-react-utils && rimraf node_modules/topcoder-react-ui-kit/node_modules/topcoder-react-utils"
2222
},
2323
"repository": {
2424
"type": "git",
@@ -62,6 +62,7 @@
6262
"filestack-react": "^2.0.0",
6363
"flag-icon-css": "^3.3.0",
6464
"focus-trap-react": "^6.0.0",
65+
"react-ga": "^2.7.0",
6566
"helmet": "^3.12.1",
6667
"highlight.js": "^9.18.1",
6768
"html-to-text": "^5.1.1",
@@ -81,7 +82,7 @@
8182
"moment-timezone": "^0.5.21",
8283
"money": "^0.2.0",
8384
"morgan": "^1.9.0",
84-
"navigation-component": "topcoder-platform/navigation-component#develop",
85+
"navigation-component": "topcoder-platform/navigation-component#ga-hotfix",
8586
"node-forge": "^0.7.5",
8687
"nuka-carousel": "^4.5.3",
8788
"postcss": "^6.0.23",

src/shared/actions/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
import { actions } from 'topcoder-react-lib';
88
import pageActions from './page';
9+
import * as tracking from './tracking';
10+
11+
export { tracking };
912

1013
export default {
1114
...pageActions,

src/shared/actions/tracking.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/* global window */
2+
3+
import ReactGA from 'react-ga';
4+
import { config } from 'topcoder-react-utils';
5+
6+
const TRACKING_NAME = 'tracking';
7+
8+
/**
9+
* init - Init Google Analytics tracking
10+
* @param {string} userId
11+
*/
12+
export const init = (userId) => {
13+
ReactGA.initialize([{
14+
trackingId: config.GOOGLE_ANALYTICS_ID,
15+
gaOptions: {
16+
name: TRACKING_NAME,
17+
userId,
18+
},
19+
}], {
20+
alwaysSendToDefaultTracker: false,
21+
});
22+
};
23+
24+
/**
25+
* pageView - Track page view
26+
*/
27+
export const pageView = () => {
28+
ReactGA.pageview(window.location.pathname
29+
+ window.location.search, [TRACKING_NAME]);
30+
};
31+
32+
/**
33+
* event - Add custom tracking event.
34+
* @param {string} category
35+
* @param {string} action
36+
* @param {string} label
37+
*/
38+
export const event = (category, action, label) => {
39+
ReactGA.event({
40+
category,
41+
action,
42+
label,
43+
}, [TRACKING_NAME]);
44+
};
45+
46+
export default undefined;

src/shared/components/Header/index.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import _ from 'lodash';
22
import React, { useState, useEffect } from 'react';
33
import PT from 'prop-types';
44
import { config } from 'topcoder-react-utils';
5-
import { tracking } from 'topcoder-react-lib';
65
import Logo from 'assets/images/tc-logo.svg';
6+
import { tracking } from '../../actions';
77

88
let TopNavRef;
99
let LoginNavRef;
@@ -95,6 +95,7 @@ const Header = ({
9595
auth={auth}
9696
profile={normalizedProfile}
9797
authURLs={config.HEADER_AUTH_URLS}
98+
tracking={tracking}
9899
/>
99100
)}
100101
logo={<Logo />}
@@ -106,6 +107,7 @@ const Header = ({
106107
setOpenMore={handleChangeOpenMore}
107108
loggedIn={!_.isEmpty(profile)}
108109
profileHandle={profile ? profile.handle : ''}
110+
tracking={tracking}
109111
/>
110112
</div>
111113
);

src/shared/components/Notifications/index.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import cn from 'classnames';
44
import _ from 'lodash';
55
import moment from 'moment';
66
import { Link } from 'topcoder-react-utils';
7-
import { tracking } from 'topcoder-react-lib';
87
import IconArrow from 'assets/images/notifications/arrow.svg';
8+
import { tracking } from '../../actions';
99
import styles from './style.scss';
1010
import TabsPanel from './TabsPanel';
1111

0 commit comments

Comments
 (0)