Browse Source

Add options for API keys and event collection

master
Luke Childs 8 years ago
parent
commit
f5d8165d8b
  1. 20
      src/index.js

20
src/index.js

@ -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);
});
}

Loading…
Cancel
Save