2016-06-07 00:37:09 +00:00
|
|
|
(function () {
|
2017-04-21 04:38:37 +00:00
|
|
|
"use strict";
|
2016-06-07 00:37:09 +00:00
|
|
|
|
2017-04-21 06:09:40 +00:00
|
|
|
function SendVisitorData(Socket, $state) {
|
2016-06-07 00:37:09 +00:00
|
|
|
|
|
|
|
// Create a controller method for sending visitor data
|
2017-04-21 06:09:40 +00:00
|
|
|
function send(form, lastActiveIndex) {
|
2016-06-07 00:37:09 +00:00
|
|
|
// Create a new message object
|
2016-11-02 19:35:01 +00:00
|
|
|
/*var visitorData = {
|
2016-06-07 00:37:09 +00:00
|
|
|
referrer: document.referrer,
|
|
|
|
isSubmitted: form.submitted,
|
|
|
|
formId: form._id,
|
|
|
|
lastActiveField: form.form_fields[lastActiveIndex]._id,
|
2016-06-17 21:33:33 +00:00
|
|
|
timeElapsed: timeElapsed,
|
|
|
|
//@TODO @FIXME: David: Need to make this get the language from the HTTP Header instead
|
2016-06-17 21:51:17 +00:00
|
|
|
language: window.navigator.userLanguage || window.navigator.language,
|
|
|
|
ipAddr: '',
|
|
|
|
deviceType: ''
|
2016-06-07 00:37:09 +00:00
|
|
|
};
|
2016-06-17 21:33:33 +00:00
|
|
|
|
2016-06-21 07:49:21 +00:00
|
|
|
$http.get('https://jsonip.com/').success(function(response) {
|
2016-06-17 21:33:33 +00:00
|
|
|
visitorData.ipAddr = response['ip']+'';
|
|
|
|
}).error(function(error) {
|
|
|
|
console.error('Could not get users\'s ip');
|
2016-06-17 21:51:17 +00:00
|
|
|
}).then(function(){
|
|
|
|
|
2016-06-17 21:33:33 +00:00
|
|
|
visitorData.userAgent = deviceDetector.raw;
|
|
|
|
|
|
|
|
if(deviceDetector.isTablet()) {
|
|
|
|
visitorData.deviceType = 'tablet';
|
|
|
|
}else if(deviceDetector.isMobile()){
|
|
|
|
visitorData.deviceType = 'phone';
|
|
|
|
}else {
|
|
|
|
visitorData.deviceType = 'desktop';
|
|
|
|
}
|
2016-06-17 21:51:17 +00:00
|
|
|
console.log(visitorData.deviceType);
|
2016-06-17 21:33:33 +00:00
|
|
|
Socket.emit('form-visitor-data', visitorData);
|
2016-11-02 19:35:01 +00:00
|
|
|
});*/
|
2016-06-17 21:33:33 +00:00
|
|
|
|
2016-06-07 00:37:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function init(){
|
|
|
|
// Make sure the Socket is connected
|
2016-11-02 19:35:01 +00:00
|
|
|
/*if (!Socket.socket) {
|
2016-06-07 00:37:09 +00:00
|
|
|
Socket.connect();
|
2016-11-02 19:35:01 +00:00
|
|
|
}*/
|
2016-06-07 00:37:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var service = {
|
|
|
|
send: send
|
|
|
|
};
|
2016-06-07 02:53:47 +00:00
|
|
|
|
2016-06-07 00:37:09 +00:00
|
|
|
init();
|
|
|
|
return service;
|
|
|
|
|
|
|
|
}
|
2017-04-21 04:38:37 +00:00
|
|
|
|
|
|
|
// Create the SendVisitorData service
|
|
|
|
angular
|
|
|
|
.module('forms')
|
|
|
|
.factory('SendVisitorData', SendVisitorData);
|
|
|
|
|
|
|
|
SendVisitorData.$inject = ['Socket', '$state', '$http'];
|
|
|
|
|
|
|
|
|
2016-06-07 00:37:09 +00:00
|
|
|
}());
|
|
|
|
|