Merge pull request #182 from EverythingMe/feature_events_throtle

Make sure events are reported at most once per second
This commit is contained in:
Arik Fraimovich 2014-04-22 16:40:34 +03:00
commit d26b822f6c
2 changed files with 15 additions and 1 deletions

View File

@ -69,6 +69,9 @@
}; };
// TODO: fire event for query view for each query // TODO: fire event for query view for each query
Events.record(currentUser, "view", "widget", $scope.widget.id);
Events.record(currentUser, "view", "query", $scope.widget.visualization.query.id);
Events.record(currentUser, "view", "visualization", $scope.widget.visualization.id);
$scope.query = new Query($scope.widget.visualization.query); $scope.query = new Query($scope.widget.visualization.query);
$scope.queryResult = $scope.query.getQueryResult(); $scope.queryResult = $scope.query.getQueryResult();

View File

@ -20,6 +20,16 @@
} }
function Events($http) { function Events($http) {
this.events = [];
this.post = _.debounce(function() {
var events = this.events;
this.events = [];
$http.post('/api/events', events);
}, 1000);
this.record = function (user, action, object_type, object_id, additional_properties) { this.record = function (user, action, object_type, object_id, additional_properties) {
var event = { var event = {
@ -30,8 +40,9 @@
"timestamp": Date.now()/1000.0 "timestamp": Date.now()/1000.0
}; };
_.extend(event, additional_properties); _.extend(event, additional_properties);
this.events.push(event);
$http.post('/api/events', [event]); this.post();
}; };
} }