Fix configs loading #470
2 changed files with 28 additions and 11 deletions
|
@ -36,12 +36,18 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.getPrototypeOf || functio
|
|||
var googleId = null;
|
||||
|
||||
if (!_siteConfig.default) {
|
||||
console.log('no site config found for GAListener');
|
||||
console.log('WARNING: no site config found for GAListener');
|
||||
}
|
||||
|
||||
if (_siteConfig.default.analytics) {
|
||||
googleId = _siteConfig.default.analytics.googleId;
|
||||
if (!_siteConfig.default.analytics) {
|
||||
console.log('WARNING: no analytics configs found in siteConfig.json');
|
||||
}
|
||||
|
||||
if (_siteConfig.default && _siteConfig.default.analytics) {
|
||||
googleId = _siteConfig.default.analytics.googleId;
|
||||
}
|
||||
|
||||
if (googleId) {
|
||||
_reactGa.default.initialize(googleId);
|
||||
}
|
||||
|
||||
|
@ -63,12 +69,14 @@ function (_React$Component) {
|
|||
}, {
|
||||
key: "sendPageView",
|
||||
value: function sendPageView(location) {
|
||||
if (googleId) {
|
||||
_reactGa.default.set({
|
||||
page: location.pathname
|
||||
});
|
||||
|
||||
_reactGa.default.pageview(location.pathname);
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: "render",
|
||||
value: function render() {
|
||||
|
|
|
@ -7,11 +7,18 @@ import siteConfig from '@config/siteConfig.json';
|
|||
let googleId = null;
|
||||
|
||||
if (!siteConfig) {
|
||||
console.log('no site config found for GAListener');
|
||||
console.log('WARNING: no site config found for GAListener');
|
||||
}
|
||||
|
||||
if (siteConfig.analytics) {
|
||||
if (!siteConfig.analytics) {
|
||||
console.log('WARNING: no analytics configs found in siteConfig.json');
|
||||
}
|
||||
|
||||
if (siteConfig && siteConfig.analytics) {
|
||||
({ googleId } = siteConfig.analytics);
|
||||
}
|
||||
|
||||
if (googleId) {
|
||||
GoogleAnalytics.initialize(googleId);
|
||||
}
|
||||
|
||||
|
@ -22,9 +29,11 @@ class GAListener extends React.Component {
|
|||
}
|
||||
|
||||
sendPageView (location) {
|
||||
if (googleId) {
|
||||
GoogleAnalytics.set({ page: location.pathname });
|
||||
GoogleAnalytics.pageview(location.pathname);
|
||||
}
|
||||
}
|
||||
|
||||
render () {
|
||||
return this.props.children;
|
||||
|
|
Loading…
Reference in a new issue