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,11 +69,13 @@ function (_React$Component) {
|
|||
}, {
|
||||
key: "sendPageView",
|
||||
value: function sendPageView(location) {
|
||||
_reactGa.default.set({
|
||||
page: location.pathname
|
||||
});
|
||||
if (googleId) {
|
||||
_reactGa.default.set({
|
||||
page: location.pathname
|
||||
});
|
||||
|
||||
_reactGa.default.pageview(location.pathname);
|
||||
_reactGa.default.pageview(location.pathname);
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: "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,8 +29,10 @@ class GAListener extends React.Component {
|
|||
}
|
||||
|
||||
sendPageView (location) {
|
||||
GoogleAnalytics.set({ page: location.pathname });
|
||||
GoogleAnalytics.pageview(location.pathname);
|
||||
if (googleId) {
|
||||
GoogleAnalytics.set({ page: location.pathname });
|
||||
GoogleAnalytics.pageview(location.pathname);
|
||||
}
|
||||
}
|
||||
|
||||
render () {
|
||||
|
|
Loading…
Reference in a new issue