tellform/public/modules/forms/directives/analytics-service.client.directive.js

68 lines
1.5 KiB
JavaScript
Raw Normal View History

2016-06-07 00:37:09 +00:00
(function () {
"use strict";
2016-06-07 00:37:09 +00:00
function SendVisitorData() {
2016-06-07 00:37:09 +00:00
// Create a controller method for sending visitor data
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 00:37:09 +00:00
init();
return service;
}
// Create the SendVisitorData service
angular
.module('forms')
.factory('SendVisitorData', SendVisitorData);
SendVisitorData.$inject = [];
2016-06-07 00:37:09 +00:00
}());