Improve analytics, switch from Segment to Google Analytics

This commit is contained in:
Glavin Wiechert 2016-06-27 23:52:48 -03:00
parent ce02903f89
commit 21c0ce7cde
2 changed files with 70 additions and 44 deletions

View File

@ -96,7 +96,6 @@
"atom": ">=1.6.0 <2.0.0"
},
"dependencies": {
"analytics-node": "^2.1.0",
"async": "^1.2.1",
"atom-message-panel": "^1.2.4",
"atom-space-pen-views": "^2.0.5",
@ -130,6 +129,7 @@
"typescript": "^1.8.10",
"typescript-formatter": "^2.1.0",
"underscore-plus": "^1.6.6",
"universal-analytics": "^0.3.11",
"which": "^1.1.1",
"winston": "^2.2.0",
"yaml-front-matter": "^3.2.3"

View File

@ -8,7 +8,7 @@ logger = require('../logger')(__filename)
# Lazy loaded dependencies
extend = null
Analytics = null
ua = null
fs = null
strip = null
yaml = null
@ -17,11 +17,12 @@ editorconfig = null
# Misc
{allowUnsafeEval} = require 'loophole'
allowUnsafeEval ->
Analytics = require("analytics-node")
ua = require("universal-analytics")
pkg = require("../../package.json")
version = pkg.version
# Analytics
analyticsWriteKey = "u3c26xkae8"
trackingId = "UA-52729731-2"
###
Register all supported beautifiers
@ -201,6 +202,27 @@ module.exports = class Beautifiers extends EventEmitter
logger.warn("Unsupported Language options: ", beautifierOptions)
return options
trackEvent : (payload) ->
@track("event", payload)
trackTiming : (payload) ->
@track("timing", payload)
track : (type, payload) ->
try
# Check if Analytics is enabled
if atom.config.get("atom-beautify.general.analytics")
# Setup Analytics
unless atom.config.get("atom-beautify.general._analyticsUserId")
uuid = require("node-uuid")
atom.config.set "atom-beautify.general._analyticsUserId", uuid.v4()
# Setup Analytics User Id
userId = atom.config.get("atom-beautify.general._analyticsUserId")
@analytics ?= new ua(trackingId, userId).debug()
@analytics[type](payload).send()
catch error
logger.error(error)
beautify : (text, allOptions, grammar, filePath, {onSave} = {}) ->
return Promise.all(allOptions)
@ -282,59 +304,63 @@ module.exports = class Beautifiers extends EventEmitter
context =
filePath: filePath
startTime = new Date()
beautifier.beautify(text, language.name, options, context)
.then(resolve)
.catch(reject)
.then((result) =>
resolve(result)
# Track Timing
@trackTiming({
utc: "Beautify" # Category
utv: language?.name # Variable
utt: (new Date() - startTime) # Value
utl: version # Label
})
# Track Empty beautification results
if not result
@trackEvent({
ec: version, # Category
ea: "Beautify:Empty" # Action
el: language?.name # Label
})
)
.catch((error) =>
reject(error)
# Track Errors
@trackEvent({
ec: version, # Category
ea: "Beautify:Error" # Action
el: language?.name # Label
})
)
.finally(=>
@emit "beautify::end"
)
# Check if Analytics is enabled
if atom.config.get("atom-beautify.general.analytics")
@trackEvent({
ec: version, # Category
ea: "Beautify" # Action
el: language?.name # Label
})
if onSave
@trackEvent({
ec: version, # Category
ea: "Beautify:OnSave" # Action
el: language?.name # Label
})
else
@trackEvent({
ec: version, # Category
ea: "Beautify:Manual" # Action
el: language?.name # Label
})
# Setup Analytics
analytics = new Analytics(analyticsWriteKey)
unless atom.config.get("atom-beautify.general._analyticsUserId")
uuid = require("node-uuid")
atom.config.set "atom-beautify.general._analyticsUserId", uuid.v4()
# Setup Analytics User Id
userId = atom.config.get("atom-beautify.general._analyticsUserId")
analytics.identify userId : userId
version = pkg.version
analytics.track
userId : atom.config.get("atom-beautify.general._analyticsUserId")
event : "Beautify"
properties :
language : language?.name
grammar : grammar
extension : fileExtension
version : version
#options : allOptions
label : language?.name
category : version
if unsupportedGrammar
if atom.config.get("atom-beautify.general.muteUnsupportedLanguageErrors")
return resolve( null )
else
repoBugsUrl = pkg.bugs.url
# issueTitle = "Add support for language with grammar '
# issueBody = """
#
# **Atom Version**:
# **Atom Beautify Version**:
# **Platform**:
#
# ```
#
# ```
#
# """
# requestLanguageUrl = "
# detail = "If you would like to request this language be supported please create an issue by clicking <a href=\"
title = "Atom Beautify could not find a supported beautifier for this file"
detail = """
Atom Beautify could not determine a supported beautifier to handle this file with grammar \"#{grammar}\" and extension \"#{fileExtension}\". \