Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

mixpanel stats

  • Loading branch information...
commit 1a590f2442eb1f2a188736059d83bd45e1cae7ab 1 parent 873667c
@wadey wadey authored
Showing with 29 additions and 1 deletion.
  1. +16 −0 app.js
  2. +2 −1  package.json
  3. +11 −0 routes/index.js
View
16 app.js
@@ -8,8 +8,14 @@ if (!process.env.MASHAPE_API_KEY || !process.env.MASHAPE_API_SECRET) {
var express = require('express')
, routes = require('./routes')
+ , Mixpanel = require('mixpanel')
var app = module.exports = express.createServer();
+var mixpanel;
+
+if (process.env.MIXPANEL) {
+ mixpanel = Mixpanel.init(process.env.MIXPANEL)
+}
// Configuration
@@ -18,6 +24,16 @@ app.configure(function(){
app.set('view engine', 'jade');
app.use(express.bodyParser());
app.use(express.methodOverride());
+ app.use(function(req, res, next) {
+ if (mixpanel) {
+ req.metrics = mixpanel
+ } else {
+ req.metrics = {
+ track: function() {}
+ }
+ }
+ next()
+ });
app.use(app.router);
app.use(express.static(__dirname + '/public'));
});
View
3  package.json
@@ -11,6 +11,7 @@
"async": "~0.1.12",
"coffee-script": "~1.1.2",
"lru-cache": "~1.0.4",
- "opencv": "git://github.com/peterbraden/node-opencv.git"
+ "opencv": "git://github.com/botriot/node-opencv.git",
+ "mixpanel": "0.0.6"
}
}
View
11 routes/index.js
@@ -10,6 +10,12 @@ exports.img = function(req, res, next) {
overlay: req.param('overlay', 'mustache'),
method: req.param('method', 'cv')
}
+ req.metrics.track('img', {
+ ip: req.headers['x-real-ip'],
+ image: data.image,
+ overlay: data.overlay,
+ method: data.method
+ })
image.mash(data, function(err, image) {
if (err) {
@@ -29,6 +35,11 @@ exports.check = function(req, res, next) {
overlay: req.param('overlay', 'mustache'),
method: req.param('method', 'cv')
}
+ req.metrics.track('check', {
+ ip: req.headers['x-real-ip'],
+ image: data.image,
+ method: data.method
+ })
image.mash(data, function(err, image) {
if (err) {
Please sign in to comment.
Something went wrong with that request. Please try again.