Allow to disable GA

This commit is contained in:
cyril lopez 2018-03-23 12:44:17 +01:00
parent b15c848cd8
commit 19648b1a13
10 changed files with 84 additions and 5 deletions

View File

@ -3,3 +3,17 @@
* AdminPage actions
*
*/
import { GET_GA_STATUS, GET_GA_STATUS_SUCCEEDED } from './constants';
export function getGaStatus() {
return {
type: GET_GA_STATUS,
};
}
export function getGaStatusSucceeded(allowGa) {
return {
type: GET_GA_STATUS_SUCCEEDED,
allowGa,
};
}

View File

@ -3,3 +3,6 @@
* AdminPage constants
*
*/
export const GET_GA_STATUS = 'app/Admin/GET_GA_STATUS';
export const GET_GA_STATUS_SUCCEEDED = 'app/Admin/GET_GA_STATUS_SUCCEEDED';

View File

@ -52,6 +52,7 @@ import auth from 'utils/auth';
import injectReducer from 'utils/injectReducer';
import injectSaga from 'utils/injectSaga';
import { getGaStatus } from './actions';
import reducer from './reducer';
import saga from './saga';
import selectAdminPage from './selectors';
@ -72,7 +73,7 @@ export class AdminPage extends React.Component { // eslint-disable-line react/pr
componentDidMount() {
this.checkLogin(this.props);
this.props.getGaStatus();
ReactGA.initialize('UA-54313258-9');
}
@ -80,7 +81,9 @@ export class AdminPage extends React.Component { // eslint-disable-line react/pr
if (nextProps.location.pathname !== this.props.location.pathname) {
this.checkLogin(nextProps);
ReactGA.pageview(nextProps.location.pathname);
if (nextProps.adminPage.allowGa) {
ReactGA.pageview(nextProps.location.pathname);
}
}
if (get(nextProps.plugins.toJS(), ['users-permissions', 'hasAdminUser']) !== get(this.props.plugins.toJS(), ['users-permissions', 'hasAdminUser'])) {
@ -185,6 +188,7 @@ AdminPage.propTypes = {
blockApp: PropTypes.bool.isRequired,
disableGlobalOverlayBlocker: PropTypes.func.isRequired,
enableGlobalOverlayBlocker: PropTypes.func.isRequired,
getGaStatus: PropTypes.func.isRequired,
hasUserPlugin: PropTypes.bool,
history: PropTypes.object.isRequired,
location: PropTypes.object.isRequired,
@ -206,6 +210,7 @@ function mapDispatchToProps(dispatch) {
return {
disableGlobalOverlayBlocker: () => { dispatch(disableGlobalOverlayBlocker()); },
enableGlobalOverlayBlocker: () => { dispatch(enableGlobalOverlayBlocker()); },
getGaStatus: () => { dispatch(getGaStatus()); },
onHideNotification: (id) => { dispatch(hideNotification(id)); },
pluginLoaded: (plugin) => { dispatch(pluginLoaded(plugin)); },
updatePlugin: (pluginId, updatedKey, updatedValue) => { dispatch(updatePlugin(pluginId, updatedKey, updatedValue)); },

View File

@ -6,10 +6,16 @@
import { fromJS } from 'immutable';
const initialState = fromJS({});
import { GET_GA_STATUS_SUCCEEDED } from './constants';
const initialState = fromJS({
allowGa: true,
});
function adminPageReducer(state = initialState, action) {
switch (action.type) {
case GET_GA_STATUS_SUCCEEDED:
return state.update('allowGa', () => action.allowGa);
default:
return state;
}

View File

@ -1,3 +1,20 @@
function* defaultSaga() {}
import { fork, call, put, takeLatest } from 'redux-saga/effects';
import request from 'utils/request';
import { getGaStatusSucceeded } from './actions';
import { GET_GA_STATUS } from './constants';
function* getGaStatus() {
try {
const response = yield call(request, '/admin/gaConfig', { method: 'GET' });
yield put(getGaStatusSucceeded(response.allowGa));
} catch(err) {
strapi.notification.error('notification.error');
}
}
function* defaultSaga() {
yield fork(takeLatest, GET_GA_STATUS, getGaStatus);
}
export default defaultSaga;

View File

@ -14,6 +14,12 @@
"handler": "Admin.getCurrentEnvironment",
"policies": []
},
{
"method": "GET",
"path": "/gaConfig",
"handler": "Admin.getGaConfig",
"policies": []
},
{
"method": "POST",
"path": "/plugins/install",

View File

@ -2,6 +2,7 @@
const path = require('path');
const exec = require('child_process').execSync;
const _ = require('lodash');
/**
* A set of functions called "actions" for `Admin`
@ -16,6 +17,16 @@ module.exports = {
}
},
getGaConfig: async ctx =>{
try {
const allowGa = _.get(strapi.config, 'info.customs.allowGa', true);
ctx.send({ allowGa });
} catch(err) {
console.log(err)
ctx.badRequest(null, [{ messages: [{ id: 'An error occured' }] }]);
}
},
installPlugin: async ctx => {
try {
const { plugin, port } = ctx.request.body;

View File

@ -0,0 +1,16 @@
# DISCLAIMER:
Google Analytics allows us to analyze the usage of Strapi. The aim is to
improve the product and helps us to understand how you interact with the Admin.
Note: The collected data are anonymous and aren't sold to anyone!
If you don't want to share your data with us, you can simply modify the `strapi` object in the package.json as follows:
```json
{
"strapi": {
"allowGa": false
}
}
```

View File

@ -48,4 +48,4 @@
"npm": ">= 3.0.0"
},
"license": "MIT"
}
}

View File

@ -73,6 +73,7 @@ module.exports.nested = function() {
module.exports.app = async function() {
// Retrieve Strapi version.
this.config.uuid = get(this.config.info, 'strapi.uuid', '');
this.config.info.customs = get(this.config.info, 'strapi', {});
this.config.info.strapi = (get(this.config, 'info.dependencies.strapi') || '').replace(/(\^|~)/g, ''),
this.config.info.node = process.versions.node;