Added Google Analytics

This commit is contained in:
benweet 2013-06-10 23:32:34 +01:00
parent 8942314860
commit 9b61c5062f
9 changed files with 92 additions and 54 deletions

View File

@ -553,7 +553,8 @@ div.dropdown-menu i {
text-align: left; text-align: left;
} }
#modal-settings .accordion-inner .form-inline .label-text { #modal-settings .accordion-inner .form-inline .label-text,
#modal-settings .accordion-inner .control-label {
margin: 0 10px; margin: 0 10px;
} }

View File

@ -17,7 +17,7 @@ define([
// Used for periodic tasks // Used for periodic tasks
var intervalId = undefined; var intervalId = undefined;
var periodicCallbacks = []; var periodicCallbacks = [extensionMgr.onPeriodicRun];
core.addPeriodicCallback = function(callback) { core.addPeriodicCallback = function(callback) {
periodicCallbacks.push(callback); periodicCallbacks.push(callback);
}; };

View File

@ -40,10 +40,12 @@ define([
} }
// Return a function that calls every callbacks from extensions // Return a function that calls every callbacks from extensions
function createHook(hookName) { function createHook(hookName, noLog) {
var callbackList = getExtensionCallbackList(hookName); var callbackList = getExtensionCallbackList(hookName);
return function() { return function() {
if(!noLog) {
logger.log(hookName, arguments); logger.log(hookName, arguments);
}
var callbackArguments = arguments; var callbackArguments = arguments;
_.each(callbackList, function(callback) { _.each(callbackList, function(callback) {
callback.apply(null, callbackArguments); callback.apply(null, callbackArguments);
@ -52,8 +54,8 @@ define([
} }
// Add a Hook to the extensionMgr // Add a Hook to the extensionMgr
function addHook(hookName) { function addHook(hookName, noLog) {
extensionMgr[hookName] = createHook(hookName); extensionMgr[hookName] = createHook(hookName, noLog);
} }
// Set extension config // Set extension config
@ -87,7 +89,8 @@ define([
addHook("onMessage"); addHook("onMessage");
addHook("onError"); addHook("onError");
addHook("onOfflineChanged"); addHook("onOfflineChanged");
addHook("onAsyncRunning"); addHook("onAsyncRunning", true);
addHook("onPeriodicRun", true);
// To access modules that are loaded after extensions // To access modules that are loaded after extensions
addHook("onFileMgrCreated"); addHook("onFileMgrCreated");

View File

@ -1,13 +1,26 @@
define([ define([
"jquery", "jquery",
"underscore", "underscore",
"utils",
"text!html/buttonSync.html", "text!html/buttonSync.html",
], function($, _, buttonSyncHTML) { "text!html/buttonSyncSettingsBloc.html",
], function($, _, utils, buttonSyncHTML, buttonSyncSettingsBlocHTML) {
var buttonSync = { var buttonSync = {
extensionId: "buttonSync", extensionId: "buttonSync",
extensionName: 'Button "Synchronize"', extensionName: 'Button "Synchronize"',
settingsBloc: '<p>Adds a "Synchronize documents" button in the navigation bar.</p>' defaultConfig: {
syncPeriod: 180000
},
settingsBloc: buttonSyncSettingsBlocHTML
};
buttonSync.onLoadSettings = function() {
utils.setInputValue("#input-sync-period", buttonSync.config.syncPeriod);
};
buttonSync.onSaveSettings = function(newConfig, event) {
newConfig.syncPeriod = utils.getInputIntValue("#input-sync-period", undefined, 0);
}; };
var button = undefined; var button = undefined;
@ -32,10 +45,21 @@ define([
synchronizer = synchronizerParameter; synchronizer = synchronizerParameter;
}; };
// Run sync periodically
var lastSync = 0;
buttonSync.onPeriodicRun = function() {
if(viewerMode === true || !buttonSync.config.syncPeriod || lastSync + buttonSync.config.syncPeriod > utils.currentTime) {
return;
}
if(synchronizer.sync() === true) {
lastSync = utils.currentTime;
}
};
buttonSync.onCreateButton = function() { buttonSync.onCreateButton = function() {
button = $(buttonSyncHTML).click(function() { button = $(buttonSyncHTML).click(function() {
if(!$(this).hasClass("disabled")) { if(!$(this).hasClass("disabled")) {
synchronizer.forceSync(); synchronizer.sync();
} }
}); });
return button; return button;

View File

@ -31,48 +31,48 @@ define([
// Collect informations about user settings // Collect informations about user settings
_gaq.push([ _gaq.push([
'_trackEvent', '_trackEvent',
"settings", "Settings",
'layoutOrientation', 'layoutOrientation',
"" + settings.layoutOrientation "" + settings.layoutOrientation
]); ]);
_gaq.push([ _gaq.push([
'_trackEvent', '_trackEvent',
"settings", "Settings",
'lazyRendering', 'lazyRendering',
"" + settings.lazyRendering "" + settings.lazyRendering
]); ]);
_gaq.push([ _gaq.push([
'_trackEvent', '_trackEvent',
"settings", "Settings",
'editorFontSize', 'editorFontSize',
"" + settings.editorFontSize "" + settings.editorFontSize
]); ]);
// Check if user has removed back links // Check if user has removed back links
_gaq.push([ _gaq.push([
'_trackEvent', '_trackEvent',
"settings", "Settings",
'defaultContentBacklink', 'defaultContent backlink',
"" + settings.defaultContent.indexOf(MAIN_URL) >= 0 "" + settings.defaultContent.indexOf(MAIN_URL) >= 0
]); ]);
_gaq.push([ _gaq.push([
'_trackEvent', '_trackEvent',
"settings", "Settings",
'commitMsgBacklink', 'commitMsg backlink',
"" + settings.commitMsg.indexOf(MAIN_URL) >= 0 "" + settings.commitMsg.indexOf(MAIN_URL) >= 0
]); ]);
// Check if user has changed sshProxy // Check if user has changed sshProxy
_gaq.push([ _gaq.push([
'_trackEvent', '_trackEvent',
"settings", "Settings",
'sshProxyChanged', 'sshProxy changed',
"" + settings.sshProxy != SSH_PROXY_URL "" + settings.sshProxy != SSH_PROXY_URL
]); ]);
// Check if extensions have been disabled // Check if extensions have been disabled
_.each(settings.extensionSettings, function(config, extensionId) { _.each(settings.extensionSettings, function(config, extensionId) {
_gaq.push([ _gaq.push([
'_trackEvent', '_trackEvent',
"extensions", "Extensions",
extensionId + "Enabled", extensionId + " enabled",
"" + config.enabled "" + config.enabled
]); ]);
}); });
@ -97,25 +97,34 @@ define([
init(); init();
}; };
var currentAction = "No action"; var currentAction = "Unknown";
googleAnalytics.onSyncRunning = function() { var startTime = 0;
googleAnalytics.onSyncRunning = function(isRunning) {
if(isRunning === true) {
currentAction = "Sync"; currentAction = "Sync";
startTime = new Date().getTime();
}
}; };
googleAnalytics.onPublishRunning = function() { googleAnalytics.onPublishRunning = function(isRunning) {
if(isRunning === true) {
currentAction = "Publish"; currentAction = "Publish";
startTime = new Date().getTime();
}
}; };
googleAnalytics.onAsyncRunning = function(isRunning) { googleAnalytics.onAsyncRunning = function(isRunning) {
if(isRunning === false) { if(isRunning === false) {
currentAction = "No action"; currentAction = "Unknown";
} }
}; };
// Log sync frequency // Log sync time
googleAnalytics.onSyncSuccess = function() { googleAnalytics.onSyncSuccess = function() {
var endTime = new Date().getTime();
_gaq.push([ _gaq.push([
'_trackEvent', '_trackTiming',
'Sync', 'Sync',
'SyncSuccess' 'SyncTime',
endTime - startTime
]); ]);
}; };
// Log import frequency and provider // Log import frequency and provider
@ -128,7 +137,7 @@ define([
_gaq.push([ _gaq.push([
'_trackEvent', '_trackEvent',
'Sync', 'Sync',
'SyncImportProvider', 'SyncImport provider',
provider.providerId provider.providerId
]); ]);
}; };
@ -142,22 +151,24 @@ define([
_gaq.push([ _gaq.push([
'_trackEvent', '_trackEvent',
'Sync', 'Sync',
'SyncExportProvider', 'SyncExport provider',
syncAttributes.provider.providerId syncAttributes.provider.providerId
]); ]);
}; };
// Log publish frequency and provider // Log publish time and provider
googleAnalytics.onPublishSuccess = function(fileDesc) { googleAnalytics.onPublishSuccess = function(fileDesc) {
var endTime = new Date().getTime();
_gaq.push([ _gaq.push([
'_trackEvent', '_trackTiming',
'Publish', 'Publish',
'PublishSuccess' 'PublishSuccess',
endTime - startTime
]); ]);
_.each(fileDesc.publishLocations, function(publishAttributes) { _.each(fileDesc.publishLocations, function(publishAttributes) {
_gaq.push([ _gaq.push([
'_trackEvent', '_trackEvent',
'Publish', 'Publish',
'PublishSuccessProvider', 'PublishSuccess provider',
publishAttributes.provider.providerId publishAttributes.provider.providerId
]); ]);
}); });
@ -167,7 +178,7 @@ define([
_gaq.push([ _gaq.push([
'_trackEvent', '_trackEvent',
'Publish', 'Publish',
'NewPublishProvider', 'NewPublish provider',
publishAttributes.provider.providerId publishAttributes.provider.providerId
]); ]);
}; };

View File

@ -7,7 +7,7 @@ define([
var toc = { var toc = {
extensionId: "toc", extensionId: "toc",
extensionName: "Table of content", extensionName: "Table of Content",
optional: true, optional: true,
defaultConfig: { defaultConfig: {
marker: "\\[(TOC|toc)\\]" marker: "\\[(TOC|toc)\\]"

View File

@ -5,7 +5,7 @@ define([
var workingIndicator = { var workingIndicator = {
extensionId: "workingIndicator", extensionId: "workingIndicator",
extensionName: "Working indicator", extensionName: "Working Indicator",
settingsBloc: '<p>Displays an animated image when a network operation is running.</p>' settingsBloc: '<p>Displays an animated image when a network operation is running.</p>'
}; };

View File

@ -0,0 +1,10 @@
<p>Adds a "Synchronize documents" button in the navigation bar.</p>
<div class="form-horizontal">
<div class="control-group">
<label class="control-label" for="input-sync-period">Sync period (optional)</label>
<div class="controls">
<input type="text" id="input-sync-period"
class="input-mini"> <span class="help-inline">ms</span>
</div>
</div>
</div>

View File

@ -41,12 +41,6 @@ define([
}); });
}); });
// Force the synchronization
synchronizer.forceSync = function() {
lastSync = 0;
synchronizer.sync();
};
// Recursive function to upload a single file on multiple locations // Recursive function to upload a single file on multiple locations
var uploadSyncAttributesList = []; var uploadSyncAttributesList = [];
var uploadContent = undefined; var uploadContent = undefined;
@ -154,16 +148,14 @@ define([
// Main entry point for synchronization // Main entry point for synchronization
var syncRunning = false; var syncRunning = false;
var lastSync = 0;
synchronizer.sync = function() { synchronizer.sync = function() {
// If sync is already running or timeout is not reached or offline // If sync is already running or offline
if(syncRunning || lastSync + SYNC_PERIOD > utils.currentTime || core.isOffline) { if(syncRunning || core.isOffline) {
return; return false;
} }
syncRunning = true; syncRunning = true;
extensionMgr.onSyncRunning(true); extensionMgr.onSyncRunning(true);
uploadCycle = true; uploadCycle = true;
lastSync = utils.currentTime;
function isError(error) { function isError(error) {
if(error !== undefined) { if(error !== undefined) {
@ -187,11 +179,8 @@ define([
extensionMgr.onSyncSuccess(); extensionMgr.onSyncSuccess();
}); });
}); });
return true;
}; };
// Run sync function periodically
if(viewerMode === false) {
core.addPeriodicCallback(synchronizer.sync);
}
// Initialize the export dialog // Initialize the export dialog
function initExportDialog(provider) { function initExportDialog(provider) {