Skip to content

Commit

Permalink
add usage tracking about open/save clicks
Browse files Browse the repository at this point in the history
add error handling to open external file
  • Loading branch information
drichard committed Jun 24, 2012
1 parent c785ca2 commit eb233bb
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
3 changes: 1 addition & 2 deletions src/js/FilePicker.js
Expand Up @@ -40,9 +40,8 @@ mindmaps.FilePicker = function(eventBus, mindmapModel) {
try {
var doc = mindmaps.Document.fromJSON(data);
} catch (e) {
console.error('Error while opening map from cloud', e);
eventBus.publish(mindmaps.Event.NOTIFICATION_ERROR, 'File is not a valid mind map!');
return;
throw new Error('Error while opening map from cloud', e);
}

mindmapModel.setDocument(doc);
Expand Down
14 changes: 12 additions & 2 deletions src/js/OpenDocument.js
Expand Up @@ -103,6 +103,8 @@ mindmaps.OpenDocumentPresenter = function(eventBus, mindmapModel, view, filePick
* Open file via cloud
*/
view.openCloudButtonClicked = function(e) {
mindmaps.Util.trackEvent("Clicks", "cloud-open");

filePicker.open({
success: function() {
view.hideOpenDialog();
Expand All @@ -113,7 +115,6 @@ mindmaps.OpenDocumentPresenter = function(eventBus, mindmapModel, view, filePick
});
};

// TODO experimental, catch errrs
// http://www.w3.org/TR/FileAPI/#dfn-filereader
/**
* View callback: external file has been selected. Try to read and parse a
Expand All @@ -122,12 +123,19 @@ mindmaps.OpenDocumentPresenter = function(eventBus, mindmapModel, view, filePick
* @ignore
*/
view.openExernalFileClicked = function(e) {
mindmaps.Util.trackEvent("Clicks", "hdd-open");

var files = e.target.files;
var file = files[0];

var reader = new FileReader();
reader.onload = function() {
var doc = mindmaps.Document.fromJSON(reader.result);
try {
var doc = mindmaps.Document.fromJSON(reader.result);
} catch (e) {
eventBus.publish(mindmaps.Event.NOTIFICATION_ERROR, 'File is not a valid mind map!');
throw new Error('Error while opening map from hdd', e);
}
mindmapModel.setDocument(doc);
view.hideOpenDialog();
};
Expand All @@ -143,6 +151,8 @@ mindmaps.OpenDocumentPresenter = function(eventBus, mindmapModel, view, filePick
* @param {mindmaps.Document} doc
*/
view.documentClicked = function(doc) {
mindmaps.Util.trackEvent("Clicks", "localstorage-open");

mindmapModel.setDocument(doc);
view.hideOpenDialog();
};
Expand Down
6 changes: 6 additions & 0 deletions src/js/SaveDocument.js
Expand Up @@ -101,6 +101,8 @@ mindmaps.SaveDocumentPresenter = function(eventBus, mindmapModel, view, autosave
* Save in cloud button was clicked.
*/
view.cloudStorageButtonClicked = function() {
mindmaps.Util.trackEvent("Clicks", "cloud-save");

filePicker.save({
success: function() {
view.hideSaveDialog();
Expand All @@ -118,6 +120,8 @@ mindmaps.SaveDocumentPresenter = function(eventBus, mindmapModel, view, autosave
* @ignore
*/
view.localStorageButtonClicked = function() {
mindmaps.Util.trackEvent("Clicks", "localstorage-save");

var success = mindmapModel.saveToLocalStorage();
if (success) {
view.hideSaveDialog();
Expand Down Expand Up @@ -148,6 +152,8 @@ mindmaps.SaveDocumentPresenter = function(eventBus, mindmapModel, view, autosave
* @returns {String}
*/
view.fileNameRequested = function() {
mindmaps.Util.trackEvent("Clicks", "hdd-save");

return mindmapModel.getMindMap().getRoot().getCaption() + ".json";
};

Expand Down
15 changes: 15 additions & 0 deletions src/js/Util.js
Expand Up @@ -3,6 +3,21 @@
*/
mindmaps.Util = mindmaps.Util || {};

/**
* Tracks an event to google analytics.
*/
mindmaps.Util.trackEvent = function(category, action, label) {
if (!window._gaq) {
return;
}

if (label) {
_gaq.push([ '_trackEvent', category, action, label]);
} else {
_gaq.push([ '_trackEvent', category, action]);
}
}

/**
* Creates a UUID in compliance with RFC4122.
*
Expand Down

0 comments on commit eb233bb

Please sign in to comment.