Skip to content

Commit

Permalink
Closes #47. Add Google Analytics.
Browse files Browse the repository at this point in the history
  • Loading branch information
Glavin001 committed Jul 12, 2014
1 parent 667bdec commit d8fb272
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 5 deletions.
23 changes: 21 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions lib/atom-beautify.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ function handleSaveEvent() {
}

plugin.configDefaults = _.merge({
googleAnalytics: true,
beautifyOnSave: false
}, defaultLanguageOptions);

Expand Down
35 changes: 33 additions & 2 deletions lib/language-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit d8fb272

Please sign in to comment.