fixed analytics fieldValue bug

This commit is contained in:
David Baldwynn 2017-10-07 04:34:01 -04:00
parent 1a155e9ef1
commit 4a816c786d
7 changed files with 399 additions and 308 deletions

View file

@ -12,7 +12,7 @@ var mongoose = require('mongoose'),
module.exports = function (io, socket) {
var visitorsData = {};
var saveVisitorData = function (data, cb){
var saveVisitorData = function (data, socket, cb){
Form.findById(data.formId, function(err, form) {
if (err) {
console.error(err);
@ -32,6 +32,12 @@ module.exports = function (io, socket) {
form.analytics.visitors.push(newVisitor);
request('https://freegeoip.net/json/'+socket.conn.transport.socket._socket.remoteAddress, (error, response, body)=> {
var geoData = body;
data.geoLocation = {
city: geoData.city,
country: geoData.country_name
}
form.save(function (formSaveErr) {
if (err) {
console.error(err);
@ -43,6 +49,7 @@ module.exports = function (io, socket) {
}
});
});
});
};
io.on('connection', function(current_socket) {
@ -54,15 +61,6 @@ module.exports = function (io, socket) {
visitorsData[current_socket.id].ipAddr = current_socket.conn.transport.socket._socket.remoteAddress;
console.log(current_socket);
request('https://freegeoip.net/json/'+current_socket.conn.transport.socket._socket.remoteAddress, (error, response, body)=> {
console.log(body);
var geoData = body;
visitorsData[current_socket.id].geoLocation = {
city: geoData.city,
country: geoData.country_name
}
if (data.isSubmitted && !data.isSaved) {
visitorsData[current_socket.id].isSaved = true;
saveVisitorData(data, function() {
@ -70,7 +68,6 @@ module.exports = function (io, socket) {
});
}
});
});
current_socket.on('disconnect', function() {
var data = visitorsData[current_socket.id];
@ -85,3 +82,4 @@ module.exports = function (io, socket) {
});
});
};

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long