mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-05-22 21:57:03 +00:00
feat(event-tracking): add server-side GA tracking for ecommerce events
This commit is contained in:
parent
ffb42906e1
commit
f7b4a04a59
6 changed files with 15 additions and 3 deletions
|
|
@ -17,5 +17,6 @@
|
|||
"STRIPE_API_KEY":"aaaabbbbccccddddeeeeffff00001111",
|
||||
"STRIPE_PUB_KEY":"22223333444455556666777788889999",
|
||||
"PAYPAL_MERCHANT":"paypal-merchant@gmail.com",
|
||||
"NEW_RELIC_LICENSE_KEY":"NEW_RELIC_LICENSE_KEY"
|
||||
"NEW_RELIC_LICENSE_KEY":"NEW_RELIC_LICENSE_KEY",
|
||||
"GA_ID": "GA_ID"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,7 +48,8 @@
|
|||
"winston": "~0.7.2",
|
||||
"winston-mail": "~0.2.7",
|
||||
"winston-newrelic": "~0.1.4",
|
||||
"domain-middleware": "~0.1.0"
|
||||
"domain-middleware": "~0.1.0",
|
||||
"universal-analytics": "~0.3.2"
|
||||
},
|
||||
"private": true,
|
||||
"subdomain": "habitrpg",
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
||||
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
|
||||
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
|
||||
ga('create', 'UA-33510635-1', 'habitrpg.com');
|
||||
ga('create', window.env.GA_ID, 'habitrpg.com');
|
||||
ga('send', 'pageview');
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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'));
|
||||
};
|
||||
Loading…
Reference in a new issue