diff --git a/karma.conf.js b/karma.conf.js index 8233bc0145e..bb5a9fdf485 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -58,7 +58,8 @@ module.exports = function(config) { new webpack.DefinePlugin({ ENV_API_ROOT: null, ENV_LOGIN_ROOT: null, - ENV_APP_ROOT: null + ENV_APP_ROOT: null, + ENV_GA_ID: null }), new CircularDependencyPlugin({ failOnError: true, diff --git a/package.json b/package.json index 79ad82b4234..d622676d6af 100644 --- a/package.json +++ b/package.json @@ -102,6 +102,7 @@ "react": "^15.1.0", "react-addons-test-utils": "^15.1.0", "react-dom": "^15.1.0", + "react-ga": "^2.1.2", "react-redux": "^4.0.6", "react-router": "^2.4.1", "react-router-redux": "^4.0.5", diff --git a/src/constants.js b/src/constants.js index 9a23a456d07..4c05bff1be1 100644 --- a/src/constants.js +++ b/src/constants.js @@ -1,6 +1,7 @@ export const API_ROOT = ENV_API_ROOT || 'https://api.alpha.linode.com/v4'; // eslint-disable-line no-undef export const LOGIN_ROOT = ENV_LOGIN_ROOT || 'https://login.alpha.linode.com'; // eslint-disable-line no-undef export const APP_ROOT = ENV_APP_ROOT || 'http://localhost:3000'; // eslint-disable-line no-undef +export const GA_ID = ENV_GA_ID || '000000'; // eslint-disable-line no-undef export const LinodeStates = { pending: [ diff --git a/src/index.js b/src/index.js index 57e5d5be634..3146d259b5b 100644 --- a/src/index.js +++ b/src/index.js @@ -6,6 +6,8 @@ import store from './store'; import { Router, Route, IndexRedirect, browserHistory } from 'react-router'; import DevTools from './components/DevTools'; import { syncHistoryWithStore } from 'react-router-redux'; +import ReactGA from 'react-ga'; +import { GA_ID } from './constants'; import checkLogin, { initializeAuthentication } from './session'; @@ -29,11 +31,17 @@ import { hideModal } from '~/actions/modal'; import { actions, thunks, reducer } from '~/api/configs/linodes'; window.actions = actions; window.thunks = thunks; window.reducer = reducer; +ReactGA.initialize(GA_ID); // eslint-disable-line no-undef +function logPageView() { + ReactGA.set({ page: window.location.pathname }); + ReactGA.pageview(window.location.pathname); +} + const init = () => { render(
- + store.dispatch(hideModal())} diff --git a/webpack.config.dev.js b/webpack.config.dev.js index 4664755fa52..97c83342e1c 100644 --- a/webpack.config.dev.js +++ b/webpack.config.dev.js @@ -21,7 +21,8 @@ module.exports = { new webpack.DefinePlugin({ 'ENV_API_ROOT': JSON.stringify(process.env.API_ROOT), 'ENV_LOGIN_ROOT': JSON.stringify(process.env.LOGIN_ROOT), - 'ENV_APP_ROOT': JSON.stringify(process.env.APP_ROOT) + 'ENV_APP_ROOT': JSON.stringify(process.env.APP_ROOT), + 'ENV_GA_ID': JSON.stringify(process.env.GA_ID) }) ], module: { diff --git a/webpack.config.prod.js b/webpack.config.prod.js index a961d9a0ed5..38d3fdae564 100644 --- a/webpack.config.prod.js +++ b/webpack.config.prod.js @@ -12,7 +12,8 @@ _.plugins = [ }, 'ENV_APP_ROOT': JSON.stringify(process.env.APP_ROOT), 'ENV_API_ROOT': JSON.stringify(process.env.API_ROOT), - 'ENV_LOGIN_ROOT': JSON.stringify(process.env.LOGIN_ROOT) + 'ENV_LOGIN_ROOT': JSON.stringify(process.env.LOGIN_ROOT), + 'ENV_GA_ID': JSON.stringify(process.env.GA_ID) }), new webpack.optimize.UglifyJsPlugin({ compressor: {