diff --git a/__tests__/__snapshots__/index.js.snap b/__tests__/__snapshots__/index.js.snap index 18663275..416655e0 100644 --- a/__tests__/__snapshots__/index.js.snap +++ b/__tests__/__snapshots__/index.js.snap @@ -387,5 +387,11 @@ Object { "delay": [Function], "formatDuration": [Function], }, + "tracking": Object { + "default": undefined, + "event": [Function], + "init": [Function], + "pageView": [Function], + }, } `; diff --git a/config/default.json b/config/default.json index 38d4e982..e7c3a7bf 100644 --- a/config/default.json +++ b/config/default.json @@ -2,5 +2,6 @@ "AV_SCAN_SCORER_REVIEW_TYPE_ID": "", "PROVISIONAL_SCORING_COMPLETED_REVIEW_TYPE_ID": "", "PAGE_SIZE": 50, - "REVIEW_OPPORTUNITY_PAGE_SIZE": 1000 + "REVIEW_OPPORTUNITY_PAGE_SIZE": 1000, + "GOOGLE_ANALYTICS_ID": "" } diff --git a/config/development.json b/config/development.json index b1519a01..95eeb428 100644 --- a/config/development.json +++ b/config/development.json @@ -1,4 +1,5 @@ { "AV_SCAN_SCORER_REVIEW_TYPE_ID": "68c5a381-c8ab-48af-92a7-7a869a4ee6c3", - "PROVISIONAL_SCORING_COMPLETED_REVIEW_TYPE_ID": "52c91e85-745f-4e62-b592-9879a2dfe9fd" + "PROVISIONAL_SCORING_COMPLETED_REVIEW_TYPE_ID": "52c91e85-745f-4e62-b592-9879a2dfe9fd", + "GOOGLE_ANALYTICS_ID": "UA-161803421-1" } diff --git a/config/production.json b/config/production.json index d2b1223d..92031113 100644 --- a/config/production.json +++ b/config/production.json @@ -1,4 +1,5 @@ { "AV_SCAN_SCORER_REVIEW_TYPE_ID": "55bbb17d-aac2-45a6-89c3-a8d102863d05", - "PROVISIONAL_SCORING_COMPLETED_REVIEW_TYPE_ID": "df51ca7d-fb0a-4147-9569-992fcf5aae48" + "PROVISIONAL_SCORING_COMPLETED_REVIEW_TYPE_ID": "df51ca7d-fb0a-4147-9569-992fcf5aae48", + "GOOGLE_ANALYTICS_ID": "UA-6340959-1" } diff --git a/config/webpack/default.js b/config/webpack/default.js index 4872dd72..3ef26273 100644 --- a/config/webpack/default.js +++ b/config/webpack/default.js @@ -19,6 +19,7 @@ module.exports = { 'moment-duration-format', 'react', 'react-dom', + 'react-ga', 'redux', 'redux-actions', 'isomorphic-fetch', diff --git a/package.json b/package.json index b5a3500b..74bc2abe 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "lint:js": "./node_modules/.bin/eslint --ext .js,.jsx .", "test": "npm run lint && npm run jest" }, - "version": "0.15.0", + "version": "0.17.0", "dependencies": { "auth0-js": "^6.8.4", "config": "^3.2.0", @@ -44,6 +44,7 @@ "qs": "^6.5.2", "react": "^16.4.1", "react-dom": "^16.4.1", + "react-ga": "^2.7.0", "react-redux": "^6.0.1", "redux": "^3.7.2", "redux-actions": "^2.4.0", diff --git a/src/index.js b/src/index.js index 78103660..b8c4c79f 100644 --- a/src/index.js +++ b/src/index.js @@ -12,5 +12,5 @@ export { actions } from './actions'; export { services } from './services'; export { - challenge, logger, errors, tc, time, mock, submission, + challenge, logger, errors, tc, time, mock, submission, tracking, } from './utils'; diff --git a/src/utils/index.js b/src/utils/index.js index 6a6387a4..d0212e21 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -8,6 +8,7 @@ import * as mock from './mock'; import * as errors from './errors'; import * as filter from './challenge/filter'; import * as submission from './submission'; +import * as tracking from './tracking'; const challenge = { filter, @@ -21,4 +22,5 @@ export { mock, errors, submission, + tracking, }; diff --git a/src/utils/tracking.js b/src/utils/tracking.js new file mode 100644 index 00000000..4b764615 --- /dev/null +++ b/src/utils/tracking.js @@ -0,0 +1,47 @@ +/* global window */ +/* global CONFIG */ + +import ReactGA from 'react-ga'; + +const { GOOGLE_ANALYTICS_ID } = CONFIG; +const TRACKING_NAME = 'tracking'; + +/** + * init - Init Google Analytics tracking + * @param {string} userId + */ +export const init = (userId) => { + ReactGA.initialize([{ + trackingId: 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; pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy