-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add a new factory for the client stats - Use it to define client time, event and error methods - Log a stat every time we switch tabs (example of client_time) - Log errors in the tab switching (example of client_error) - Log when we forced sync (example of client_nav_event) - Add the new factory to index.html! Related usercache code is e-mission/cordova-usercache@67ae0c9 server code is e-mission/e-mission-server@7487c82
- Loading branch information
Showing
4 changed files
with
98 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
'use strict'; | ||
|
||
angular.module('emission.stats.clientstats', []) | ||
|
||
.factory('ClientStats', function($window) { | ||
var clientStat = {}; | ||
|
||
clientStat.CLIENT_TIME = "stats/client_time"; | ||
clientStat.CLIENT_ERROR = "stats/client_error"; | ||
clientStat.CLIENT_NAV_EVENT = "stats/client_nav_event"; | ||
|
||
clientStat.getStatKeys = function() { | ||
return { | ||
STATE_CHANGED: "state_changed", | ||
BUTTON_FORCE_SYNC: "button_sync_forced" | ||
}; | ||
} | ||
|
||
clientStat.getDB = function() { | ||
if (angular.isDefined($window) && angular.isDefined($window.cordova) && | ||
angular.isDefined($window.cordova.plugins)) { | ||
return $window.cordova.plugins.BEMUserCache; | ||
} else { | ||
return; // undefined | ||
} | ||
} | ||
|
||
clientStat.getAppVersion = function() { | ||
if (angular.isDefined(clientStat.appVersion)) { | ||
return clientStat.appVersion; | ||
} else { | ||
if (angular.isDefined($window) && angular.isDefined($window.cordova) && | ||
angular.isDefined($window.cordova.getAppVersion)) { | ||
$window.cordova.getAppVersion.getVersionNumber().then(function(version) { | ||
clientStat.appVersion = version; | ||
}); | ||
} | ||
return; | ||
} | ||
} | ||
|
||
clientStat.getStatsEvent = function(name, reading) { | ||
var ts_sec = Date.now() / 1000; | ||
var appVersion = clientStat.getAppVersion(); | ||
return { | ||
'name': name, | ||
'ts': ts_sec, | ||
'reading': reading, | ||
'client_app_version': appVersion, | ||
'client_os_version': $window.device.version | ||
}; | ||
} | ||
clientStat.addReading = function(name, reading) { | ||
var db = clientStat.getDB(); | ||
if (angular.isDefined(db)) { | ||
return db.putMessage(clientStat.CLIENT_TIME, | ||
clientStat.getStatsEvent(name, reading)); | ||
} | ||
} | ||
|
||
clientStat.addEvent = function(name) { | ||
var db = clientStat.getDB(); | ||
if (angular.isDefined(db)) { | ||
return db.putMessage(clientStat.CLIENT_NAV_EVENT, | ||
clientStat.getStatsEvent(name, null)); | ||
} | ||
} | ||
|
||
clientStat.addError = function(name, errorStr) { | ||
var db = clientStat.getDB(); | ||
if (angular.isDefined(db)) { | ||
return db.putMessage(clientStat.CLIENT_ERROR, | ||
clientStat.getStatsEvent(name, errorStr)); | ||
} | ||
} | ||
|
||
return clientStat; | ||
}) | ||
|