Closes #47. Add Google Analytics.
This commit is contained in:
parent
667bdececb
commit
d8fb27289d
23
README.md
23
README.md
|
@ -2,8 +2,8 @@
|
|||
|
||||
> [Beautify](https://github.com/einars/js-beautify)
|
||||
HTML (including [Handlebars](http://handlebarsjs.com/)),
|
||||
CSS (including [Sass](http://sass-lang.com/) and [LESS](http://lesscss.org/))
|
||||
and JavaScript in Atom.
|
||||
CSS (including [Sass](http://sass-lang.com/) and [LESS](http://lesscss.org/)),
|
||||
JavaScript, and much more in Atom.
|
||||
|
||||
Atom Package: https://atom.io/packages/atom-beautify
|
||||
|
||||
|
@ -40,10 +40,29 @@ It will only beautify selected text, if a selection is found - if not, the whole
|
|||
|
||||
You can also type `ctrl-alt-b` as a shortcut or click `Packages > Beautify` in the menu.
|
||||
|
||||
#### Custom Keyboard Shortcuts
|
||||
|
||||
See [Keymaps In-Depth](https://atom.io/docs/latest/advanced/keymaps) for more details.
|
||||
|
||||
For example:
|
||||
|
||||
```coffeescript
|
||||
'.editor': # Available from Editor only
|
||||
'ctrl-alt-b': 'beautify'
|
||||
```
|
||||
|
||||
### Package Options
|
||||
|
||||
- `beautifyOnSave`
|
||||
You can also choose to beautify on every file save.
|
||||
|
||||
- `googleAnalytics`
|
||||
There is Google Analytics to track what languages
|
||||
are being used the most and other stats.
|
||||
Everything is anonymized and no personal information,
|
||||
such as source code, is sent to Google.
|
||||
See https://github.com/Glavin001/atom-beautify/issues/47
|
||||
for more details.
|
||||
|
||||
## Configuration
|
||||
|
||||
|
|
|
@ -297,6 +297,7 @@ function handleSaveEvent() {
|
|||
}
|
||||
|
||||
plugin.configDefaults = _.merge({
|
||||
googleAnalytics: true,
|
||||
beautifyOnSave: false
|
||||
}, defaultLanguageOptions);
|
||||
|
||||
|
|
|
@ -14,6 +14,8 @@ var beautifySQL = require('./langs/sql-beautify');
|
|||
var beautifyPHP = require('./langs/php-beautify');
|
||||
var beautifyPython = require('./langs/python-beautify');
|
||||
var beautifyRuby = require('./langs/ruby-beautify');
|
||||
var NA = require('nodealytics');
|
||||
var pkg = require('../package.json');
|
||||
|
||||
module.exports = {
|
||||
|
||||
|
@ -68,6 +70,8 @@ module.exports = {
|
|||
// Process each language
|
||||
beautify: function (text, grammar, allOptions, beautifyCompleted) {
|
||||
var self = this;
|
||||
// Beautify!
|
||||
var unsupportedGrammar = false;
|
||||
switch (grammar) {
|
||||
case 'JSON':
|
||||
// Treat JSON as JavaScript, because it will support comments.
|
||||
|
@ -104,14 +108,41 @@ module.exports = {
|
|||
beautifyPHP(text, self.getOptions('php', allOptions), beautifyCompleted);
|
||||
break;
|
||||
case 'Python':
|
||||
beautifyPython(text, self.getOptions('python', allOptions), beautifyCompleted);
|
||||
beautifyPython(text, self.getOptions('python', allOptions),
|
||||
beautifyCompleted);
|
||||
break;
|
||||
case 'Ruby':
|
||||
beautifyRuby(text, self.getOptions('ruby', allOptions), beautifyCompleted);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
unsupportedGrammar = true;
|
||||
}
|
||||
|
||||
// Google Analytics
|
||||
if (atom.config.get('atom-beautify.googleAnalytics')) {
|
||||
NA.initialize('UA-52729731-2', 'https://atom.io/packages/atom-beautify',
|
||||
function () {
|
||||
// category, action, label, value
|
||||
NA.trackEvent('grammar', grammar, function (err, resp) {
|
||||
// console.log(err, resp);
|
||||
// if (!err && resp.statusCode === 200) {
|
||||
// console.log('Event has been tracked with Google Analytics');
|
||||
// }
|
||||
});
|
||||
NA.trackEvent('version', pkg.version, function (err, resp) {
|
||||
// console.log(err, resp);
|
||||
// if (!err && resp.statusCode === 200) {
|
||||
// console.log('Event has been tracked with Google Analytics');
|
||||
// }
|
||||
});
|
||||
if (unsupportedGrammar) {
|
||||
NA.trackEvent('unsupportedGrammar', grammar, function (err, resp) {
|
||||
//
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
getOptions: function (selection, allOptions) {
|
||||
|
|
|
@ -72,7 +72,8 @@
|
|||
"lodash": "2.4.1",
|
||||
"strip-json-comments": "^0.1.3",
|
||||
"js-yaml": "^3.0.2",
|
||||
"temp": "^0.8.0"
|
||||
"temp": "^0.8.0",
|
||||
"nodealytics": "0.0.6"
|
||||
},
|
||||
"activationEvents": [
|
||||
"beautify"
|
||||
|
|
Loading…
Reference in New Issue