Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Adding Analytics logging for JSRefactor, Live Preview, Quick Edit and more features #14253

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/LiveDevelopment/LiveDevelopment.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ define(function LiveDevelopment(require, exports, module) {
StringUtils = require("utils/StringUtils"),
UserServer = require("LiveDevelopment/Servers/UserServer").UserServer,
WebSocketTransport = require("LiveDevelopment/transports/WebSocketTransport"),
PreferencesManager = require("preferences/PreferencesManager");
PreferencesManager = require("preferences/PreferencesManager"),
HealthLogger = require("utils/HealthLogger");

// Inspector
var Inspector = require("LiveDevelopment/Inspector/Inspector");
Expand Down Expand Up @@ -1350,6 +1351,13 @@ define(function LiveDevelopment(require, exports, module) {
});
}
}
// Send analytics data when Live Preview is opened
HealthLogger.sendAnalyticsData(
"livePreviewOpen",
"usage",
"livePreview",
"open"
);

// Register user defined server provider and keep handlers for further clean-up
_regServers.push(LiveDevServerManager.registerServer({ create: _createUserServer }, 99));
Expand Down
9 changes: 9 additions & 0 deletions src/editor/CSSInlineEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ define(function (require, exports, module) {
MultiRangeInlineEditor = require("editor/MultiRangeInlineEditor"),
Strings = require("strings"),
ViewUtils = require("utils/ViewUtils"),
HealthLogger = require("utils/HealthLogger"),
_ = require("thirdparty/lodash");

var _newRuleCmd,
Expand Down Expand Up @@ -169,6 +170,14 @@ define(function (require, exports, module) {
return null;
}

//Send analytics data for QuickEdit open
HealthLogger.sendAnalyticsData(
"QuickEditOpen",
"usage",
"quickEdit",
"open"
);

// Only provide CSS editor if the selection is within a single line
var sel = hostEditor.getSelection();
if (sel.start.line !== sel.end.line) {
Expand Down
10 changes: 9 additions & 1 deletion src/editor/EditorStatusBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ define(function (require, exports, module) {
CommandManager = require("command/CommandManager"),
Commands = require("command/Commands"),
DocumentManager = require("document/DocumentManager"),
StringUtils = require("utils/StringUtils");
StringUtils = require("utils/StringUtils"),
HealthLogger = require("utils/HealthLogger");

var SupportedEncodingsText = require("text!supported-encodings.json"),
SupportedEncodings = JSON.parse(SupportedEncodingsText);
Expand Down Expand Up @@ -174,6 +175,13 @@ define(function (require, exports, module) {
selStr = "";

if (sels.length > 1) {
//Send analytics data for multicursor use
HealthLogger.sendAnalyticsData(
"multiCursor",
"usage",
"multiCursor",
"use"
);
selStr = StringUtils.format(Strings.STATUSBAR_SELECTION_MULTIPLE, sels.length);
} else if (editor.hasSelection()) {
var sel = sels[0];
Expand Down
10 changes: 9 additions & 1 deletion src/extensions/default/JavaScriptQuickEdit/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ define(function (require, exports, module) {
LanguageManager = brackets.getModule("language/LanguageManager"),
PerfUtils = brackets.getModule("utils/PerfUtils"),
ProjectManager = brackets.getModule("project/ProjectManager"),
Strings = brackets.getModule("strings");
Strings = brackets.getModule("strings"),
HealthLogger = brackets.getModule("utils/HealthLogger");

/**
* Return the token string that is at the specified position.
Expand Down Expand Up @@ -196,6 +197,13 @@ define(function (require, exports, module) {
return null;
}

//Send analytics data for Quick Edit open
HealthLogger.sendAnalyticsData(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again do we are just capturing quick edit performed. Are we interested in errors which we get in this operation?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we just capture logging when quick edit is performed.

"QuickEditOpen",
"usage",
"quickEdit",
"open"
);
// Only provide JavaScript editor if the selection is within a single line
var sel = hostEditor.getSelection();
if (sel.start.line !== sel.end.line) {
Expand Down
76 changes: 68 additions & 8 deletions src/extensions/default/JavaScriptRefactoring/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ define(function (require, exports, module) {
ExtractToFunction = require("ExtractToFunction"),
WrapSelection = require("WrapSelection"),
CommandManager = brackets.getModule("command/CommandManager"),
Menus = brackets.getModule("command/Menus");
Menus = brackets.getModule("command/Menus"),
HealthLogger = brackets.getModule("utils/HealthLogger"),
_ = brackets.getModule("thirdparty/lodash"),
EditorManager = brackets.getModule("editor/EditorManager");

var jsRefactoringEnabled = true;

Expand Down Expand Up @@ -66,6 +69,63 @@ define(function (require, exports, module) {
jsRefactoringEnabled = _isRefactoringEnabled();
});

function _handleRefactor(functionName) {
var eventName, eventType = "";

switch (functionName) {
case REFACTOR_RENAME:
eventName = REFACTOR_RENAME;
eventType = "rename";
RenameIdentifier.handleRename();
break;
case EXTRACTTO_VARIABLE:
eventName = EXTRACTTO_VARIABLE;
eventType = "extractToVariable";
ExtractToVariable.handleExtractToVariable();
break;
case EXTRACTTO_FUNCTION:
eventName = EXTRACTTO_FUNCTION;
eventType = "extractToFunction";
ExtractToFunction.handleExtractToFunction();
break;
case REFACTORWRAPINTRYCATCH:
eventName = REFACTORWRAPINTRYCATCH;
eventType = "tryCatch";
WrapSelection.wrapInTryCatch();
break;
case REFACTORWRAPINCONDITION:
eventName = REFACTORWRAPINCONDITION;
eventType = "wrapInCondition";
WrapSelection.wrapInCondition();
break;
case REFACTORCONVERTTOARROWFN:
eventName = REFACTORCONVERTTOARROWFN;
eventType = "convertToFunction";
WrapSelection.convertToArrowFunction();
break;
case REFACTORCREATEGETSET:
eventName = REFACTORCREATEGETSET;
eventType = "createGetterSetter";
WrapSelection.createGettersAndSetters();
break;
}
if (eventName) {
var editor = EditorManager.getActiveEditor();

// Logging should be done only when the context is javascript
if (!editor || editor.getModeForSelection() !== "javascript") {
return;
}
// Send analytics data for js refactoring
HealthLogger.sendAnalyticsData(
eventName,
"usage",
"jsRefactor",
eventType
);
}
}

AppInit.appReady(function () {

if (jsRefactoringEnabled) {
Expand All @@ -76,34 +136,34 @@ define(function (require, exports, module) {
Menus.getMenu(menuLocation).addMenuDivider();

// Rename Identifier
CommandManager.register(Strings.CMD_REFACTORING_RENAME, REFACTOR_RENAME, RenameIdentifier.handleRename);
CommandManager.register(Strings.CMD_REFACTORING_RENAME, REFACTOR_RENAME, _.partial(_handleRefactor, REFACTOR_RENAME));
subMenu.addMenuItem(REFACTOR_RENAME);
Menus.getMenu(menuLocation).addMenuItem(REFACTOR_RENAME, KeyboardPrefs.renameIdentifier);

// Extract to Variable
CommandManager.register(Strings.CMD_EXTRACTTO_VARIABLE, EXTRACTTO_VARIABLE, ExtractToVariable.handleExtractToVariable);
CommandManager.register(Strings.CMD_EXTRACTTO_VARIABLE, EXTRACTTO_VARIABLE, _.partial(_handleRefactor, EXTRACTTO_VARIABLE));
subMenu.addMenuItem(EXTRACTTO_VARIABLE);
Menus.getMenu(menuLocation).addMenuItem(EXTRACTTO_VARIABLE, KeyboardPrefs.extractToVariable);

// Extract to Function
CommandManager.register(Strings.CMD_EXTRACTTO_FUNCTION, EXTRACTTO_FUNCTION, ExtractToFunction.handleExtractToFunction);
CommandManager.register(Strings.CMD_EXTRACTTO_FUNCTION, EXTRACTTO_FUNCTION, _.partial(_handleRefactor, EXTRACTTO_FUNCTION));
subMenu.addMenuItem(EXTRACTTO_FUNCTION);
Menus.getMenu(menuLocation).addMenuItem(EXTRACTTO_FUNCTION, KeyboardPrefs.extractToFunction);

// Wrap Selection
CommandManager.register(Strings.CMD_REFACTORING_TRY_CATCH, REFACTORWRAPINTRYCATCH, WrapSelection.wrapInTryCatch);
CommandManager.register(Strings.CMD_REFACTORING_TRY_CATCH, REFACTORWRAPINTRYCATCH, _.partial(_handleRefactor, REFACTORWRAPINTRYCATCH));
subMenu.addMenuItem(REFACTORWRAPINTRYCATCH);
Menus.getMenu(menuLocation).addMenuItem(REFACTORWRAPINTRYCATCH);

CommandManager.register(Strings.CMD_REFACTORING_CONDITION, REFACTORWRAPINCONDITION, WrapSelection.wrapInCondition);
CommandManager.register(Strings.CMD_REFACTORING_CONDITION, REFACTORWRAPINCONDITION, _.partial(_handleRefactor, REFACTORWRAPINCONDITION));
subMenu.addMenuItem(REFACTORWRAPINCONDITION);
Menus.getMenu(menuLocation).addMenuItem(REFACTORWRAPINCONDITION);

CommandManager.register(Strings.CMD_REFACTORING_ARROW_FUNCTION, REFACTORCONVERTTOARROWFN, WrapSelection.convertToArrowFunction);
CommandManager.register(Strings.CMD_REFACTORING_ARROW_FUNCTION, REFACTORCONVERTTOARROWFN, _.partial(_handleRefactor, REFACTORCONVERTTOARROWFN));
subMenu.addMenuItem(REFACTORCONVERTTOARROWFN);
Menus.getMenu(menuLocation).addMenuItem(REFACTORCONVERTTOARROWFN);

CommandManager.register(Strings.CMD_REFACTORING_GETTERS_SETTERS, REFACTORCREATEGETSET, WrapSelection.createGettersAndSetters);
CommandManager.register(Strings.CMD_REFACTORING_GETTERS_SETTERS, REFACTORCREATEGETSET, _.partial(_handleRefactor, REFACTORCREATEGETSET));
subMenu.addMenuItem(REFACTORCREATEGETSET);
Menus.getMenu(menuLocation).addMenuItem(REFACTORCREATEGETSET);
}
Expand Down
20 changes: 19 additions & 1 deletion src/extensions/default/MDNDocs/InlineDocsViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ define(function (require, exports, module) {
InlineWidget = brackets.getModule("editor/InlineWidget").InlineWidget,
KeyEvent = brackets.getModule("utils/KeyEvent"),
Strings = brackets.getModule("strings"),
Mustache = brackets.getModule("thirdparty/mustache/mustache");
Mustache = brackets.getModule("thirdparty/mustache/mustache"),
HealthLogger = brackets.getModule("utils/HealthLogger");

// Load template
var inlineEditorTemplate = require("text!InlineDocsViewer.html");
Expand Down Expand Up @@ -73,6 +74,8 @@ define(function (require, exports, module) {

this.$scroller = this.$wrapperDiv.find(".scroller");
this.$scroller.on("mousewheel", this._handleWheelScroll);
this.$moreinfo = this.$wrapperDiv.find(".more-info");
this.$moreinfo.on("click", this._logAnalyticsData);
this._onKeydown = this._onKeydown.bind(this);
}

Expand Down Expand Up @@ -191,6 +194,21 @@ define(function (require, exports, module) {
InlineDocsViewer.prototype._sizeEditorToContent = function () {
this.hostEditor.setInlineWidgetHeight(this, this.$wrapperDiv.height() + 20, true);
};

/**
* Send analytics data for Quick Doc "readMore" action
*
* @return {boolean} false
*/
InlineDocsViewer.prototype._logAnalyticsData = function () {
HealthLogger.sendAnalyticsData(
"QuickDocReadMore",
"usage",
"quickDoc",
"readMore"
);
return false;
};


module.exports = InlineDocsViewer;
Expand Down
11 changes: 10 additions & 1 deletion src/extensions/default/MDNDocs/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ define(function (require, exports, module) {
FileUtils = brackets.getModule("file/FileUtils"),
CSSUtils = brackets.getModule("language/CSSUtils"),
HTMLUtils = brackets.getModule("language/HTMLUtils"),
ExtensionUtils = brackets.getModule("utils/ExtensionUtils");
ExtensionUtils = brackets.getModule("utils/ExtensionUtils"),
HealthLogger = brackets.getModule("utils/HealthLogger");

// Extension modules
var InlineDocsViewer = require("InlineDocsViewer");
Expand Down Expand Up @@ -102,6 +103,14 @@ define(function (require, exports, module) {
return null;
}

// Send analytics data for Quick Doc open
HealthLogger.sendAnalyticsData(
"cssQuickDoc",
"usage",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2nd param is event category? usage might not be the correct word. feature name should be there something like quickedit, multicursor, refactor etc

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SnchitGrover would be able to clarify this.

"quickDoc",
"open"
);

// Only provide docs if the selection is within a single line
var sel = hostEditor.getSelection();
if (sel.start.line !== sel.end.line) {
Expand Down
10 changes: 9 additions & 1 deletion src/preferences/PreferencesDialogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ define(function (require, exports, module) {
Strings = require("strings"),
SettingsDialogTemplate = require("text!htmlContent/project-settings-dialog.html"),
Mustache = require("thirdparty/mustache/mustache"),
PathUtils = require("thirdparty/path-utils/path-utils");
PathUtils = require("thirdparty/path-utils/path-utils"),
HealthLogger = require("utils/HealthLogger");

/**
* Validate that text string is a valid base url which should map to a server folder
Expand Down Expand Up @@ -101,6 +102,13 @@ define(function (require, exports, module) {
var baseUrlValue = $baseUrlControl.val();
var result = _validateBaseUrl(baseUrlValue);
if (result === "") {
// Send analytics data when url is set in project settings
HealthLogger.sendAnalyticsData(
"projectSettingsLivepreview",
"usage",
"projectSettings",
"use"
);
ProjectManager.setBaseUrl(baseUrlValue);
} else {
// Re-invoke dialog with result (error message)
Expand Down