Fix configs loading #470
2 changed files with 11 additions and 7 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
const logger = require('winston');
|
||||||
|
|
||||||
function SiteConfig () {
|
function SiteConfig () {
|
||||||
this.analytics = {
|
this.analytics = {
|
||||||
googleId: 'default',
|
googleId: 'default',
|
||||||
|
@ -31,7 +33,7 @@ function SiteConfig () {
|
||||||
return console.log('No site config received.');
|
return console.log('No site config received.');
|
||||||
}
|
}
|
||||||
const { analytics, assetDefaults, auth, details, publishing } = config;
|
const { analytics, assetDefaults, auth, details, publishing } = config;
|
||||||
console.log('Configuring site details...');
|
logger.info('configuring site details...');
|
||||||
this.analytics = analytics;
|
this.analytics = analytics;
|
||||||
this.assetDefaults = assetDefaults;
|
this.assetDefaults = assetDefaults;
|
||||||
this.auth = auth;
|
this.auth = auth;
|
||||||
|
|
|
@ -13,7 +13,7 @@ const createServeEventParams = (headers, ip, originalUrl) => {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const createPublishTimingEventParams = (category, variable, label, startTime, endTime) => {
|
const createTimingEventParams = (category, variable, label, startTime, endTime) => {
|
||||||
const duration = endTime - startTime;
|
const duration = endTime - startTime;
|
||||||
return {
|
return {
|
||||||
userTimingCategory : category,
|
userTimingCategory : category,
|
||||||
|
@ -24,23 +24,25 @@ const createPublishTimingEventParams = (category, variable, label, startTime, en
|
||||||
};
|
};
|
||||||
|
|
||||||
const sendGoogleAnalyticsEvent = (ip, params) => {
|
const sendGoogleAnalyticsEvent = (ip, params) => {
|
||||||
|
logger.debug('googleId', googleId);
|
||||||
const visitorId = ip.replace(/\./g, '-');
|
const visitorId = ip.replace(/\./g, '-');
|
||||||
const visitor = ua(googleId, visitorId, { strictCidFormat: false, https: true });
|
const visitor = ua(googleId, visitorId, { strictCidFormat: false, https: true });
|
||||||
visitor.event(params, (err) => {
|
visitor.event(params, (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
return logger.error('Google Analytics Event Error >>', err);
|
return logger.error('Google Analytics Event Error >>', err);
|
||||||
}
|
}
|
||||||
logger.debug(`Event successfully sent to google analytics`);
|
logger.debug(`Event successfully sent to google analytics`, params);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const sendGoogleAnalyticsTiming = (visitorId, params) => {
|
const sendGoogleAnalyticsTiming = (siteTitle, params) => {
|
||||||
const visitor = ua(googleId, visitorId, { strictCidFormat: false, https: true });
|
logger.debug('googleId', googleId);
|
||||||
|
const visitor = ua(googleId, siteTitle, { strictCidFormat: false, https: true });
|
||||||
visitor.timing(params, (err) => {
|
visitor.timing(params, (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
return logger.error('Google Analytics Event Error >>', err);
|
return logger.error('Google Analytics Event Error >>', err);
|
||||||
}
|
}
|
||||||
logger.debug(`Timing event successfully sent to google analytics`);
|
logger.debug(`Timing event successfully sent to google analytics`, params);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -50,7 +52,7 @@ const sendGAServeEvent = (headers, ip, originalUrl) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const sendGATimingEvent = (category, variable, label, startTime, endTime) => {
|
const sendGATimingEvent = (category, variable, label, startTime, endTime) => {
|
||||||
const params = createPublishTimingEventParams(category, variable, label, startTime, endTime);
|
const params = createTimingEventParams(category, variable, label, startTime, endTime);
|
||||||
sendGoogleAnalyticsTiming(title, params);
|
sendGoogleAnalyticsTiming(title, params);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue