Skip to content

Commit 1411199

Browse files
authored
Merge pull request #150 from topcoder-platform/notifications-analytics
Notifications analytics
2 parents 418b158 + fa544cd commit 1411199

File tree

6 files changed

+58
-2
lines changed

6 files changed

+58
-2
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/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

+3-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"url": "git+https://github.com/topcoder-platform/topcoder-react-lib.git"
2222
},
2323
"scripts": {
24+
"prepare": "npm run build",
2425
"build": "npm run clean && npm run build:dev && npm run build:prod",
2526
"build:dev": "./node_modules/.bin/webpack --env=development --progress --profile --colors --display-optimization-bailout",
2627
"build:dev:watch": "npm run clean && ./node_modules/.bin/webpack --env=development --progress --profile --colors --watch --display-optimization-bailout",
@@ -31,7 +32,7 @@
3132
"lint:js": "./node_modules/.bin/eslint --ext .js,.jsx .",
3233
"test": "npm run lint && npm run jest"
3334
},
34-
"version": "0.15.0",
35+
"version": "0.16.0",
3536
"dependencies": {
3637
"auth0-js": "^6.8.4",
3738
"config": "^3.2.0",
@@ -44,6 +45,7 @@
4445
"qs": "^6.5.2",
4546
"react": "^16.4.1",
4647
"react-dom": "^16.4.1",
48+
"react-ga": "^2.7.0",
4749
"react-redux": "^6.0.1",
4850
"redux": "^3.7.2",
4951
"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

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

0 commit comments

Comments
 (0)