Send events to Postgre.

This commit is contained in:
Paulo Reis 2016-08-10 17:28:13 +01:00
parent 4886e8ba0e
commit 0ec8e22ccf

View file

@ -2,14 +2,14 @@ define [
"base" "base"
"modules/localStorage" "modules/localStorage"
], (App) -> ], (App) ->
CACHE_KEY = "countlyEvents" CACHE_KEY = "mbEvents"
send = (category, action, attributes = {})-> send = (category, action, attributes = {})->
ga('send', 'event', category, action) ga('send', 'event', category, action)
event_name = "#{action}-#{category}" event_name = "#{action}-#{category}"
Intercom?("trackEvent", event_name, attributes) Intercom?("trackEvent", event_name, attributes)
App.factory "event_tracking", ($http, localStorage) ->
App.factory "event_tracking", (localStorage) ->
_getEventCache = () -> _getEventCache = () ->
eventCache = localStorage CACHE_KEY eventCache = localStorage CACHE_KEY
@ -34,30 +34,23 @@ define [
send: (category, action, label, value)-> send: (category, action, label, value)->
ga('send', 'event', category, action, label, value) ga('send', 'event', category, action, label, value)
sendCountly: (key, segmentation) -> sendMB: (key, segmentation = {}) ->
eventData = { key } $http {
eventData.segmentation = segmentation if segmentation? url: "/event/#{key}",
Countly?.q.push([ "add_event", eventData ])
sendCountlySampled: (key, segmentation) ->
@sendCountly key, segmentation if Math.random() < .01
sendCountlyOnce: (key, segmentation) ->
if ! _eventInCache(key)
_addEventToCache(key)
@sendCountly key, segmentation
send: (category, action, attributes = {})->
event_name = "#{action}-#{category}"
$.ajax {
url: "/event/#{event_name}",
method: "POST", method: "POST",
data: attributes, data: segmentation
dataType: "json",
headers: { headers: {
"X-CSRF-Token": window.csrfToken "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
} }
# App.directive "countlyTrack", () -> # App.directive "countlyTrack", () ->