added analytics to client side

This commit is contained in:
bill bittner 2017-06-12 19:09:39 -07:00
parent a3f0d0f878
commit 80e33e0ae0
6 changed files with 44 additions and 25 deletions

View file

@ -1,8 +1,11 @@
var fs = require('fs');
var lbryApi = require('../helpers/lbryApi.js');
var config = require('config');
var ua = require('universal-analytics');
var walledAddress = config.get('WalletConfig.lbryAddress');
var googleAnalyticsId = config.get('AnalyticsConfig.googleId');
var visitor = ua(googleAnalyticsId, {https: true});
function handlePublishError(error) {
if (error.code === "ECONNREFUSED"){
@ -44,16 +47,19 @@ module.exports = {
publish: function(name, filepath, license, nsfw, socket) {
// update the client
socket.emit("publish-status", "Your image is being published (this might take a second)...");
visitor.event("Publish", "Publish Request", name, {filepath, license, nsfw}).send();
// create the publish object
var publishParams = createPublishParams(name, filepath, license, nsfw);
// get a promise to publish
lbryApi.publishClaim(publishParams)
.then(function(data){
visitor.event("Publish", "Publish Success", name, {filepath, license, nsfw}).send();
console.log("publish promise success. Tx info:", data)
socket.emit("publish-complete", {name: name, result: data.result});
deleteTemporaryFile(filepath);
})
.catch(function(error){
visitor.event("Publish", "Publish Failure", name, {filepath, license, nsfw}).send();
console.log("error:", error);
socket.emit("publish-failure", handlePublishError(error));
deleteTemporaryFile(filepath);

View file

@ -1,6 +1,5 @@
var path = require('path');
var axios = require('axios');
var lbryApi = require('../helpers/lbryApi.js');
module.exports = function(app){

View file

@ -1,12 +1,17 @@
var path = require('path');
var routeHelpers = require('../helpers/routeHelpers.js');
var lbryApi = require('../helpers/lbryApi.js');
var ua = require('universal-analytics');
var config = require('config');
module.exports = function(app, visitor){
var googleAnalyticsId = config.get('AnalyticsConfig.googleId');
var visitor = ua(googleAnalyticsId, {https: true});
module.exports = function(app){
// route to fetch all free public claims
app.get("/:name/all", function(req, res){
console.log(">> GET request on /" + req.params.name + " (all)");
visitor.pageview(req.url).send();
visitor.event("Claim Request", "Name/all", req.params.name + "/all").send();
// create promise
lbryApi.getAllClaims(req.params.name)
.then(function(orderedFreePublicClaims){
@ -21,7 +26,7 @@ module.exports = function(app, visitor){
});
// route to fetch one free public claim
app.get("/:name/:claim_id", function(req, res){
visitor.event("Claim Request", "Name/ClaimId", req.params.name + "/" + req.params.claim_id).send();
var uri = req.params.name + "#" + req.params.claim_id;
console.log(">> GET request on /" + uri);
// create promise
@ -37,7 +42,7 @@ module.exports = function(app, visitor){
});
// route to fetch one free public claim
app.get("/:name", function(req, res){
visitor.event("Claim Request", "Name", req.params.name).send();
console.log(">> GET request on /" + req.params.name);
// create promise
lbryApi.getClaimBasedOnNameOnly(req.params.name)
@ -51,12 +56,10 @@ module.exports = function(app, visitor){
});
// route for the home page
app.get("/", function(req, res){
visitor.pageview(req.url).send();
res.status(200).render('index');
});
// a catch-all route if someone visits a page that does not exist
app.use("*", function(req, res){
visitor.pageview(req.url).send();
res.status(404).render('fourOhFour');
});
}

View file

@ -1,12 +1,18 @@
var path = require('path');
var siofu = require("socketio-file-upload");
var socketHelpers = require('../helpers/socketHelpers.js');
var ua = require('universal-analytics');
var config = require('config');
var googleAnalyticsId = config.get('AnalyticsConfig.googleId');
var visitor = ua(googleAnalyticsId, {https: true});
module.exports = function(app) {
var http = require('http').Server(app);
var io = require('socket.io')(http);
var path = require('path');
var siofu = require("socketio-file-upload");
var socketHelpers = require('../helpers/socketHelpers.js');
io.on('connection', function(socket){
console.log('a user connected');
console.log('a user connected via sockets');
// attach upload listeners
var uploader = new siofu();
uploader.dir = path.join(__dirname, '../../Uploads');
@ -17,6 +23,7 @@ module.exports = function(app) {
})
uploader.on("saved", function(event){
console.log("saved " + event.file.name);
visitor.event("Publish", "Publish Request", event.file.name).send();
if (event.file.success){
socket.emit("publish-status", "file upload successfully completed");
socketHelpers.publish(event.file.meta.name, event.file.pathName, event.file.meta.license, event.file.meta.nsfw, socket)

View file

@ -4,11 +4,6 @@ var bodyParser = require('body-parser');
var path = require('path');
var siofu = require("socketio-file-upload");
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
var PORT = 3000;
@ -29,11 +24,11 @@ app.engine('handlebars', expressHandlebars({defaultLayout: 'main'}));
app.set('view engine', 'handlebars');
// require express routes
require("./routes/api-routes.js")(app, visitor);
require("./routes/html-routes.js")(app, visitor);
require("./routes/api-routes.js")(app);
require("./routes/html-routes.js")(app);
// wrap the server in socket.io to intercept incoming sockets requests
var http = require("./routes/sockets-routes.js")(app, visitor);
var http = require("./routes/sockets-routes.js")(app);
// start server
http.listen(PORT, function() {

View file

@ -6,16 +6,25 @@
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Spee.ch</title>
<!-- Font Awesome -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.0/css/font-awesome.min.css">
<!-- Bootstrap core CSS -->
<link href="/vendors/MDB/css/bootstrap.min.css" rel="stylesheet">
<!-- Material Design Bootstrap -->
<link href="/vendors/MDB/css/mdb.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.0/css/font-awesome.min.css">
<!-- Bootstrap core CSS -->
<link href="/vendors/MDB/css/bootstrap.min.css" rel="stylesheet">
<!-- Material Design Bootstrap -->
<link href="/vendors/MDB/css/mdb.min.css" rel="stylesheet">
<!-- custom styles -->
<link rel="stylesheet" href="/assets/css/style.css" type="text/css">
</head>
<body>
{{{ body }}}
<!-- google analytics -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(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','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-100747990-1', 'auto');
ga('send', 'pageview');
</script>
<!-- JQuery -->
<script type="text/javascript" src="/vendors/MDB/js/jquery-3.1.1.min.js"></script>
<!-- Bootstrap tooltips -->