Skip to content

Commit

Permalink
chore: add desktop google analytics ids, not wired in
Browse files Browse the repository at this point in the history
  • Loading branch information
abose committed Dec 18, 2023
1 parent 6cb36dd commit e3f0832
Show file tree
Hide file tree
Showing 9 changed files with 193 additions and 22 deletions.
1 change: 1 addition & 0 deletions docs/generatedApiDocs/GitHub-API-Index.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ The list of all APIs for phoenix.
1. [utils/ExtensionInterface](ExtensionInterface-API)
1. [utils/FeatureGate](FeatureGate-API)
1. [utils/Metrics](Metrics-API)
1. [utils/StringUtils](StringUtils-API)
1. [widgets/NotificationUI](NotificationUI-API)
1. [worker/ExtensionsWorker](ExtensionsWorker-API)
1. [worker/IndexingWorker](IndexingWorker-API)
Expand Down
28 changes: 28 additions & 0 deletions docs/generatedApiDocs/NodeConnector-API.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,32 @@ Checks if Node.js Engine is available.

Returns **[boolean][5]** Returns true if Node.js Engine is available.

## terminateNode

Terminate the PhNodeEngine node if it is available. Else does nothing.

Returns **void**

## setInspectEnabled

Sets weather to enable node inspector in next boot.

### Parameters

* `enabled` **[boolean][5]** true to enable, else false.

## isInspectEnabled

Returns whether node inspector is enabled. If node is not present, always returns false.

Returns **[boolean][5]** True if inspect mode is enabled, false otherwise.

## getInspectPort

Retrieves the node inspector port for the Phoenix Node.js engine.

Returns **[number][6]** The inspection port number.

[1]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String

[2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
Expand All @@ -172,3 +198,5 @@ Returns **[boolean][5]** Returns true if Node.js Engine is available.
[4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function

[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean

[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
131 changes: 131 additions & 0 deletions docs/generatedApiDocs/utils/StringUtils-API.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

## utils/StringUtils

Utilities functions related to string manipulation

## format

Format a string by replacing placeholder symbols with passed in arguments.

Example: var formatted = StringUtils.format("Hello {0}", "World");

### Parameters

* `str` **[string][1]** The base string

Returns **[string][1]** Formatted string

## getLines

Splits the text by new line characters and returns an array of lines

### Parameters

* `text` **[string][1]**

Returns **[Array][2]<[string][1]>** lines

## offsetToLineNum

Returns a line number corresponding to an offset in some text. The text can
be specified as a single string or as an array of strings that correspond to
the lines of the string.

Specify the text in lines when repeatedly calling the function on the same
text in a loop. Use getLines() to divide the text into lines, then repeatedly call
this function to compute a line number from the offset.

### Parameters

* `textOrLines` **([string][1] | [Array][2]<[string][1]>)** string or array of lines from which
to compute the line number from the offset
* `offset` **[number][3]**

Returns **[number][3]** line number

## startsWith

Returns true if the given string starts with the given prefix.

### Parameters

* `str` **[String][1]**
* `prefix` **[String][1]**

Returns **[Boolean][4]**

## endsWith

Returns true if the given string ends with the given suffix.

### Parameters

* `str` **[string][1]**
* `suffix` **[string][1]**

## breakableUrl

Return an escaped path or URL string that can be broken near path separators.

### Parameters

* `url` **[string][1]** the path or URL to format

Returns **[string][1]** the formatted path or URL

## prettyPrintBytes

Converts number of bytes into human readable format.
If param bytes is negative it returns the number without any changes.

### Parameters

* `bytes` **[number][3]** Number of bytes to convert
* `precision` **[number][3]** Number of digits after the decimal separator

Returns **[string][1]**

## truncate

Truncate text to specified length.

### Parameters

* `str` **[string][1]** Text to be truncated.
* `len` **[number][3]** Length to which text should be truncated

Returns **[string][1]?** Returns truncated text only if it was changed

## hashCode

Computes a 32bit hash from the given string
Taken from [http://stackoverflow.com/questions/7616461/generate-a-hash-from-string-in-javascript-jquery][5]

### Parameters

* `str` **[string][1]** The string for which hash is to be computed

Returns **[number][3]** The 32-bit hash

## randomString

Generates a random nonce string of the specified length.

!!!Should not be used for crypto secure workflows.!!!

### Parameters

* `stringLength` **[number][3]** The length of the nonce in bytes.

Returns **[string][1]** The randomly generated nonce.

[1]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String

[2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array

[3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number

[4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean

[5]: http://stackoverflow.com/questions/7616461/generate-a-hash-from-string-in-javascript-jquery
1 change: 1 addition & 0 deletions src/brackets.config.dist.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"googleAnalyticsID" : "G-FBK9RP5YK2",
"googleAnalyticsIDDesktop": "G-M7MX9BYZZ3",
"mixPanelID" : "8cb6814f733e37c05cc59b4adad26407",
"coreAnalyticsID" : "phoenix",
"coreAnalyticsAppName" : "phoenix-prod",
Expand Down
1 change: 1 addition & 0 deletions src/brackets.config.staging.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"googleAnalyticsID" : "G-FP5S9BKDSJ",
"googleAnalyticsIDDesktop" : "G-D5R1Y6PTS8",
"mixPanelID" : "a7e08ffd43c37767c29b13df1d2e6c62",
"coreAnalyticsID" : "phoenix",
"coreAnalyticsAppName" : "phoenix-stage",
Expand Down
1 change: 1 addition & 0 deletions src/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"linting.enabled_by_default": true,
"build_timestamp": "",
"googleAnalyticsID": "G-P4HJFPDB76",
"googleAnalyticsIDDesktop": "G-VE5BXWJ0HF",
"mixPanelID": "49c4d164b592be2350fc7af06a259bf3",
"coreAnalyticsID": "phoenix",
"coreAnalyticsAppName": "phoenix-dev",
Expand Down
22 changes: 1 addition & 21 deletions src/utils/Metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ define(function (require, exports, module) {
script.onload = function(){
gtag('js', new Date());

// TODO use googleAnalyticsIDDesktop for desktop analytics
gtag('config', brackets.config.googleAnalyticsID, {
'page_title': 'Phoenix editor',
'page_path': '/index.html',
Expand Down Expand Up @@ -198,25 +199,6 @@ define(function (require, exports, module) {
});
}

function _sendToMixPanel(category, action, label, count, value) {
if(disabled || window.testEnvironment){
return;
}
category = category || "category";
action = action || "action";
if(!label){
label = action;
}
count = count || 1;
value = value || 1;
if(!window.mixpanel || !mixpanel.track) {
return;
}
mixpanel.track(category, {
action, label, count, value
});
}

function _sendToCoreAnalytics(category, action, label, count, value) {
// https://developers.google.com/analytics/devguides/collection/analyticsjs/events
if(disabled || window.testEnvironment){
Expand Down Expand Up @@ -256,7 +238,6 @@ define(function (require, exports, module) {
function _countEvent(eventType, eventCategory, eventSubCategory, count= 1) {
_logEventForAudit(eventType, eventCategory, eventSubCategory, count, AUDIT_TYPE_COUNT);
_sendToGoogleAnalytics(eventType, eventCategory, eventSubCategory, count);
_sendToMixPanel(eventType, eventCategory, eventSubCategory, count);
_sendToCoreAnalytics(eventType, eventCategory, eventSubCategory, count);
}

Expand Down Expand Up @@ -286,7 +267,6 @@ define(function (require, exports, module) {
function _valueEvent(eventType, eventCategory, eventSubCategory, value) {
_logEventForAudit(eventType, eventCategory, eventSubCategory, value, AUDIT_TYPE_VALUE);
_sendToGoogleAnalytics(eventType, eventCategory, eventSubCategory, value);
_sendToMixPanel(eventType, eventCategory, eventSubCategory, 1, value);
_sendToCoreAnalytics(eventType, eventCategory, eventSubCategory, 1, value);
}

Expand Down
28 changes: 28 additions & 0 deletions src/utils/StringUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
*
*/

// @INCLUDE_IN_API_DOCS

/* The hash code routne is taken from http://stackoverflow.com/questions/7616461/generate-a-hash-from-string-in-javascript-jquery
@CC wiki attribution: esmiralha
*/
Expand All @@ -29,6 +31,7 @@
/**
* Utilities functions related to string manipulation
*
* @module utils/StringUtils
*/
define(function (require, exports, module) {

Expand Down Expand Up @@ -243,6 +246,30 @@ define(function (require, exports, module) {
return hash;
}

/**
* Generates a random nonce string of the specified length.
*
* !!!Should not be used for crypto secure workflows.!!!
*
* @param {number} stringLength - The length of the nonce in bytes.
* @returns {string} - The randomly generated nonce.
*/
function randomString(stringLength) {
const randomBuffer = new Uint8Array(stringLength);
crypto.getRandomValues(randomBuffer);

// Define the character set for the random string
const charset = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';

// Convert the ArrayBuffer to a case-sensitive random string with numbers
let randomId = '';
Array.from(randomBuffer).forEach(byte => {
randomId += charset[byte % charset.length];
});

return randomId;
}

// Define public API
exports.format = format;
exports.regexEscape = regexEscape;
Expand All @@ -256,4 +283,5 @@ define(function (require, exports, module) {
exports.prettyPrintBytes = prettyPrintBytes;
exports.truncate = truncate;
exports.hashCode = hashCode;
exports.randomString = randomString;
});
2 changes: 1 addition & 1 deletion test/spec/LowLevelFileIO-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ define(function (require, exports, module) {
});

it("should getDisplayLocation return correct path in tauri", function () {
if(!brackets.browser.isTauri) {
if(!Phoenix.browser.isTauri) {
return;
}
// tauri paths
Expand Down

0 comments on commit e3f0832

Please sign in to comment.