Skip to content

Commit a9936b1

Browse files
authored
Merge pull request #160 from topcoder-platform/develop
Notifications Analytics
2 parents de55694 + b5fb7d0 commit a9936b1

File tree

9 files changed

+65
-5
lines changed

9 files changed

+65
-5
lines changed

__tests__/__snapshots__/index.js.snap

+6
Original file line numberDiff line numberDiff line change
@@ -387,5 +387,11 @@ Object {
387387
"delay": [Function],
388388
"formatDuration": [Function],
389389
},
390+
"tracking": Object {
391+
"default": undefined,
392+
"event": [Function],
393+
"init": [Function],
394+
"pageView": [Function],
395+
},
390396
}
391397
`;

config/default.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
"AV_SCAN_SCORER_REVIEW_TYPE_ID": "",
33
"PROVISIONAL_SCORING_COMPLETED_REVIEW_TYPE_ID": "",
44
"PAGE_SIZE": 50,
5-
"REVIEW_OPPORTUNITY_PAGE_SIZE": 1000
5+
"REVIEW_OPPORTUNITY_PAGE_SIZE": 1000,
6+
"GOOGLE_ANALYTICS_ID": ""
67
}

config/development.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
22
"AV_SCAN_SCORER_REVIEW_TYPE_ID": "68c5a381-c8ab-48af-92a7-7a869a4ee6c3",
3-
"PROVISIONAL_SCORING_COMPLETED_REVIEW_TYPE_ID": "52c91e85-745f-4e62-b592-9879a2dfe9fd"
3+
"PROVISIONAL_SCORING_COMPLETED_REVIEW_TYPE_ID": "52c91e85-745f-4e62-b592-9879a2dfe9fd",
4+
"GOOGLE_ANALYTICS_ID": "UA-161803421-1"
45
}

config/production.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
22
"AV_SCAN_SCORER_REVIEW_TYPE_ID": "55bbb17d-aac2-45a6-89c3-a8d102863d05",
3-
"PROVISIONAL_SCORING_COMPLETED_REVIEW_TYPE_ID": "df51ca7d-fb0a-4147-9569-992fcf5aae48"
3+
"PROVISIONAL_SCORING_COMPLETED_REVIEW_TYPE_ID": "df51ca7d-fb0a-4147-9569-992fcf5aae48",
4+
"GOOGLE_ANALYTICS_ID": "UA-6340959-1"
45
}

config/webpack/default.js

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ module.exports = {
1919
'moment-duration-format',
2020
'react',
2121
'react-dom',
22+
'react-ga',
2223
'redux',
2324
'redux-actions',
2425
'isomorphic-fetch',

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"lint:js": "./node_modules/.bin/eslint --ext .js,.jsx .",
3232
"test": "npm run lint && npm run jest"
3333
},
34-
"version": "0.15.0",
34+
"version": "0.17.0",
3535
"dependencies": {
3636
"auth0-js": "^6.8.4",
3737
"config": "^3.2.0",
@@ -44,6 +44,7 @@
4444
"qs": "^6.5.2",
4545
"react": "^16.4.1",
4646
"react-dom": "^16.4.1",
47+
"react-ga": "^2.7.0",
4748
"react-redux": "^6.0.1",
4849
"redux": "^3.7.2",
4950
"redux-actions": "^2.4.0",

src/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ export { actions } from './actions';
1212
export { services } from './services';
1313

1414
export {
15-
challenge, logger, errors, tc, time, mock, submission,
15+
challenge, logger, errors, tc, time, mock, submission, tracking,
1616
} from './utils';

src/utils/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import * as mock from './mock';
88
import * as errors from './errors';
99
import * as filter from './challenge/filter';
1010
import * as submission from './submission';
11+
import * as tracking from './tracking';
1112

1213
const challenge = {
1314
filter,
@@ -21,4 +22,5 @@ export {
2122
mock,
2223
errors,
2324
submission,
25+
tracking,
2426
};

src/utils/tracking.js

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

0 commit comments

Comments
 (0)