mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Use existing localStorage module.
This commit is contained in:
parent
a3af95006b
commit
a93980f080
1 changed files with 19 additions and 26 deletions
|
@ -1,21 +1,19 @@
|
|||
define [
|
||||
"base"
|
||||
"modules/localStorage"
|
||||
], (App) ->
|
||||
CACHE_KEY = "countlyEvents"
|
||||
|
||||
App.factory "event_tracking", (localStorage) ->
|
||||
_getEventCache = () ->
|
||||
eventCacheStr = window.localStorage.getItem CACHE_KEY
|
||||
eventCache = localStorage CACHE_KEY
|
||||
|
||||
# Initialize as an empy object if the event cache is still empty.
|
||||
if !eventCacheStr?
|
||||
eventCacheStr = "{}"
|
||||
if !eventCache?
|
||||
eventCache = {}
|
||||
localStorage CACHE_KEY, eventCache
|
||||
|
||||
# Errors writing to localStorage may happen when quota is full or
|
||||
# browser is in incognito mode. We'll return an empty object, anyway.
|
||||
try
|
||||
window.localStorage.setItem CACHE_KEY, eventCacheStr
|
||||
|
||||
return JSON.parse eventCacheStr
|
||||
return eventCache
|
||||
|
||||
_eventInCache = (key) ->
|
||||
curCache = _getEventCache()
|
||||
|
@ -28,14 +26,9 @@ define [
|
|||
_addEventToCache = (key) ->
|
||||
curCache = _getEventCache()
|
||||
curCache[key] = true
|
||||
curCacheAsStr = JSON.stringify curCache
|
||||
|
||||
# Protection against issues mentioned above.
|
||||
try
|
||||
window.localStorage.setItem CACHE_KEY, curCacheAsStr
|
||||
localStorage CACHE_KEY, curCache
|
||||
|
||||
|
||||
App.factory "event_tracking", ->
|
||||
return {
|
||||
send: (category, action, label, value)->
|
||||
ga('send', 'event', category, action, label, value)
|
||||
|
|
Loading…
Reference in a new issue