2016-06-07 00:37:09 +00:00
|
|
|
(function () {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
// Create the SendVisitorData service
|
|
|
|
angular
|
|
|
|
.module('forms')
|
|
|
|
.factory('SendVisitorData', SendVisitorData);
|
|
|
|
|
|
|
|
SendVisitorData.$inject = ['Socket', '$state'];
|
|
|
|
|
|
|
|
function SendVisitorData(Socket, $state) {
|
|
|
|
|
|
|
|
// Create a controller method for sending visitor data
|
|
|
|
function send(form, lastActiveIndex, timeElapsed) {
|
|
|
|
|
|
|
|
// Create a new message object
|
|
|
|
var visitorData = {
|
|
|
|
referrer: document.referrer,
|
|
|
|
isSubmitted: form.submitted,
|
|
|
|
formId: form._id,
|
|
|
|
lastActiveField: form.form_fields[lastActiveIndex]._id,
|
|
|
|
timeElapsed: timeElapsed
|
|
|
|
};
|
|
|
|
Socket.emit('form-visitor-data', visitorData);
|
|
|
|
}
|
|
|
|
|
|
|
|
function init(){
|
|
|
|
// Make sure the Socket is connected
|
|
|
|
if (!Socket.socket) {
|
|
|
|
Socket.connect();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var service = {
|
|
|
|
send: send
|
|
|
|
};
|
2016-06-07 02:53:47 +00:00
|
|
|
|
2016-06-07 00:37:09 +00:00
|
|
|
init();
|
|
|
|
return service;
|
|
|
|
|
|
|
|
}
|
|
|
|
}());
|
|
|
|
|