Skip to content

Commit f7f2576

Browse files
committed
ci: Merge remote-tracking branch 'origin/develop' into config-hotfix
2 parents 21763bd + f0532a0 commit f7f2576

File tree

9 files changed

+90
-22
lines changed

9 files changed

+90
-22
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",
@@ -133,7 +134,7 @@
133134
"tc-accounts": "git+https://github.com/appirio-tech/accounts-app.git#dev",
134135
"tc-core-library-js": "github:appirio-tech/tc-core-library-js#v2.6.3",
135136
"tc-ui": "^1.0.12",
136-
"topcoder-react-lib": "v1000.15.4",
137+
"topcoder-react-lib": "v1000.16.0",
137138
"topcoder-react-ui-kit": "^1.0.11",
138139
"topcoder-react-utils": "0.7.8",
139140
"turndown": "^4.0.2",

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: 14 additions & 17 deletions
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;
@@ -54,23 +54,18 @@ const Header = ({
5454
}, []);
5555

5656
/*
57-
* Reload notificaitons if token was changed
58-
* This prevent to use expired token in API call
59-
*/
60-
if (auth) {
61-
useEffect(() => {
62-
loadNotifications(auth.tokenV3);
63-
}, [auth.tokenV3]);
64-
}
65-
66-
/*
67-
* Init Google Analytics
57+
* Load Notifications and Init Google Analytics
6858
*/
69-
if (auth && auth.user) {
70-
useEffect(() => {
71-
tracking.init(auth.user.handle);
72-
}, [auth.user.handle]);
73-
}
59+
useEffect(() => {
60+
if (auth) {
61+
if (auth.tokenV3) {
62+
loadNotifications(auth.tokenV3);
63+
}
64+
if (auth.user) {
65+
tracking.init(auth.user.handle);
66+
}
67+
}
68+
}, []);
7469

7570
if (TopNavRef) {
7671
return (
@@ -95,6 +90,7 @@ const Header = ({
9590
auth={auth}
9691
profile={normalizedProfile}
9792
authURLs={config.HEADER_AUTH_URLS}
93+
tracking={tracking}
9894
/>
9995
)}
10096
logo={<Logo />}
@@ -106,6 +102,7 @@ const Header = ({
106102
setOpenMore={handleChangeOpenMore}
107103
loggedIn={!_.isEmpty(profile)}
108104
profileHandle={profile ? profile.handle : ''}
105+
tracking={tracking}
109106
/>
110107
</div>
111108
);

src/shared/components/Notifications/TabsPanel/index.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
33
import cn from 'classnames';
4-
import { tracking } from 'topcoder-react-lib';
54
import styles from './style.scss';
65

76

@@ -21,7 +20,7 @@ export default class TabsPanel extends React.Component {
2120

2221

2322
render() {
24-
const { changeTab } = this.props;
23+
const { changeTab, tracking } = this.props;
2524
const { tab } = this.state;
2625
return (
2726
<div className={styles.container}>
@@ -106,4 +105,5 @@ export default class TabsPanel extends React.Component {
106105

107106
TabsPanel.propTypes = {
108107
changeTab: PropTypes.func.isRequired,
108+
tracking: PropTypes.shape().isRequired,
109109
};

src/shared/components/Notifications/index.jsx

Lines changed: 2 additions & 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

@@ -184,6 +184,7 @@ export default class NotificationList extends React.Component {
184184
<div className={styles['notifications-panel']}>
185185
<TabsPanel
186186
changeTab={tab => this.setState({ activeTab: tab })}
187+
tracking={tracking}
187188
/>
188189
<div className={styles['noti-body']}>
189190
<Fragment key="nonComplete">

0 commit comments

Comments
 (0)