added more user params
This commit is contained in:
parent
df828a02b5
commit
5813397219
2 changed files with 33 additions and 17 deletions
|
@ -27,26 +27,37 @@ module.exports = {
|
||||||
logger.error('sequelize error', error);
|
logger.error('sequelize error', error);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
sendGoogleAnalytics (action, ip, originalUrl) {
|
sendGoogleAnalytics (action, headers, ip, originalUrl) {
|
||||||
const visitorId = ip.replace(/\./g, '-');
|
const visitorId = ip.replace(/\./g, '-');
|
||||||
const visitor = ua(googleApiKey, visitorId, { strictCidFormat: false, https: true });
|
const visitor = ua(googleApiKey, visitorId, { strictCidFormat: false, https: true });
|
||||||
|
logger.verbose('visitor', visitor);
|
||||||
|
let params;
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case 'serve':
|
case 'serve':
|
||||||
visitor.event('serve', originalUrl, (err) => {
|
params = {
|
||||||
if (err) {
|
ec : 'serve',
|
||||||
logger.error('Google Analytics Event Error >>', err);
|
ea : originalUrl,
|
||||||
}
|
uip: ip,
|
||||||
});
|
ua : headers['user-agent'],
|
||||||
|
ul : headers['accept-language'],
|
||||||
|
};
|
||||||
break;
|
break;
|
||||||
case 'publish':
|
case 'publish':
|
||||||
visitor.event('publish', originalUrl, (err) => {
|
params = {
|
||||||
if (err) {
|
ec : 'publish',
|
||||||
logger.error('Google Analytics Event Error >>', err);
|
ea : originalUrl,
|
||||||
}
|
uip: ip,
|
||||||
});
|
ua : headers['user-agent'],
|
||||||
|
ul : headers['accept-language'],
|
||||||
|
};
|
||||||
break;
|
break;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
|
visitor.event(params, (err) => {
|
||||||
|
if (err) {
|
||||||
|
logger.error('Google Analytics Event Error >>', err);
|
||||||
|
}
|
||||||
|
});
|
||||||
},
|
},
|
||||||
getStatsSummary () {
|
getStatsSummary () {
|
||||||
logger.debug('retrieving site statistics');
|
logger.debug('retrieving site statistics');
|
||||||
|
|
|
@ -32,17 +32,22 @@ function serveFile ({ fileName, fileType, filePath }, res) {
|
||||||
res.status(200).sendFile(filePath, options);
|
res.status(200).sendFile(filePath, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendAnalyticsAndLog (ip, originalUrl) {
|
function sendAnalyticsAndLog (headers, ip, originalUrl) {
|
||||||
// google analytics
|
// google analytics
|
||||||
sendGoogleAnalytics('serve', ip, originalUrl);
|
sendGoogleAnalytics('serve', headers, ip, originalUrl);
|
||||||
// logging
|
// logging
|
||||||
logger.verbose(`GET request on ${originalUrl} from ${ip}`);
|
logger.verbose(`GET request on ${originalUrl} from ${ip}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = (app) => {
|
module.exports = (app) => {
|
||||||
// route to fetch one free public claim
|
// route to fetch one free public claim
|
||||||
app.get('/:name/:claim_id', ({ ip, originalUrl, params }, res) => {
|
app.get('/:name/:claim_id', ({ headers, ip, ips, originalUrl, params }, res) => {
|
||||||
sendAnalyticsAndLog(ip, originalUrl);
|
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
|
// begin image-serve processes
|
||||||
serveController
|
serveController
|
||||||
.getClaimByClaimId(params.name, params.claim_id)
|
.getClaimByClaimId(params.name, params.claim_id)
|
||||||
|
@ -60,8 +65,8 @@ module.exports = (app) => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
// route to fetch one free public claim
|
// route to fetch one free public claim
|
||||||
app.get('/:name', ({ ip, originalUrl, params }, res) => {
|
app.get('/:name', ({ headers, ip, originalUrl, params }, res) => {
|
||||||
sendAnalyticsAndLog(ip, originalUrl);
|
sendAnalyticsAndLog(headers, ip, originalUrl);
|
||||||
// begin image-serve processes
|
// begin image-serve processes
|
||||||
serveController
|
serveController
|
||||||
.getClaimByName(params.name)
|
.getClaimByName(params.name)
|
||||||
|
|
Loading…
Reference in a new issue