Skip to content

#4309: Move tracking from topcoder-react-lib to community-app #4315

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
May 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ workflows:
filters:
branches:
only:
- hot-fix-hall-of-fame
- develop
# Production builds are exectuted
# when PR is merged to the master
Expand Down
16 changes: 16 additions & 0 deletions __tests__/shared/components/Header/__snapshots__/index.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,26 @@ exports[`Default render 1`] = `
"title": "Switch to BUSINESS",
}
}
tracking={
Object {
"default": undefined,
"event": [Function],
"init": [Function],
"pageView": [Function],
}
}
/>
}
setOpenMore={[Function]}
theme="light"
tracking={
Object {
"default": undefined,
"event": [Function],
"init": [Function],
"pageView": [Function],
}
}
/>
</div>
`;
3 changes: 3 additions & 0 deletions config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ module.exports = {

SWIFT_PROGRAM_ID: 3445,

/* Google Analytics tracking ID */
GOOGLE_ANALYTICS_ID: 'UA-161803421-1',

/* Various URLs. Most of them lead to different segments of Topcoder
* platform. */
URL: {
Expand Down
1 change: 1 addition & 0 deletions config/production.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module.exports = {
},
LOG_ENTRIES_TOKEN: '',
SERVER_API_KEY: 'aa9ccf36-3936-450c-9983-097ddba51bef',
GOOGLE_ANALYTICS_ID: 'UA-6340959-1',
URL: {
ARENA: 'https://arena.topcoder.com',
APP: 'https://community-app.topcoder.com',
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"test": "npm run lint && npm run --runInBand jest",
"commitlint": "commitlint -E HUSKY_GIT_PARAMS",
"release:changelog": "npm run conventional-changelog -- -p angular -i CHANGELOG.md -s",
"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"
"postinstall": "rimraf node_modules/navigation-component/node_modules/topcoder-react-utils && rimraf node_modules/topcoder-react-ui-kit/node_modules/topcoder-react-utils"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -62,6 +62,7 @@
"filestack-react": "^2.0.0",
"flag-icon-css": "^3.3.0",
"focus-trap-react": "^6.0.0",
"react-ga": "^2.7.0",
"helmet": "^3.12.1",
"highlight.js": "^9.18.1",
"html-to-text": "^5.1.1",
Expand Down Expand Up @@ -133,7 +134,7 @@
"tc-accounts": "git+https://github.com/appirio-tech/accounts-app.git#dev",
"tc-core-library-js": "github:appirio-tech/tc-core-library-js#v2.6.3",
"tc-ui": "^1.0.12",
"topcoder-react-lib": "v0.17.0",
"topcoder-react-lib": "v0.17.1",
"topcoder-react-ui-kit": "^1.0.11",
"topcoder-react-utils": "0.7.8",
"turndown": "^4.0.2",
Expand Down
3 changes: 3 additions & 0 deletions src/shared/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

import { actions } from 'topcoder-react-lib';
import pageActions from './page';
import * as tracking from './tracking';

export { tracking };

export default {
...pageActions,
Expand Down
46 changes: 46 additions & 0 deletions src/shared/actions/tracking.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/* global window */

import ReactGA from 'react-ga';
import { config } from 'topcoder-react-utils';

const TRACKING_NAME = 'tracking';

/**
* init - Init Google Analytics tracking
* @param {string} userId
*/
export const init = (userId) => {
ReactGA.initialize([{
trackingId: config.GOOGLE_ANALYTICS_ID,
gaOptions: {
name: TRACKING_NAME,
userId,
},
}], {
alwaysSendToDefaultTracker: false,
});
};

/**
* pageView - Track page view
*/
export const pageView = () => {
ReactGA.pageview(window.location.pathname
+ window.location.search, [TRACKING_NAME]);
};

/**
* event - Add custom tracking event.
* @param {string} category
* @param {string} action
* @param {string} label
*/
export const event = (category, action, label) => {
ReactGA.event({
category,
action,
label,
}, [TRACKING_NAME]);
};

export default undefined;
31 changes: 14 additions & 17 deletions src/shared/components/Header/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import _ from 'lodash';
import React, { useState, useEffect } from 'react';
import PT from 'prop-types';
import { config } from 'topcoder-react-utils';
import { tracking } from 'topcoder-react-lib';
import Logo from 'assets/images/tc-logo.svg';
import { tracking } from '../../actions';

let TopNavRef;
let LoginNavRef;
Expand Down Expand Up @@ -54,23 +54,18 @@ const Header = ({
}, []);

/*
* Reload notificaitons if token was changed
* This prevent to use expired token in API call
*/
if (auth) {
useEffect(() => {
loadNotifications(auth.tokenV3);
}, [auth.tokenV3]);
}

/*
* Init Google Analytics
* Load Notifications and Init Google Analytics
*/
if (auth && auth.user) {
useEffect(() => {
tracking.init(auth.user.handle);
}, [auth.user.handle]);
}
useEffect(() => {
if (auth) {
if (auth.tokenV3) {
loadNotifications(auth.tokenV3);
}
if (auth.user) {
tracking.init(auth.user.handle);
}
}
}, []);

if (TopNavRef) {
return (
Expand All @@ -95,6 +90,7 @@ const Header = ({
auth={auth}
profile={normalizedProfile}
authURLs={config.HEADER_AUTH_URLS}
tracking={tracking}
/>
)}
logo={<Logo />}
Expand All @@ -106,6 +102,7 @@ const Header = ({
setOpenMore={handleChangeOpenMore}
loggedIn={!_.isEmpty(profile)}
profileHandle={profile ? profile.handle : ''}
tracking={tracking}
/>
</div>
);
Expand Down
2 changes: 1 addition & 1 deletion src/shared/components/Notifications/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import cn from 'classnames';
import _ from 'lodash';
import moment from 'moment';
import { Link } from 'topcoder-react-utils';
import { tracking } from 'topcoder-react-lib';
import IconArrow from 'assets/images/notifications/arrow.svg';
import { tracking } from '../../actions';
import styles from './style.scss';
import TabsPanel from './TabsPanel';

Expand Down