diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index aa27109d9..7bc4b5274 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -41,6 +41,7 @@ //= require registration_form //= require suggest //= require forms +//= require tracks var initialize_modules = function() { App.Comments.initialize(); @@ -57,6 +58,7 @@ var initialize_modules = function() { App.RegistrationForm.initialize(); App.Suggest.initialize(); App.Forms.initialize(); + App.Tracks.initialize(); }; $(function(){ diff --git a/app/assets/javascripts/tracks.js.coffee b/app/assets/javascripts/tracks.js.coffee new file mode 100644 index 000000000..1b6cfe82e --- /dev/null +++ b/app/assets/javascripts/tracks.js.coffee @@ -0,0 +1,28 @@ +App.Tracks = + + tracking_enabled: -> + _paq? + + set_custom_var: (id, name, value, scope) -> + _paq.push(['setCustomVariable', id, name, value, scope]) + _paq.push(['trackPageView']) + + track_event: ($this) -> + category = $this.data('track-event-category') + action = $this.data('track-event-action') + _paq.push(['trackEvent', category, action]) + + initialize: -> + if App.Tracks.tracking_enabled() + $('[data-track-usertype]').each -> + $this = $(this) + usertype = $this.data('track-usertype') + App.Tracks.set_custom_var(1, "usertype", usertype, "visit") + + $('[data-track-event-category]').each -> + $this = $(this) + App.Tracks.track_event($this) + + $('[data-track-click]').on 'click', -> + $this = $(this) + App.Tracks.track_event($this) diff --git a/app/controllers/admin/stats_controller.rb b/app/controllers/admin/stats_controller.rb index ec5c2d19d..f724a054c 100644 --- a/app/controllers/admin/stats_controller.rb +++ b/app/controllers/admin/stats_controller.rb @@ -18,6 +18,10 @@ class Admin::StatsController < Admin::BaseController @verified_users = User.with_hidden.level_two_or_three_verified.count @unverified_users = User.with_hidden.unverified.count @users = User.with_hidden.count + + @user_ids_who_voted_proposals = + ActsAsVotable::Vote.where(votable_type: 'Proposal').pluck(:voter_id).uniq.count + @user_ids_who_didnt_vote_proposals = @verified_users - @user_ids_who_voted_proposals end end diff --git a/app/helpers/tracks_helper.rb b/app/helpers/tracks_helper.rb new file mode 100644 index 000000000..53c110d49 --- /dev/null +++ b/app/helpers/tracks_helper.rb @@ -0,0 +1,12 @@ +module TracksHelper + def track_event(data={}) + track_data = "" + prefix = " data-track-event-" + data.each do |key, value| + track_data = track_data + prefix + key.to_s + '=' + value + " " + end + content_for :track_event do + track_data + end + end +end \ No newline at end of file diff --git a/app/models/concerns/verification.rb b/app/models/concerns/verification.rb index 3520e5b31..c876ef5ed 100644 --- a/app/models/concerns/verification.rb +++ b/app/models/concerns/verification.rb @@ -53,7 +53,18 @@ module Verification def no_phone_available? !verification_sms_sent? end - + + def user_type + case + when level_three_verified? + :level_3_user + when level_two_verified? + :level_2_user + else + :level_1_user + end + end + def sms_code_not_confirmed? !sms_verified? end diff --git a/app/views/admin/stats/show.html.erb b/app/views/admin/stats/show.html.erb index 84abd7be9..93b6be821 100644 --- a/app/views/admin/stats/show.html.erb +++ b/app/views/admin/stats/show.html.erb @@ -76,6 +76,13 @@ <%= t "admin.stats.show.summary.user_level_three" %>
<%= number_with_delimiter(@user_level_three) %>

+ +

+ <%= t "admin.stats.show.summary.verified_users_who_didnt_vote_proposals" %>
+ + <%=number_with_delimiter(@user_ids_who_didnt_vote_proposals)%> + +

diff --git a/app/views/layouts/_tracking_data.html.erb b/app/views/layouts/_tracking_data.html.erb new file mode 100644 index 000000000..a0be1bafa --- /dev/null +++ b/app/views/layouts/_tracking_data.html.erb @@ -0,0 +1 @@ +/> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index ff41ea1ea..e7c5fdf56 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -4,6 +4,7 @@ + <%=render "layouts/tracking_data"%> <%= content_for?(:title) ? yield(:title) : setting['org_name'] %> <%= stylesheet_link_tag "application" %> <%= javascript_include_tag "application", 'data-turbolinks-track' => true %> diff --git a/app/views/verification/letter/edit.html.erb b/app/views/verification/letter/edit.html.erb index c792e219d..5ca194d33 100644 --- a/app/views/verification/letter/edit.html.erb +++ b/app/views/verification/letter/edit.html.erb @@ -1,4 +1,5 @@
+ <%track_event(category: "verification", action: "edit_letter" )%>

diff --git a/app/views/verification/letter/new.html.erb b/app/views/verification/letter/new.html.erb index 130fb106c..9bd6a2ddd 100644 --- a/app/views/verification/letter/new.html.erb +++ b/app/views/verification/letter/new.html.erb @@ -1,4 +1,5 @@