Merge pull request #289 from sharelatex/pr-countly-pruning

Countly pruning
This commit is contained in:
Paulo Jorge Reis 2016-07-28 09:17:21 +01:00 committed by GitHub
commit d6be52af27
5 changed files with 35 additions and 11 deletions

View file

@ -56,9 +56,6 @@ html(itemscope, itemtype='http://schema.org/Product')
Countly.url = '#{settings.analytics.countly.server}'; Countly.url = '#{settings.analytics.countly.server}';
!{ session.user ? 'Countly.device_id = "' + session.user._id + '";' : '' } !{ session.user ? 'Countly.device_id = "' + session.user._id + '";' : '' }
Countly.q.push(['track_sessions']);
Countly.q.push(['track_pageview']);
(function() { (function() {
var cly = document.createElement('script'); cly.type = 'text/javascript'; var cly = document.createElement('script'); cly.type = 'text/javascript';
cly.async = true; cly.async = true;

View file

@ -72,13 +72,13 @@ define [
# Tracking code. # Tracking code.
$scope.$watch "ui.view", (newView, oldView) -> $scope.$watch "ui.view", (newView, oldView) ->
if newView? and newView != "editor" and newView != "pdf" if newView? and newView != "editor" and newView != "pdf"
event_tracking.sendCountly "ide-open-view-#{ newView }" event_tracking.sendCountlyOnce "ide-open-view-#{ newView }-once"
$scope.$watch "ui.chatOpen", (isOpen) -> $scope.$watch "ui.chatOpen", (isOpen) ->
event_tracking.sendCountly "ide-open-chat" if isOpen event_tracking.sendCountlyOnce "ide-open-chat-once" if isOpen
$scope.$watch "ui.leftMenuShown", (isOpen) -> $scope.$watch "ui.leftMenuShown", (isOpen) ->
event_tracking.sendCountly "ide-open-left-menu" if isOpen event_tracking.sendCountlyOnce "ide-open-left-menu-once" if isOpen
# End of tracking code. # End of tracking code.
window._ide = ide window._ide = ide

View file

@ -333,7 +333,7 @@ define [
$scope.toggleLogs = () -> $scope.toggleLogs = () ->
$scope.shouldShowLogs = !$scope.shouldShowLogs $scope.shouldShowLogs = !$scope.shouldShowLogs
event_tracking.sendCountly "ide-open-logs" if $scope.shouldShowLogs event_tracking.sendCountlyOnce "ide-open-logs-once" if $scope.shouldShowLogs
$scope.showPdf = () -> $scope.showPdf = () ->
$scope.pdf.view = "pdf" $scope.pdf.view = "pdf"
@ -499,7 +499,7 @@ define [
App.controller "PdfLogEntryController", ["$scope", "ide", "event_tracking", ($scope, ide, event_tracking) -> App.controller "PdfLogEntryController", ["$scope", "ide", "event_tracking", ($scope, ide, event_tracking) ->
$scope.openInEditor = (entry) -> $scope.openInEditor = (entry) ->
event_tracking.sendCountly 'logs-jump-to-location' event_tracking.sendCountlyOnce "logs-jump-to-location-once"
entity = ide.fileTreeManager.findEntityByPath(entry.file) entity = ide.fileTreeManager.findEntityByPath(entry.file)
return if !entity? or entity.type != "doc" return if !entity? or entity.type != "doc"
if entry.line? if entry.line?

View file

@ -3,7 +3,7 @@ define [
], (App) -> ], (App) ->
App.controller "ShareController", ["$scope", "$modal", "event_tracking", ($scope, $modal, event_tracking) -> App.controller "ShareController", ["$scope", "$modal", "event_tracking", ($scope, $modal, event_tracking) ->
$scope.openShareProjectModal = () -> $scope.openShareProjectModal = () ->
event_tracking.sendCountly "ide-open-share-modal" event_tracking.sendCountlyOnce "ide-open-share-modal-once"
$modal.open( $modal.open(
templateUrl: "shareProjectModalTemplate" templateUrl: "shareProjectModalTemplate"

View file

@ -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", () ->