Permalink
Browse files

added campaign reference tracking for ?ref= to kissmetrics

  • Loading branch information...
1 parent b39fcd1 commit 1a8e04da9b809f48a266db10d3b7d20d3925972b @jexp jexp committed Dec 3, 2013
Showing with 24 additions and 3 deletions.
  1. +22 −1 app.js
  2. +2 −2 package.json
View
23 app.js
@@ -35,11 +35,15 @@ var express = require('express')
, videos = require("./helpers/videos")
, asset = require("./helpers/assets.js").asset
, twitter = require("./helpers/twitter.js")
- , mylog = require("./helpers/log.js");
+ , mylog = require("./helpers/log.js")
+ , kissmetrics = require('kissmymetrics');
+
var content = require("./helpers/content")
, pages = require("./helpers/pages");
+var kmClient = new kissmetrics({ key: process.env.KM_KEY });
+
var app = express();
// data
@@ -233,6 +237,23 @@ app.configure(function () {
res.header('Access-Control-Allow-Methods', 'GET'); // 'PUT, GET, POST, DELETE, OPTIONS');
res.header('Access-Control-Allow-Headers', 'Content-Type');
next();
+ });
+ app.use(function(req, res, next) {
+ var ref=req.query["ref"];
+ if (ref && typeof(kmClient) !== "undefined") {
+ var info = {host: req.host, page: req.path, ip: req.ip, cookies: ""+req.cookies, ref: ref, region:""+res.locals.region};
+ try {
+ kmClient.event(req.ip,"campaign_ref", info,
+ function(err){
+ console.log("Error sending to kissmetrics",err,info);
+ }
+ );
+ console.log("logging campaign_ref to km",ref,info);
+ } catch(err) {
+ console.log("Error sending to kissmetrics",err,info);
+ }
+ }
+ next();
});
app.use(routes.assets);
app.use(express.logger('dev'));
View
@@ -15,12 +15,12 @@
"rssparser" : "0.0.2",
"googleclientlogin" : "0.2.5",
"hooky-spreadsheets" : "0.0.4",
- "rssparser" : "0.0.2",
"soap": "0.2.7",
"marketo-soap-security": "0.0.2",
"express": "3.0.0rc5",
"ejs": "*",
"node-markdown":"0.1.1",
- "vimeo-client":"0.2.0"
+ "vimeo-client":"0.2.0",
+ "kissmymetrics":"0.1.1"
}
}

0 comments on commit 1a8e04d

Please sign in to comment.