Skip to content

Instantly share code, notes, and snippets.

@weilandia
Last active November 28, 2017 04:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save weilandia/745b20836a2423074e737974d077dfd6 to your computer and use it in GitHub Desktop.
Save weilandia/745b20836a2423074e737974d077dfd6 to your computer and use it in GitHub Desktop.
const serverless = require('serverless-http');
const Mixpanel = require('mixpanel');
const mixpanel = Mixpanel.init(process.env.MIXPANEL_TOKEN);
function handler(event, context, callback) {
let body = JSON.parse(event.body);
let eventsTracked = 0;
body.forEach((sendGridEvent) => {
mixpanel.track('SendGrid: ' + sendGridEvent.event, sendGridEvent);
eventsTracked += 1;
});
const response = {
statusCode: 200,
eventsTracked: eventsTracked
};
callback(null, response);
}
module.exports.mixpanel = mixpanel;
module.exports.handler = handler;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment