|
@@ -1,8 +1,30 @@
|
|
|
define [
|
|
define [
|
|
|
"base"
|
|
"base"
|
|
|
|
|
+ "modules/localStorage"
|
|
|
], (App) ->
|
|
], (App) ->
|
|
|
|
|
+ CACHE_KEY = "countlyEvents"
|
|
|
|
|
+
|
|
|
|
|
+ App.factory "event_tracking", (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
|
|
|
|
|
|
|
|
- App.factory "event_tracking", ->
|
|
|
|
|
return {
|
|
return {
|
|
|
send: (category, action, label, value)->
|
|
send: (category, action, label, value)->
|
|
|
ga('send', 'event', category, action, label, value)
|
|
ga('send', 'event', category, action, label, value)
|
|
@@ -10,10 +32,15 @@ define [
|
|
|
sendCountly: (key, segmentation) ->
|
|
sendCountly: (key, segmentation) ->
|
|
|
eventData = { key }
|
|
eventData = { key }
|
|
|
eventData.segmentation = segmentation if segmentation?
|
|
eventData.segmentation = segmentation if segmentation?
|
|
|
- Countly?.q.push([ "add_event", eventData ]);
|
|
|
|
|
|
|
+ Countly?.q.push([ "add_event", eventData ])
|
|
|
|
|
|
|
|
sendCountlySampled: (key, segmentation) ->
|
|
sendCountlySampled: (key, segmentation) ->
|
|
|
@sendCountly key, segmentation if Math.random() < .01
|
|
@sendCountly key, segmentation if Math.random() < .01
|
|
|
|
|
+
|
|
|
|
|
+ sendCountlyOnce: (key, segmentation) ->
|
|
|
|
|
+ if ! _eventInCache(key)
|
|
|
|
|
+ _addEventToCache(key)
|
|
|
|
|
+ @sendCountly key, segmentation
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
# App.directive "countlyTrack", () ->
|
|
# App.directive "countlyTrack", () ->
|