Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

anonlytics-express

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

anonlytics-express - npm Package Compare versions

Comparing version 0.1.1 to 0.2.0

2

package.json
{
"name": "anonlytics-express",
"version": "0.1.1",
"version": "0.2.0",
"description": "Privacy respecting analytics for express apps",

@@ -5,0 +5,0 @@ "main": "src/index.js",

const KeenTracking = require('keen-tracking');
const responseTime = require('response-time');
const client = new KeenTracking({
projectId: process.env.KEEN_PROJECT_ID,
writeKey: process.env.KEEN_WRITE_KEY
});
module.exports = (options = {}) => {
module.exports = responseTime((req, res, time) => {
// Setup options
const eventCollection = options.eventCollection || 'anonlytics';
const client = new KeenTracking({
projectId: options.keenProjectId || process.env.KEEN_PROJECT_ID,
writeKey: options.keenWriteKey || process.env.KEEN_WRITE_KEY
});
// Setup event data
const eventData = {
http: {
method: req.method,
statusCode: res.statusCode
},
responseTime: time,
url: {
string: `${req.protocol}://${req.headers.host}${req.originalUrl}`
},
ip: req.ip.substr(0, 7) == '::ffff:' ? req.ip.substr(7) : req.ip,
userAgent: {
string: req.headers['user-agent']
},
referrer: {
url: req.headers.referer
},
express: {
route: req.route && req.route.path
}
};
// Return middleware function
return responseTime((req, res, time) => {
// Enable keen date time addon
eventData.keen = {
addons: [
// Setup event data
const eventData = {
http: {
method: req.method,
statusCode: res.statusCode
},
responseTime: time,
url: {
string: `${req.protocol}://${req.headers.host}${req.originalUrl}`
},
ip: req.ip.substr(0, 7) == '::ffff:' ? req.ip.substr(7) : req.ip,
userAgent: {
string: req.headers['user-agent']
},
referrer: {
url: req.headers.referer
},
express: {
route: req.route && req.route.path
}
};
// Enable keen date time addon
eventData.keen = {
addons: [
{
name: 'keen:date_time_parser',
input: {
date_time: 'keen.timestamp',
},
output: 'timestamp_info'
}
]
};
// Only enable other keen addons if we have the required input
const keenAddons = [
{
name: 'keen:date_time_parser',
name: 'keen:url_parser',
input: {
date_time: 'keen.timestamp',
url: 'url.string'
},
output: 'timestamp_info'
}
]
};
// Only enable other keen addons if we have the required input
const keenAddons = [
{
name: 'keen:url_parser',
input: {
url: 'url.string'
output: 'url.components'
},
output: 'url.components'
},
{
name: 'keen:ip_to_geo',
input: {
ip: 'ip'
{
name: 'keen:ip_to_geo',
input: {
ip: 'ip'
},
output: 'location'
},
output: 'location'
},
{
name: 'keen:ua_parser',
input: {
ua_string: 'userAgent.string'
{
name: 'keen:ua_parser',
input: {
ua_string: 'userAgent.string'
},
output: 'userAgent.info'
},
output: 'userAgent.info'
},
{
name: 'keen:referrer_parser',
input: {
referrer_url: 'referrer.url',
page_url: 'url.string'
},
output: 'referrer.info'
}
];
keenAddons.forEach(addon => {
const hasRequiredProperties = Object
.keys(addon.input)
.map(key => addon.input[key])
.every(requiredProp => requiredProp.split('.').reduce((obj, i) => obj[i], eventData));
{
name: 'keen:referrer_parser',
input: {
referrer_url: 'referrer.url',
page_url: 'url.string'
},
output: 'referrer.info'
}
];
keenAddons.forEach(addon => {
const hasRequiredProperties = Object
.keys(addon.input)
.map(key => addon.input[key])
.every(requiredProp => requiredProp.split('.').reduce((obj, i) => obj[i], eventData));
if(hasRequiredProperties) {
eventData.keen.addons.push(addon);
}
if(hasRequiredProperties) {
eventData.keen.addons.push(addon);
}
});
// Send event data
client.recordEvent(eventCollection, eventData);
});
// Send event data
client.recordEvent('analytics', eventData);
});
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc