mirror of
https://github.com/overleaf/overleaf.git
synced 2024-10-31 21:21:03 -04:00
5a13ee1077
- don’t talk to postgres - show recent blog post announcments - proxy all events to analytics api
61 lines
1.4 KiB
CoffeeScript
61 lines
1.4 KiB
CoffeeScript
define [
|
|
"base"
|
|
"modules/localStorage"
|
|
], (App) ->
|
|
CACHE_KEY = "mbEvents"
|
|
|
|
send = (category, action, attributes = {})->
|
|
ga('send', 'event', category, action)
|
|
event_name = "#{action}-#{category}"
|
|
Intercom?("trackEvent", event_name, attributes)
|
|
|
|
App.factory "event_tracking", ($http, localStorage) ->
|
|
_getEventCache = () ->
|
|
eventCache = localStorage CACHE_KEY
|
|
|
|
# Initialize as an empy object if the event cache is still empty.
|
|
if !eventCache?
|
|
eventCache = {}
|
|
localStorage CACHE_KEY, eventCache
|
|
|
|
return eventCache
|
|
|
|
_eventInCache = (key) ->
|
|
curCache = _getEventCache()
|
|
curCache[key] || false
|
|
|
|
_addEventToCache = (key) ->
|
|
curCache = _getEventCache()
|
|
curCache[key] = true
|
|
|
|
localStorage CACHE_KEY, curCache
|
|
|
|
return {
|
|
send: (category, action, label, value)->
|
|
ga('send', 'event', category, action, label, value)
|
|
|
|
sendMB: (key, segmentation = {}) ->
|
|
$http {
|
|
url: "/event/#{key}",
|
|
method: "POST",
|
|
data: segmentation
|
|
headers: {
|
|
"X-CSRF-Token": window.csrfToken
|
|
}
|
|
}
|
|
|
|
sendMBSampled: (key, segmentation) ->
|
|
@sendMB key, segmentation if Math.random() < .01
|
|
|
|
sendMBOnce: (key, segmentation) ->
|
|
if ! _eventInCache(key)
|
|
_addEventToCache(key)
|
|
@sendMB key, segmentation
|
|
}
|
|
|
|
|
|
#header
|
|
$('.navbar a').on "click", (e)->
|
|
href = $(e.target).attr("href")
|
|
if href?
|
|
ga('send', 'event', 'navigation', 'top menu bar', href)
|