feat(event-tracking): add server-side GA tracking for ecommerce events

This commit is contained in:
Tyler Renelle
2014-02-10 11:35:33 -07:00
parent ffb42906e1
commit f7b4a04a59
6 changed files with 15 additions and 3 deletions
+5
View File
@@ -10,6 +10,7 @@ var validator = require('validator');
var check = validator.check;
var sanitize = validator.sanitize;
var User = require('./../models/user').model;
var ga = require('./../utils').ga;
var Group = require('./../models/group').model;
var Challenge = require('./../models/challenge').model;
var logging = require('./../logging');
@@ -294,6 +295,7 @@ api.buyGems = function(req, res, next) {
function(response, cb) {
//user.purchased.ads = true;
if (req.query.plan) {
ga.event('subscribe', 'Stripe').send()
user.purchased.plan = {
planId:'basic_earned',
customerId: response.id,
@@ -302,6 +304,7 @@ api.buyGems = function(req, res, next) {
gemsBought: 0
};
} else {
ga.event('checkout', 'Stripe').send()
user.balance += 5;
}
user.save(cb);
@@ -331,6 +334,7 @@ api.cancelSubscription = function(req, res, next) {
], function(err, saved){
if (err) return res.send(500, err.toString()); // don't json this, let toString() handle errors
res.send(200, saved);
ga.event('unsubscribe', 'Stripe').send()
});
}
@@ -351,6 +355,7 @@ api.buyGemsPaypalIPN = function(req, res, next) {
//user.purchased.ads = true;
user.save();
logging.info('PayPal transaction completed and user updated');
ga.event('checkout', 'PayPal').send()
});
}
});
+1
View File
@@ -234,6 +234,7 @@ module.exports.locals = function(req, res, next) {
NODE_ENV: nconf.get('NODE_ENV'),
BASE_URL: nconf.get('BASE_URL'),
PAYPAL_MERCHANT: nconf.get('PAYPAL_MERCHANT'),
GA_ID: nconf.get("GA_ID"),
IS_MOBILE: /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(req.header('User-Agent')),
STRIPE_PUB_KEY: nconf.get('STRIPE_PUB_KEY'),
getManifestFiles: getManifestFiles,
+4
View File
@@ -3,6 +3,8 @@ var nconf = require('nconf');
var crypto = require('crypto');
var path = require("path");
module.exports.ga = undefined; // set Google Analytics on nconf init
module.exports.sendEmail = function(mailData) {
var smtpTransport = nodemailer.createTransport("SMTP",{
service: nconf.get('SMTP_SERVICE'),
@@ -45,4 +47,6 @@ module.exports.setupConfig = function(){
Error.stackTraceLimit = Infinity;
if (nconf.get('NODE_ENV') === 'production')
require('newrelic');
module.exports.ga = require('universal-analytics')(nconf.get('GA_ID'));
};