From d1a219ef03d20ae5304dd47e681441aaa8759813 Mon Sep 17 00:00:00 2001 From: bill bittner Date: Wed, 5 Jul 2017 08:13:01 -0700 Subject: [PATCH 1/4] removed unneeded 'show' analytics --- controllers/statsController.js | 7 ------- routes/home-routes.js | 6 +----- routes/show-routes.js | 18 +++++------------- 3 files changed, 6 insertions(+), 25 deletions(-) diff --git a/controllers/statsController.js b/controllers/statsController.js index 2996afd5..0fdb5083 100644 --- a/controllers/statsController.js +++ b/controllers/statsController.js @@ -38,13 +38,6 @@ module.exports = { } }); break; - case 'show': - visitor.pageview(originalUrl, 'https://spee.ch', 'show route', (err) => { - if (err) { - logger.error('Google Analytics Pageview Error >>', err); - } - }); - break; case 'publish': visitor.event('publish', originalUrl, (err) => { if (err) { diff --git a/routes/home-routes.js b/routes/home-routes.js index f0891a01..c1ace31b 100644 --- a/routes/home-routes.js +++ b/routes/home-routes.js @@ -1,11 +1,9 @@ const logger = require('winston'); -const { postToStats, sendGoogleAnalytics } = require('../controllers/statsController.js'); +const { postToStats } = require('../controllers/statsController.js'); module.exports = app => { // route for the home page app.get('/', ({ headers, ip, originalUrl }, res) => { - // google analytics - sendGoogleAnalytics('serve', ip, originalUrl); // logging logger.verbose(`GET request on ${originalUrl} from ${ip}`); // send response @@ -13,8 +11,6 @@ module.exports = app => { }); // a catch-all route if someone visits a page that does not exist app.use('*', ({ originalUrl, ip }, res) => { - // google analytics - sendGoogleAnalytics('serve', ip, originalUrl); // logging logger.error(`Get request on ${originalUrl} from ${ip} which was a 404`); // post to stats diff --git a/routes/show-routes.js b/routes/show-routes.js index f89e600c..6a791d43 100644 --- a/routes/show-routes.js +++ b/routes/show-routes.js @@ -1,26 +1,18 @@ const logger = require('winston'); const errorHandlers = require('../helpers/libraries/errorHandlers.js'); const { getAllClaims } = require('../controllers/showController.js'); -const { getStatsSummary, postToStats, sendGoogleAnalytics } = require('../controllers/statsController.js'); - -function sendAnalyticsAndLog (ip, originalUrl) { - // google analytics - sendGoogleAnalytics('show', ip, originalUrl); - // logging - logger.verbose(`POST request on ${originalUrl} from ${ip}`); - // get and serve the content -} +const { getStatsSummary, postToStats } = require('../controllers/statsController.js'); module.exports = (app) => { // route to show 'about' page for spee.ch app.get('/about', ({ ip, originalUrl }, res) => { - sendAnalyticsAndLog(ip, originalUrl); + logger.verbose(`POST request on ${originalUrl} from ${ip}`); // get and render the content res.status(200).render('about'); }); // route to show the meme-fodder meme maker app.get('/meme-fodder/play', ({ ip, originalUrl }, res) => { - sendAnalyticsAndLog(ip, originalUrl); + logger.verbose(`POST request on ${originalUrl} from ${ip}`); // get and render the content getAllClaims('meme-fodder') .then(orderedFreePublicClaims => { @@ -33,7 +25,7 @@ module.exports = (app) => { }); // route to show statistics for spee.ch app.get('/stats', ({ ip, originalUrl }, res) => { - sendAnalyticsAndLog(ip, originalUrl); + logger.verbose(`POST request on ${originalUrl} from ${ip}`); // get and render the content getStatsSummary() .then(result => { @@ -46,7 +38,7 @@ module.exports = (app) => { }); // route to display all free public claims at a given name app.get('/:name/all', ({ ip, originalUrl, params }, res) => { - sendAnalyticsAndLog(ip, originalUrl); + logger.verbose(`POST request on ${originalUrl} from ${ip}`); // get and render the content getAllClaims(params.name) .then(orderedFreePublicClaims => { From 5813397219eaae0a5c729c29ce5cb19af4acc069 Mon Sep 17 00:00:00 2001 From: bill bittner Date: Wed, 5 Jul 2017 09:26:22 -0700 Subject: [PATCH 2/4] 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) From c34d8a2cc52183454a322a0de5aff5206329f6fb Mon Sep 17 00:00:00 2001 From: bill bittner Date: Wed, 5 Jul 2017 09:32:43 -0700 Subject: [PATCH 3/4] changed production log level to verbose --- config/production.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/production.json b/config/production.json index 6ea5cdb5..848f1700 100644 --- a/config/production.json +++ b/config/production.json @@ -12,7 +12,7 @@ "PublishUploadPath": "/home/lbry/Downloads/" }, "Logging": { - "LogLevel": "debug", + "LogLevel": "verbose", "LogDirectory": "/home/lbry/Logs" } } From 013069b6868d0da02303a6d7fce7c3f266948af9 Mon Sep 17 00:00:00 2001 From: bill bittner Date: Wed, 5 Jul 2017 09:39:32 -0700 Subject: [PATCH 4/4] updated logging on serves --- routes/serve-routes.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/routes/serve-routes.js b/routes/serve-routes.js index 7cc46c28..d81cc818 100644 --- a/routes/serve-routes.js +++ b/routes/serve-routes.js @@ -33,6 +33,7 @@ function serveFile ({ fileName, fileType, filePath }, res) { } function sendAnalyticsAndLog (headers, ip, originalUrl) { + logger.verbose('headers', headers); // google analytics sendGoogleAnalytics('serve', headers, ip, originalUrl); // logging @@ -41,12 +42,7 @@ function sendAnalyticsAndLog (headers, ip, originalUrl) { module.exports = (app) => { // route to fetch one free public claim - 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']); + app.get('/:name/:claim_id', ({ headers, ip, originalUrl, params }, res) => { sendAnalyticsAndLog(headers, ip, originalUrl); // begin image-serve processes serveController