From 5813397219eaae0a5c729c29ce5cb19af4acc069 Mon Sep 17 00:00:00 2001 From: bill bittner Date: Wed, 5 Jul 2017 09:26:22 -0700 Subject: [PATCH] added more user params --- controllers/statsController.js | 33 ++++++++++++++++++++++----------- routes/serve-routes.js | 17 +++++++++++------ 2 files changed, 33 insertions(+), 17 deletions(-) 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)