|
|
@ -1,12 +1,17 @@ |
|
|
|
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 |
|
|
|
}); |
|
|
|
|
|
|
|
// Return middleware function
|
|
|
|
return responseTime((req, res, time) => { |
|
|
|
|
|
|
|
// Setup event data
|
|
|
|
const eventData = { |
|
|
@ -87,5 +92,6 @@ module.exports = responseTime((req, res, time) => { |
|
|
|
}); |
|
|
|
|
|
|
|
// Send event data
|
|
|
|
client.recordEvent('analytics', eventData); |
|
|
|
}); |
|
|
|
client.recordEvent(eventCollection, eventData); |
|
|
|
}); |
|
|
|
} |
|
|
|