Skip to content

Commit 71dd786

Browse files
Google Analytics tracking
topcoder-platform/community-app#4154
1 parent f827249 commit 71dd786

File tree

4 files changed

+49
-1
lines changed

4 files changed

+49
-1
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -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

+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)