[backport] Adding new analytics events

stable
Jesús Espino 2017-11-22 18:34:41 +01:00
parent 19e0268cc3
commit f7a5d12d08
9 changed files with 94 additions and 23 deletions

View File

@ -141,7 +141,7 @@ module.controller("ProjectProfileController", ProjectProfileController)
## Project Profile Directive ## Project Profile Directive
############################################################################# #############################################################################
ProjectProfileDirective = ($repo, $confirm, $loading, $navurls, $location, projectService, currentUserService) -> ProjectProfileDirective = ($repo, $confirm, $loading, $navurls, $location, projectService, currentUserService, $analytics) ->
link = ($scope, $el, $attrs) -> link = ($scope, $el, $attrs) ->
$ctrl = $el.controller() $ctrl = $el.controller()
@ -155,9 +155,24 @@ ProjectProfileDirective = ($repo, $confirm, $loading, $navurls, $location, proje
.target(submitButton) .target(submitButton)
.start() .start()
privacyChanged = $scope.project.isAttributeModified("is_private")
promise = $repo.save($scope.project) promise = $repo.save($scope.project)
promise.then -> promise.then ->
currentLoading.finish() currentLoading.finish()
if privacyChanged && $scope.project.is_private
$analytics.trackEvent(
"project-privacy-changed",
"from-public-to-private",
"Change project privacy from public to private",
1
)
else if privacyChanged && !$scope.project.is_private
$analytics.trackEvent(
"project-privacy-changed",
"from-private-to-public",
"Change project privacy from private to public",
1
)
$confirm.notify("success") $confirm.notify("success")
newUrl = $navurls.resolve("project-admin-project-profile-details", { newUrl = $navurls.resolve("project-admin-project-profile-details", {
project: $scope.project.slug project: $scope.project.slug
@ -182,7 +197,8 @@ ProjectProfileDirective = ($repo, $confirm, $loading, $navurls, $location, proje
return {link:link} return {link:link}
module.directive("tgProjectProfile", ["$tgRepo", "$tgConfirm", "$tgLoading", "$tgNavUrls", "$tgLocation", module.directive("tgProjectProfile", ["$tgRepo", "$tgConfirm", "$tgLoading", "$tgNavUrls", "$tgLocation",
"tgProjectService", "tgCurrentUserService", ProjectProfileDirective]) "tgProjectService", "tgCurrentUserService", "$tgAnalytics",
ProjectProfileDirective])
############################################################################# #############################################################################
@ -295,7 +311,7 @@ module.directive("tgProjectModules", ["$tgRepo", "$tgConfirm", "$tgLoading", "tg
## Project Export Directive ## Project Export Directive
############################################################################# #############################################################################
ProjectExportDirective = ($window, $rs, $confirm, $translate) -> ProjectExportDirective = ($window, $rs, $confirm, $translate, $analytics) ->
link = ($scope, $el, $attrs) -> link = ($scope, $el, $attrs) ->
buttonsEl = $el.find(".admin-project-export-buttons") buttonsEl = $el.find(".admin-project-export-buttons")
showButtons = -> buttonsEl.removeClass("hidden") showButtons = -> buttonsEl.removeClass("hidden")
@ -354,6 +370,7 @@ ProjectExportDirective = ($window, $rs, $confirm, $translate) ->
event.preventDefault() event.preventDefault()
onSuccess = (result) => onSuccess = (result) =>
$analytics.trackEvent("exporter", "export-project", "Exported project", 1)
if result.status == 202 # Async mode if result.status == 202 # Async mode
showExportResultAsyncMode() showExportResultAsyncMode()
else #result.status == 200 # Sync mode else #result.status == 200 # Sync mode
@ -380,7 +397,7 @@ ProjectExportDirective = ($window, $rs, $confirm, $translate) ->
return {link:link} return {link:link}
module.directive("tgProjectExport", ["$window", "$tgResources", "$tgConfirm", "$translate", module.directive("tgProjectExport", ["$window", "$tgResources", "$tgConfirm", "$translate",
ProjectExportDirective]) "$tgAnalytics", ProjectExportDirective])
############################################################################# #############################################################################

View File

@ -235,7 +235,7 @@ module.directive("tgWebhook", ["$tgResources", "$tgRepo", "$tgConfirm", "$tgLoad
## New webhook Directive ## New webhook Directive
############################################################################# #############################################################################
NewWebhookDirective = ($rs, $repo, $confirm, $loading) -> NewWebhookDirective = ($rs, $repo, $confirm, $loading, $analytics) ->
link = ($scope, $el, $attrs) -> link = ($scope, $el, $attrs) ->
webhook = $scope.$eval($attrs.tgWebhook) webhook = $scope.$eval($attrs.tgWebhook)
formDOMNode = $el.find(".new-webhook-form") formDOMNode = $el.find(".new-webhook-form")
@ -266,6 +266,7 @@ NewWebhookDirective = ($rs, $repo, $confirm, $loading) ->
$scope.newValue.project = $scope.project.id $scope.newValue.project = $scope.project.id
promise = $repo.create("webhooks", $scope.newValue) promise = $repo.create("webhooks", $scope.newValue)
promise.then => promise.then =>
$analytics.trackEvent("webhooks", "create", "Create new webhook", 1)
$scope.$emit("webhooks:reload") $scope.$emit("webhooks:reload")
initializeNewValue() initializeNewValue()
@ -295,7 +296,7 @@ NewWebhookDirective = ($rs, $repo, $confirm, $loading) ->
return {link:link} return {link:link}
module.directive("tgNewWebhook", ["$tgResources", "$tgRepo", "$tgConfirm", "$tgLoading", NewWebhookDirective]) module.directive("tgNewWebhook", ["$tgResources", "$tgRepo", "$tgConfirm", "$tgLoading", "$tgAnalytics", NewWebhookDirective])
############################################################################# #############################################################################
@ -464,7 +465,7 @@ module.directive("tgSelectInputText", SelectInputText)
## GithubWebhooks Directive ## GithubWebhooks Directive
############################################################################# #############################################################################
GithubWebhooksDirective = ($repo, $confirm, $loading) -> GithubWebhooksDirective = ($repo, $confirm, $loading, $analytics) ->
link = ($scope, $el, $attrs) -> link = ($scope, $el, $attrs) ->
form = $el.find("form").checksley({"onlyOneErrorElement": true}) form = $el.find("form").checksley({"onlyOneErrorElement": true})
submit = debounce 2000, (event) => submit = debounce 2000, (event) =>
@ -478,6 +479,7 @@ GithubWebhooksDirective = ($repo, $confirm, $loading) ->
promise = $repo.saveAttribute($scope.github, "github") promise = $repo.saveAttribute($scope.github, "github")
promise.then -> promise.then ->
$analytics.trackEvent("github-webhook", "created-or-changed", "Create or changed github webhook", 1)
currentLoading.finish() currentLoading.finish()
$confirm.notify("success") $confirm.notify("success")
@ -493,14 +495,14 @@ GithubWebhooksDirective = ($repo, $confirm, $loading) ->
return {link:link} return {link:link}
module.directive("tgGithubWebhooks", ["$tgRepo", "$tgConfirm", "$tgLoading", GithubWebhooksDirective]) module.directive("tgGithubWebhooks", ["$tgRepo", "$tgConfirm", "$tgLoading", "$tgAnalytics", GithubWebhooksDirective])
############################################################################# #############################################################################
## GitlabWebhooks Directive ## GitlabWebhooks Directive
############################################################################# #############################################################################
GitlabWebhooksDirective = ($repo, $confirm, $loading) -> GitlabWebhooksDirective = ($repo, $confirm, $loading, $analytics) ->
link = ($scope, $el, $attrs) -> link = ($scope, $el, $attrs) ->
form = $el.find("form").checksley({"onlyOneErrorElement": true}) form = $el.find("form").checksley({"onlyOneErrorElement": true})
submit = debounce 2000, (event) => submit = debounce 2000, (event) =>
@ -514,6 +516,7 @@ GitlabWebhooksDirective = ($repo, $confirm, $loading) ->
promise = $repo.saveAttribute($scope.gitlab, "gitlab") promise = $repo.saveAttribute($scope.gitlab, "gitlab")
promise.then -> promise.then ->
$analytics.trackEvent("gitlab-webhook", "created-or-changed", "Create or changed gitlab webhook", 1)
currentLoading.finish() currentLoading.finish()
$confirm.notify("success") $confirm.notify("success")
$scope.$emit("project:modules:reload") $scope.$emit("project:modules:reload")
@ -530,14 +533,14 @@ GitlabWebhooksDirective = ($repo, $confirm, $loading) ->
return {link:link} return {link:link}
module.directive("tgGitlabWebhooks", ["$tgRepo", "$tgConfirm", "$tgLoading", GitlabWebhooksDirective]) module.directive("tgGitlabWebhooks", ["$tgRepo", "$tgConfirm", "$tgLoading", "$tgAnalytics", GitlabWebhooksDirective])
############################################################################# #############################################################################
## BitbucketWebhooks Directive ## BitbucketWebhooks Directive
############################################################################# #############################################################################
BitbucketWebhooksDirective = ($repo, $confirm, $loading) -> BitbucketWebhooksDirective = ($repo, $confirm, $loading, $analytics) ->
link = ($scope, $el, $attrs) -> link = ($scope, $el, $attrs) ->
form = $el.find("form").checksley({"onlyOneErrorElement": true}) form = $el.find("form").checksley({"onlyOneErrorElement": true})
submit = debounce 2000, (event) => submit = debounce 2000, (event) =>
@ -551,6 +554,7 @@ BitbucketWebhooksDirective = ($repo, $confirm, $loading) ->
promise = $repo.saveAttribute($scope.bitbucket, "bitbucket") promise = $repo.saveAttribute($scope.bitbucket, "bitbucket")
promise.then -> promise.then ->
$analytics.trackEvent("bitbucket-webhook", "created-or-changed", "Create or changed bitbucket webhook", 1)
currentLoading.finish() currentLoading.finish()
$confirm.notify("success") $confirm.notify("success")
$scope.$emit("project:modules:reload") $scope.$emit("project:modules:reload")
@ -567,7 +571,7 @@ BitbucketWebhooksDirective = ($repo, $confirm, $loading) ->
return {link:link} return {link:link}
module.directive("tgBitbucketWebhooks", ["$tgRepo", "$tgConfirm", "$tgLoading", BitbucketWebhooksDirective]) module.directive("tgBitbucketWebhooks", ["$tgRepo", "$tgConfirm", "$tgLoading", "$tgAnalytics", BitbucketWebhooksDirective])
############################################################################# #############################################################################
@ -636,4 +640,37 @@ class GogsController extends mixOf(taiga.Controller, taiga.PageMixin, taiga.Filt
@.loadProject() @.loadProject()
return @.loadModules() return @.loadModules()
GogsWebhooksDirective = ($repo, $confirm, $loading, $analytics) ->
link = ($scope, $el, $attrs) ->
form = $el.find("form").checksley({"onlyOneErrorElement": true})
submit = debounce 2000, (event) =>
event.preventDefault()
return if not form.validate()
currentLoading = $loading()
.target(submitButton)
.start()
promise = $repo.saveAttribute($scope.gogs, "gogs")
promise.then ->
$analytics.trackEvent("gogs-webhook", "create-or-change", "Create or change gogs webhook", 1)
currentLoading.finish()
$confirm.notify("success")
$scope.$emit("project:modules:reload")
promise.then null, (data) ->
currentLoading.finish()
form.setErrors(data)
if data._error_message
$confirm.notify("error", data._error_message)
submitButton = $el.find(".submit-button")
$el.on "submit", "form", submit
$el.on "click", ".submit-button", submit
return {link:link}
module.controller("GogsController", GogsController) module.controller("GogsController", GogsController)
module.directive("tgGogsWebhooks", ["$tgRepo", "$tgConfirm", "$tgLoading", "$tgAnalytics", GogsWebhooksDirective])

View File

@ -270,7 +270,7 @@ module.directive("tgPublicRegisterMessage", ["$tgConfig", "$tgNavUrls", "$routeP
"$tgTemplate", PublicRegisterMessageDirective]) "$tgTemplate", PublicRegisterMessageDirective])
LoginDirective = ($auth, $confirm, $location, $config, $routeParams, $navUrls, $events, $translate, $window) -> LoginDirective = ($auth, $confirm, $location, $config, $routeParams, $navUrls, $events, $translate, $window, $analytics) ->
link = ($scope, $el, $attrs) -> link = ($scope, $el, $attrs) ->
form = new checksley.Form($el.find("form.login-form")) form = new checksley.Form($el.find("form.login-form"))
@ -284,6 +284,7 @@ LoginDirective = ($auth, $confirm, $location, $config, $routeParams, $navUrls, $
onSuccess = (response) -> onSuccess = (response) ->
$events.setupConnection() $events.setupConnection()
$analytics.trackEvent("auth", "login", "user login", 1)
if $scope.nextUrl.indexOf('http') == 0 if $scope.nextUrl.indexOf('http') == 0
$window.location.href = $scope.nextUrl $window.location.href = $scope.nextUrl
@ -326,7 +327,7 @@ LoginDirective = ($auth, $confirm, $location, $config, $routeParams, $navUrls, $
return {link:link} return {link:link}
module.directive("tgLogin", ["$tgAuth", "$tgConfirm", "$tgLocation", "$tgConfig", "$routeParams", module.directive("tgLogin", ["$tgAuth", "$tgConfirm", "$tgLocation", "$tgConfig", "$routeParams",
"$tgNavUrls", "$tgEvents", "$translate", "$window", LoginDirective]) "$tgNavUrls", "$tgEvents", "$translate", "$window", "$tgAnalytics", LoginDirective])
############################################################################# #############################################################################

View File

@ -86,6 +86,7 @@ class AnalyticsService extends taiga.Service
}) })
trackEvent: (category, action, label, value) -> trackEvent: (category, action, label, value) ->
console.log("TRACK EVENT: ", category, action, label, value)
return if not @.initialized return if not @.initialized
return if not @win.ga return if not @win.ga

View File

@ -33,7 +33,7 @@ module = angular.module("taigaProject")
## Delete Project Lightbox Directive ## Delete Project Lightbox Directive
############################################################################# #############################################################################
DeleteProjectDirective = ($repo, $rootscope, $auth, $location, $navUrls, $confirm, lightboxService, tgLoader, currentUserService) -> DeleteProjectDirective = ($repo, $rootscope, $auth, $location, $navUrls, $confirm, lightboxService, tgLoader, currentUserService, $analytics) ->
link = ($scope, $el, $attrs) -> link = ($scope, $el, $attrs) ->
projectToDelete = null projectToDelete = null
$scope.$on "deletelightbox:new", (ctx, project)-> $scope.$on "deletelightbox:new", (ctx, project)->
@ -50,6 +50,7 @@ DeleteProjectDirective = ($repo, $rootscope, $auth, $location, $navUrls, $confir
promise = $repo.remove(projectToDelete) promise = $repo.remove(projectToDelete)
promise.then (data) -> promise.then (data) ->
$analytics.trackEvent("projects", "delete", "Delete project", 1)
tgLoader.pageLoaded() tgLoader.pageLoaded()
$rootscope.$broadcast("projects:reload") $rootscope.$broadcast("projects:reload")
$location.path($navUrls.resolve("home")) $location.path($navUrls.resolve("home"))
@ -72,4 +73,5 @@ DeleteProjectDirective = ($repo, $rootscope, $auth, $location, $navUrls, $confir
return {link:link} return {link:link}
module.directive("tgLbDeleteProject", ["$tgRepo", "$rootScope", "$tgAuth", "$tgLocation", "$tgNavUrls", module.directive("tgLbDeleteProject", ["$tgRepo", "$rootScope", "$tgAuth", "$tgLocation", "$tgNavUrls",
"$tgConfirm", "lightboxService", "tgLoader", "tgCurrentUserService", DeleteProjectDirective]) "$tgConfirm", "lightboxService", "tgLoader", "tgCurrentUserService",
"$tgAnalytics", DeleteProjectDirective])

View File

@ -26,10 +26,11 @@ class CreateEpicController
@.$inject = [ @.$inject = [
"$tgConfirm" "$tgConfirm"
"tgProjectService", "tgProjectService",
"tgEpicsService" "tgEpicsService",
"$tgAnalytics"
] ]
constructor: (@confirm, @projectService, @epicsService) -> constructor: (@confirm, @projectService, @epicsService, @analytics) ->
# NOTE: To use Checksley setFormErrors() and validateForm() # NOTE: To use Checksley setFormErrors() and validateForm()
# are defined in the directive. # are defined in the directive.
@ -53,6 +54,7 @@ class CreateEpicController
@epicsService.createEpic(@.newEpic, @.attachments) @epicsService.createEpic(@.newEpic, @.attachments)
.then (response) => # On success .then (response) => # On success
@analytics.trackEvent("epic", "create", "create epic", 1)
@.onCreateEpic() @.onCreateEpic()
@.loading = false @.loading = false
.catch (response) => # On error .catch (response) => # On error

View File

@ -23,10 +23,11 @@ class CreatetProjectFormController
"tgProjectsService", "tgProjectsService",
"$projectUrl", "$projectUrl",
"$location", "$location",
"$tgNavUrls" "$tgNavUrls",
"$tgAnalytics"
] ]
constructor: (@currentUserService, @projectsService, @projectUrl, @location, @navUrls) -> constructor: (@currentUserService, @projectsService, @projectUrl, @location, @navUrls, @analytics) ->
@.projectForm = { @.projectForm = {
is_private: false is_private: false
} }
@ -46,6 +47,7 @@ class CreatetProjectFormController
@.formSubmitLoading = true @.formSubmitLoading = true
@projectsService.create(@.projectForm).then (project) => @projectsService.create(@.projectForm).then (project) =>
@analytics.trackEvent("project", "create", "project creation", {slug: project.get('slug'), id: project.get('id')})
@location.url(@projectUrl.get(project)) @location.url(@projectUrl.get(project))
onCancelForm: () -> onCancelForm: () ->

View File

@ -22,12 +22,15 @@ class ImportTaigaController
'$tgConfirm', '$tgConfirm',
'$tgResources', '$tgResources',
'tgImportProjectService', 'tgImportProjectService',
'$translate' '$translate',
'$tgAnalytics',
] ]
constructor: (@confirm, @rs, @importProjectService, @translate) -> constructor: (@confirm, @rs, @importProjectService, @translate, @analytics) ->
importTaiga: (files) -> importTaiga: (files) ->
@analytics.trackEvent("import", "taiga", "Start import from taiga", 1)
file = files[0] file = files[0]
loader = @confirm.loader(@translate.instant('PROJECT.IMPORT.IN_PROGRESS.TITLE'), @translate.instant('PROJECT.IMPORT.IN_PROGRESS.DESCRIPTION'), true) loader = @confirm.loader(@translate.instant('PROJECT.IMPORT.IN_PROGRESS.TITLE'), @translate.instant('PROJECT.IMPORT.IN_PROGRESS.DESCRIPTION'), true)

View File

@ -29,9 +29,12 @@ class ImportProjectController
'$tgNavUrls', '$tgNavUrls',
'$tgConfig', '$tgConfig',
'$tgConfirm', '$tgConfirm',
'$tgAnalytics',
] ]
constructor: (@trelloService, @jiraService, @githubService, @asanaService, @location, @window, @routeParams, @tgNavUrls, @config, @confirm) -> constructor: (@trelloService, @jiraService, @githubService, @asanaService,
@location, @window, @routeParams, @tgNavUrls, @config, @confirm,
@analytics) ->
start: -> start: ->
@.token = null @.token = null
@ -39,6 +42,9 @@ class ImportProjectController
locationSearch = @location.search() locationSearch = @location.search()
if @.from
@analytics.trackEvent("import", @.from, "Start import from "+@.from, 1)
if @.from == "asana" if @.from == "asana"
asanaOauthToken = locationSearch.code asanaOauthToken = locationSearch.code
if locationSearch.code if locationSearch.code