2014-03-25 12:24:50 -04:00
|
|
|
define [
|
|
|
|
"libs/md5"
|
|
|
|
], () ->
|
2014-02-12 05:23:40 -05:00
|
|
|
class AnalyticsManager
|
|
|
|
constructor: (@ide) ->
|
|
|
|
@ide.editor.on "update:doc", () =>
|
|
|
|
@updateCount ||= 0
|
|
|
|
@updateCount++
|
|
|
|
if @updateCount == 100
|
2014-03-08 13:31:07 -05:00
|
|
|
ga('send', 'event', 'editor-interaction', 'multi-doc-update')
|
2014-02-12 05:23:40 -05:00
|
|
|
|
|
|
|
@ide.pdfManager.on "compile:pdf", () =>
|
|
|
|
@compileCount ||= 0
|
|
|
|
@compileCount++
|
|
|
|
if @compileCount == 1
|
2014-03-08 13:31:07 -05:00
|
|
|
ga('send', 'event', 'editor-interaction', 'single-compile')
|
2014-02-12 05:23:40 -05:00
|
|
|
if @compileCount == 3
|
2014-03-08 13:31:07 -05:00
|
|
|
ga('send', 'event', 'editor-interaction', 'multi-compile')
|
2014-03-25 12:24:50 -04:00
|
|
|
|
|
|
|
getABTestBucket: (test_name, buckets = []) ->
|
|
|
|
hash = CryptoJS.MD5("#{@ide.user.get("id")}:#{test_name}")
|
|
|
|
bucketIndex = parseInt(hash.toString().slice(0,2), 16) % buckets.length
|
|
|
|
return buckets[bucketIndex]
|
|
|
|
|
|
|
|
startABTest: (test_name, buckets = []) ->
|
|
|
|
value = @getABTestBucket(test_name, buckets)
|
|
|
|
ga('send', 'event', 'ab_tests', test_name, "viewed-#{value}")
|
|
|
|
return value
|
|
|
|
|
|
|
|
endABTest: (test_name, buckets = []) ->
|
|
|
|
value = @getABTestBucket(test_name, buckets)
|
|
|
|
ga('send', 'event', 'ab_tests', test_name, "converted-#{value}")
|
|
|
|
return value
|