changed functions to consts

This commit is contained in:
bill bittner 2018-06-05 16:24:27 -07:00
parent 7941fc0ac8
commit 3f5b20f5db

View file

@ -2,7 +2,7 @@ const logger = require('winston');
const ua = require('universal-analytics'); const ua = require('universal-analytics');
const { analytics : { googleId }, details: { title } } = require('../../config/siteConfig.js'); const { analytics : { googleId }, details: { title } } = require('../../config/siteConfig.js');
function createServeEventParams (headers, ip, originalUrl) { const createServeEventParams = (headers, ip, originalUrl) => {
return { return {
eventCategory : 'client requests', eventCategory : 'client requests',
eventAction : 'serve request', eventAction : 'serve request',
@ -11,9 +11,9 @@ function createServeEventParams (headers, ip, originalUrl) {
userAgentOverride: headers['user-agent'], userAgentOverride: headers['user-agent'],
documentReferrer : headers['referer'], documentReferrer : headers['referer'],
}; };
} };
function createPublishTimingEventParams (category, variable, label, startTime, endTime) { const createPublishTimingEventParams = (category, variable, label, startTime, endTime) => {
const duration = endTime - startTime; const duration = endTime - startTime;
return { return {
userTimingCategory : category, userTimingCategory : category,
@ -21,43 +21,42 @@ function createPublishTimingEventParams (category, variable, label, startTime, e
userTimingTime : duration, userTimingTime : duration,
userTimingLabel : label, userTimingLabel : label,
}; };
} };
function sendGoogleAnalyticsEvent (ip, params) { const sendGoogleAnalyticsEvent = (ip, params) => {
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) {
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`);
}); });
} };
function sendGoogleAnalyticsTiming (visitorId, params) { const sendGoogleAnalyticsTiming = (visitorId, params) => {
const visitor = ua(googleId, visitorId, { strictCidFormat: false, https: true }); const visitor = ua(googleId, visitorId, { strictCidFormat: false, https: true });
visitor.timing(params, (err) => { visitor.timing(params, (err) => {
if (err) { if (err) {
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`);
}); });
} };
function sendGAServeEvent (headers, ip, originalUrl) { const sendGAServeEvent = (headers, ip, originalUrl) => {
logger.debug('headers:', headers);
const params = createServeEventParams(headers, ip, originalUrl); const params = createServeEventParams(headers, ip, originalUrl);
sendGoogleAnalyticsEvent(ip, params); sendGoogleAnalyticsEvent(ip, params);
} };
function sendGATimingEvent (category, variable, label, startTime, endTime) { const sendGATimingEvent = (category, variable, label, startTime, endTime) => {
const params = createPublishTimingEventParams(category, variable, label, startTime, endTime); const params = createPublishTimingEventParams(category, variable, label, startTime, endTime);
sendGoogleAnalyticsTiming(title, params); sendGoogleAnalyticsTiming(title, params);
} };
function chooseGaLbrynetPublishLabel ({ channel_name: channelName, channel_id: channelId }) { const chooseGaLbrynetPublishLabel = ({ channel_name: channelName, channel_id: channelId }) => {
return (channelName || channelId ? 'PUBLISH_IN_CHANNEL_CLAIM' : 'PUBLISH_ANONYMOUS_CLAIM'); return (channelName || channelId ? 'PUBLISH_IN_CHANNEL_CLAIM' : 'PUBLISH_ANONYMOUS_CLAIM');
} };
module.exports = { module.exports = {
sendGAServeEvent, sendGAServeEvent,