diff --git a/controllers/statsController.js b/controllers/statsController.js index 0fdb5083..eabb7cce 100644 --- a/controllers/statsController.js +++ b/controllers/statsController.js @@ -27,26 +27,37 @@ module.exports = { logger.error('sequelize error', error); }); }, - sendGoogleAnalytics (action, ip, originalUrl) { + sendGoogleAnalytics (action, headers, ip, originalUrl) { const visitorId = ip.replace(/\./g, '-'); const visitor = ua(googleApiKey, visitorId, { strictCidFormat: false, https: true }); + logger.verbose('visitor', visitor); + let params; switch (action) { case 'serve': - visitor.event('serve', originalUrl, (err) => { - if (err) { - logger.error('Google Analytics Event Error >>', err); - } - }); + params = { + ec : 'serve', + ea : originalUrl, + uip: ip, + ua : headers['user-agent'], + ul : headers['accept-language'], + }; break; case 'publish': - visitor.event('publish', originalUrl, (err) => { - if (err) { - logger.error('Google Analytics Event Error >>', err); - } - }); + params = { + ec : 'publish', + ea : originalUrl, + uip: ip, + ua : headers['user-agent'], + ul : headers['accept-language'], + }; break; default: break; } + visitor.event(params, (err) => { + if (err) { + logger.error('Google Analytics Event Error >>', err); + } + }); }, getStatsSummary () { logger.debug('retrieving site statistics'); diff --git a/routes/serve-routes.js b/routes/serve-routes.js index f6ecb35a..7cc46c28 100644 --- a/routes/serve-routes.js +++ b/routes/serve-routes.js @@ -32,17 +32,22 @@ function serveFile ({ fileName, fileType, filePath }, res) { res.status(200).sendFile(filePath, options); } -function sendAnalyticsAndLog (ip, originalUrl) { +function sendAnalyticsAndLog (headers, ip, originalUrl) { // google analytics - sendGoogleAnalytics('serve', ip, originalUrl); + sendGoogleAnalytics('serve', headers, ip, originalUrl); // logging logger.verbose(`GET request on ${originalUrl} from ${ip}`); } module.exports = (app) => { // route to fetch one free public claim - app.get('/:name/:claim_id', ({ ip, originalUrl, params }, res) => { - sendAnalyticsAndLog(ip, originalUrl); + app.get('/:name/:claim_id', ({ headers, ip, ips, originalUrl, params }, res) => { + logger.verbose('ip', ip); + logger.verbose('ips', ips); + logger.verbose('headers', headers); + logger.verbose('user-agent', headers['user-agent']); + logger.verbose('accept-language', headers['accept-language']); + sendAnalyticsAndLog(headers, ip, originalUrl); // begin image-serve processes serveController .getClaimByClaimId(params.name, params.claim_id) @@ -60,8 +65,8 @@ module.exports = (app) => { }); }); // route to fetch one free public claim - app.get('/:name', ({ ip, originalUrl, params }, res) => { - sendAnalyticsAndLog(ip, originalUrl); + app.get('/:name', ({ headers, ip, originalUrl, params }, res) => { + sendAnalyticsAndLog(headers, ip, originalUrl); // begin image-serve processes serveController .getClaimByName(params.name)