added google analytics

This commit is contained in:
bill bittner 2017-06-12 15:57:14 -07:00
parent 92786795d2
commit a3f0d0f878
4 changed files with 18 additions and 11 deletions

View file

@ -1,6 +1,7 @@
var fs = require('fs'); var fs = require('fs');
var lbryApi = require('../helpers/lbryApi.js'); var lbryApi = require('../helpers/lbryApi.js');
var config = require('config'); var config = require('config');
var walledAddress = config.get('WalletConfig.lbryAddress'); var walledAddress = config.get('WalletConfig.lbryAddress');
function handlePublishError(error) { function handlePublishError(error) {

View file

@ -30,6 +30,7 @@
"express-handlebars": "^3.0.0", "express-handlebars": "^3.0.0",
"nodemon": "^1.11.0", "nodemon": "^1.11.0",
"socket.io": "^2.0.1", "socket.io": "^2.0.1",
"socketio-file-upload": "^0.6.0" "socketio-file-upload": "^0.6.0",
"universal-analytics": "^0.4.13"
} }
} }

View file

@ -2,15 +2,11 @@ var path = require('path');
var routeHelpers = require('../helpers/routeHelpers.js'); var routeHelpers = require('../helpers/routeHelpers.js');
var lbryApi = require('../helpers/lbryApi.js'); var lbryApi = require('../helpers/lbryApi.js');
module.exports = function(app){ module.exports = function(app, visitor){
// route for favicon // route to fetch all free public claims
// app.get("/favicon.ico", function(req, res){
// console.log(" >> GET request on favicon.ico");
// res.sendFile(path.join(__dirname, '../public/assets/img', 'favicon.ico'));
// });
// route to fetch one free public claim
app.get("/:name/all", function(req, res){ app.get("/:name/all", function(req, res){
console.log(">> GET request on /" + req.params.name + " (all)"); console.log(">> GET request on /" + req.params.name + " (all)");
visitor.pageview(req.url).send();
// create promise // create promise
lbryApi.getAllClaims(req.params.name) lbryApi.getAllClaims(req.params.name)
.then(function(orderedFreePublicClaims){ .then(function(orderedFreePublicClaims){
@ -25,6 +21,7 @@ module.exports = function(app){
}); });
// route to fetch one free public claim // route to fetch one free public claim
app.get("/:name/:claim_id", function(req, res){ app.get("/:name/:claim_id", function(req, res){
var uri = req.params.name + "#" + req.params.claim_id; var uri = req.params.name + "#" + req.params.claim_id;
console.log(">> GET request on /" + uri); console.log(">> GET request on /" + uri);
// create promise // create promise
@ -40,6 +37,7 @@ module.exports = function(app){
}); });
// route to fetch one free public claim // route to fetch one free public claim
app.get("/:name", function(req, res){ app.get("/:name", function(req, res){
console.log(">> GET request on /" + req.params.name); console.log(">> GET request on /" + req.params.name);
// create promise // create promise
lbryApi.getClaimBasedOnNameOnly(req.params.name) lbryApi.getClaimBasedOnNameOnly(req.params.name)
@ -53,10 +51,12 @@ module.exports = function(app){
}); });
// route for the home page // route for the home page
app.get("/", function(req, res){ app.get("/", function(req, res){
visitor.pageview(req.url).send();
res.status(200).render('index'); res.status(200).render('index');
}); });
// a catch-all route if someone visits a page that does not exist // a catch-all route if someone visits a page that does not exist
app.use("*", function(req, res){ app.use("*", function(req, res){
visitor.pageview(req.url).send();
res.status(404).render('fourOhFour'); res.status(404).render('fourOhFour');
}); });
} }

View file

@ -4,6 +4,11 @@ var bodyParser = require('body-parser');
var path = require('path'); var path = require('path');
var siofu = require("socketio-file-upload"); var siofu = require("socketio-file-upload");
var expressHandlebars = require("express-handlebars"); var expressHandlebars = require("express-handlebars");
var ua = require('universal-analytics');
var config = require('config');
var googleAnalyticsId = config.get('AnalyticsConfig.googleId');
var visitor = ua(googleAnalyticsId, {https: true});
// set port // set port
var PORT = 3000; var PORT = 3000;
@ -24,11 +29,11 @@ app.engine('handlebars', expressHandlebars({defaultLayout: 'main'}));
app.set('view engine', 'handlebars'); app.set('view engine', 'handlebars');
// require express routes // require express routes
require("./routes/api-routes.js")(app); require("./routes/api-routes.js")(app, visitor);
require("./routes/html-routes.js")(app); require("./routes/html-routes.js")(app, visitor);
// wrap the server in socket.io to intercept incoming sockets requests // wrap the server in socket.io to intercept incoming sockets requests
var http = require("./routes/sockets-routes.js")(app); var http = require("./routes/sockets-routes.js")(app, visitor);
// start server // start server
http.listen(PORT, function() { http.listen(PORT, function() {