overleaf/services/web/public/coffee/analytics/AnalyticsManager.coffee

33 lines
1.1 KiB
CoffeeScript
Raw Normal View History

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
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
ga('send', 'event', 'editor-interaction', 'single-compile')
2014-02-12 05:23:40 -05:00
if @compileCount == 3
ga('send', 'event', 'editor-interaction', 'multi-compile')
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