moved ip lookups to backend

This commit is contained in:
David Baldwynn 2017-10-07 01:23:42 -07:00
parent e620769d32
commit 6a4dcb0874
4 changed files with 34 additions and 24 deletions

View File

@ -5,7 +5,8 @@
*/
var mongoose = require('mongoose'),
errorHandler = require('../controllers/errors.server.controller'),
Form = mongoose.model('Form');
Form = mongoose.model('Form'),
request = require('request');
// Create the chat configuration
module.exports = function (io, socket) {
@ -50,12 +51,25 @@ module.exports = function (io, socket) {
visitorsData[current_socket.id] = data;
visitorsData[current_socket.id].socketId = current_socket.id;
visitorsData[current_socket.id].isSaved = false;
if (data.isSubmitted && !data.isSaved) {
visitorsData[current_socket.id].isSaved = true;
saveVisitorData(data, function() {
current_socket.disconnect(true);
});
}
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() {
current_socket.disconnect(true);
});
}
});
});
current_socket.on('disconnect', function() {

View File

@ -94,6 +94,7 @@
"prerender-node": "^2.2.1",
"random-js": "^1.0.8",
"raven": "^0.9.0",
"request": "^2.83.0",
"socket.io": "^1.4.6",
"socket.io-redis": "^1.0.0",
"swig": "~1.4.1",

View File

@ -196,6 +196,16 @@ angular.module('view-form').directive('submitFormDirective', ['$http', 'TimeCoun
}
};
$scope.$watch('selected.index', function(oldValue, newValue){
if(oldValue !== newValue && newValue < $scope.myform.form_fields.length){
//Only send analytics data if form has not been submitted
if(!$scope.myform.submitted){
console.log('SendVisitorData.send()');
SendVisitorData.send($scope.myform, newValue, TimeCounter.getTimeElapsed());
}
}
});
//Fire event when window is scrolled
$window.onscroll = function(){
if(!NOSCROLL){

View File

@ -28,18 +28,6 @@
deviceType = 'desktop';
}
$.ajaxSetup( { 'async': false } );
var geoData = $.getJSON('https://freegeoip.net/json/').responseJSON;
$.ajaxSetup( { 'async': true } );
if(!geoData){
geoData = {
ip: '',
city: '',
country_name: ''
};
}
// Create a new message object
var visitorData = {
referrer: document.referrer,
@ -49,11 +37,8 @@
timeElapsed: timeElapsed,
language: lang,
deviceType: deviceType,
ipAddr: geoData.ip,
geoLocation: {
city: geoData.city,
country: geoData.country_name
}
ipAddr: null,
geoLocation: null
};
Socket.emit('form-visitor-data', visitorData);