fixed analytics time elapsed bug

This commit is contained in:
David Baldwynn 2017-03-06 12:53:31 -08:00
parent 878c6a38b5
commit f62ecba90f
No known key found for this signature in database
GPG key ID: 15D1C13202224A9B
5 changed files with 12 additions and 8 deletions

View file

@ -1,6 +1,5 @@
'use strict'; 'use strict';
/** /**
* Module dependencies. * Module dependencies.
*/ */
@ -30,7 +29,7 @@ module.exports = function (io, socket) {
ipAddr: data.ipAddr, ipAddr: data.ipAddr,
deviceType: data.deviceType deviceType: data.deviceType
}; };
console.log(newVisitor);
form.analytics.visitors.push(newVisitor); form.analytics.visitors.push(newVisitor);

View file

@ -47,6 +47,7 @@ angular.module('view-form').directive('submitFormDirective', ['$http', 'TimeCoun
controller: function($document, $window, $scope){ controller: function($document, $window, $scope){
$scope.noscroll = false; $scope.noscroll = false;
$scope.forms = {}; $scope.forms = {};
TimeCounter.restartClock();
var form_fields_count = $scope.myform.visible_form_fields.filter(function(field){ var form_fields_count = $scope.myform.visible_form_fields.filter(function(field){
if(field.fieldType === 'statement' || field.fieldType === 'rating'){ if(field.fieldType === 'statement' || field.fieldType === 'rating'){
@ -79,7 +80,6 @@ angular.module('view-form').directive('submitFormDirective', ['$http', 'TimeCoun
}; };
$scope.setActiveField($scope.myform.visible_form_fields[0]._id, 0, false); $scope.setActiveField($scope.myform.visible_form_fields[0]._id, 0, false);
//console.log($scope.selected);
//Reset Timer //Reset Timer
TimeCounter.restartClock(); TimeCounter.restartClock();
}; };
@ -260,6 +260,8 @@ angular.module('view-form').directive('submitFormDirective', ['$http', 'TimeCoun
}); });
} }
console.log("time elapsed: ");
console.log(TimeCounter.getTimeElapsed());
SendVisitorData.send($scope.myform, getActiveField(), TimeCounter.getTimeElapsed()); SendVisitorData.send($scope.myform, getActiveField(), TimeCounter.getTimeElapsed());
}; };

View file

@ -29,9 +29,9 @@
} }
$.ajaxSetup( { "async": false } ); $.ajaxSetup( { "async": false } );
var geoData = $.getJSON('//freegeoip.net/json/?callback=?'); var geoData = $.getJSON('//freegeoip.net/json/').responseJSON;
$.ajaxSetup( { "async": true } ); $.ajaxSetup( { "async": true } );
// Create a new message object // Create a new message object
var visitorData = { var visitorData = {
referrer: document.referrer, referrer: document.referrer,
@ -43,6 +43,7 @@
deviceType: deviceType, deviceType: deviceType,
ipAddr: geoData.ip ipAddr: geoData.ip
}; };
console.log('sent form-visitor-data');
Socket.emit('form-visitor-data', visitorData); Socket.emit('form-visitor-data', visitorData);
} }

View file

@ -48,7 +48,7 @@ angular.module('forms').directive('editSubmissionsFormDirective', ['$rootScope',
$scope.AverageTimeElapsed = (function(){ $scope.AverageTimeElapsed = (function(){
var totalTime = 0; var totalTime = 0;
var numSubmissions = $scope.table.rows.length; var numSubmissions = $scope.table.rows.length;
for(var i=0; i<$scope.table.rows.length; i++){ for(var i=0; i<$scope.table.rows.length; i++){
totalTime += $scope.table.rows[i].timeElapsed; totalTime += $scope.table.rows[i].timeElapsed;
} }
@ -89,6 +89,8 @@ angular.module('forms').directive('editSubmissionsFormDirective', ['$rootScope',
stats[deviceType].completion = stats[deviceType].response / stats[deviceType].visits || 0; stats[deviceType].completion = stats[deviceType].response / stats[deviceType].visits || 0;
} }
console.log("stats");
console.log(stats);
} }
return stats; return stats;

View file

@ -145,7 +145,7 @@ angular.module('forms').directive('submitFormDirective', ['$http', 'TimeCounter'
}); });
}); });
}); });
}else { } else {
setTimeout(function() { setTimeout(function() {
if (document.querySelectorAll('.activeField .focusOn')[0]) { if (document.querySelectorAll('.activeField .focusOn')[0]) {
//FIXME: DAVID: Figure out how to set focus without scroll movement in HTML Dom //FIXME: DAVID: Figure out how to set focus without scroll movement in HTML Dom
@ -156,6 +156,7 @@ angular.module('forms').directive('submitFormDirective', ['$http', 'TimeCounter'
}); });
} }
SendVisitorData.send($scope.myform, getActiveField(), TimeCounter.getTimeElapsed()); SendVisitorData.send($scope.myform, getActiveField(), TimeCounter.getTimeElapsed());
}; };
@ -219,7 +220,6 @@ angular.module('forms').directive('submitFormDirective', ['$http', 'TimeCounter'
setTimeout(function () { setTimeout(function () {
$scope.submitPromise = $http.post('/forms/' + $scope.myform._id, form) $scope.submitPromise = $http.post('/forms/' + $scope.myform._id, form)
.success(function (data, status, headers) { .success(function (data, status, headers) {
console.log($scope.myform.form_fields[0]);
$scope.myform.submitted = true; $scope.myform.submitted = true;
$scope.loading = false; $scope.loading = false;
SendVisitorData.send($scope.myform, getActiveField(), _timeElapsed); SendVisitorData.send($scope.myform, getActiveField(), _timeElapsed);