added analytics dashboard
This commit is contained in:
parent
26b2fafc3d
commit
afeb7aaf2a
|
@ -48,8 +48,7 @@ var ButtonSchema = new Schema({
|
||||||
|
|
||||||
var VisitorDataSchema = new Schema({
|
var VisitorDataSchema = new Schema({
|
||||||
referrer: {
|
referrer: {
|
||||||
type: String,
|
type: String
|
||||||
required: true
|
|
||||||
},
|
},
|
||||||
lastActiveField: {
|
lastActiveField: {
|
||||||
type: Schema.Types.ObjectId
|
type: Schema.Types.ObjectId
|
||||||
|
@ -72,8 +71,7 @@ var VisitorDataSchema = new Schema({
|
||||||
deviceType: {
|
deviceType: {
|
||||||
type: String,
|
type: String,
|
||||||
enum: ['desktop', 'phone', 'tablet', 'other'],
|
enum: ['desktop', 'phone', 'tablet', 'other'],
|
||||||
default: 'other',
|
default: 'other'
|
||||||
required: true
|
|
||||||
},
|
},
|
||||||
userAgent: {
|
userAgent: {
|
||||||
type: String
|
type: String
|
||||||
|
|
|
@ -25,7 +25,10 @@ module.exports = function (io, socket) {
|
||||||
referrer: data.referrer,
|
referrer: data.referrer,
|
||||||
lastActiveField: data.lastActiveField,
|
lastActiveField: data.lastActiveField,
|
||||||
timeElapsed: data.timeElapsed,
|
timeElapsed: data.timeElapsed,
|
||||||
isSubmitted: data.isSubmitted
|
isSubmitted: data.isSubmitted,
|
||||||
|
language: data.language,
|
||||||
|
ipAddr: data.ipAddr,
|
||||||
|
deviceType: data.deviceType
|
||||||
};
|
};
|
||||||
|
|
||||||
form.analytics.visitors.push(newVisitor);
|
form.analytics.visitors.push(newVisitor);
|
||||||
|
|
|
@ -85,11 +85,11 @@ angular.module('forms').directive('editSubmissionsFormDirective', ['$rootScope',
|
||||||
stats[deviceType].visits++;
|
stats[deviceType].visits++;
|
||||||
|
|
||||||
stats[deviceType].total_time =+ visitor.timeElapsed;
|
stats[deviceType].total_time =+ visitor.timeElapsed;
|
||||||
stats[deviceType].average_time = stats[deviceType].total_time/stats[deviceType].visits;
|
stats[deviceType].average_time = stats[deviceType].total_time/stats[deviceType].visits || 0;
|
||||||
|
|
||||||
if(stats[deviceType].isSubmitted) stats[deviceType].responses++;
|
if(visitor.isSubmitted) stats[deviceType].responses++;
|
||||||
|
|
||||||
stats[deviceType].completion = stats[deviceType].response/stats[deviceType].visits;
|
stats[deviceType].completion = stats[deviceType].response/stats[deviceType].visits || 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(stats);
|
console.log(stats);
|
||||||
|
|
|
@ -8,10 +8,10 @@
|
||||||
|
|
||||||
SendVisitorData.$inject = ['Socket', '$state', '$http', 'deviceDetector'];
|
SendVisitorData.$inject = ['Socket', '$state', '$http', 'deviceDetector'];
|
||||||
|
|
||||||
function SendVisitorData(Socket, $state, $http) {
|
function SendVisitorData(Socket, $state, $http, deviceDetector) {
|
||||||
|
|
||||||
// Create a controller method for sending visitor data
|
// Create a controller method for sending visitor data
|
||||||
function send(form, lastActiveIndex, timeElapsed, deviceDetector) {
|
function send(form, lastActiveIndex, timeElapsed) {
|
||||||
// Create a new message object
|
// Create a new message object
|
||||||
var visitorData = {
|
var visitorData = {
|
||||||
referrer: document.referrer,
|
referrer: document.referrer,
|
||||||
|
@ -20,15 +20,17 @@
|
||||||
lastActiveField: form.form_fields[lastActiveIndex]._id,
|
lastActiveField: form.form_fields[lastActiveIndex]._id,
|
||||||
timeElapsed: timeElapsed,
|
timeElapsed: timeElapsed,
|
||||||
//@TODO @FIXME: David: Need to make this get the language from the HTTP Header instead
|
//@TODO @FIXME: David: Need to make this get the language from the HTTP Header instead
|
||||||
language: window.navigator.userLanguage || window.navigator.language
|
language: window.navigator.userLanguage || window.navigator.language,
|
||||||
|
ipAddr: '',
|
||||||
|
deviceType: ''
|
||||||
};
|
};
|
||||||
|
|
||||||
$http.get('http://jsonip.com/').success(function(response) {
|
$http.get('http://jsonip.com/').success(function(response) {
|
||||||
visitorData.ipAddr = response['ip']+'';
|
visitorData.ipAddr = response['ip']+'';
|
||||||
}).error(function(error) {
|
}).error(function(error) {
|
||||||
console.error('Could not get users\'s ip');
|
console.error('Could not get users\'s ip');
|
||||||
visitorData.ipAddr = '';
|
}).then(function(){
|
||||||
}).finally(function(){
|
|
||||||
visitorData.userAgent = deviceDetector.raw;
|
visitorData.userAgent = deviceDetector.raw;
|
||||||
|
|
||||||
if(deviceDetector.isTablet()) {
|
if(deviceDetector.isTablet()) {
|
||||||
|
@ -38,8 +40,8 @@
|
||||||
}else {
|
}else {
|
||||||
visitorData.deviceType = 'desktop';
|
visitorData.deviceType = 'desktop';
|
||||||
}
|
}
|
||||||
|
console.log(visitorData.deviceType);
|
||||||
Socket.emit('form-visitor-data', visitorData);
|
Socket.emit('form-visitor-data', visitorData);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue