diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js
index a688ae0b3..e24d144bb 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
//= require valuation_spending_proposal_form
//= require embed_video
@@ -59,6 +60,7 @@ var initialize_modules = function() {
App.RegistrationForm.initialize();
App.Suggest.initialize();
App.Forms.initialize();
+ App.Tracks.initialize();
App.ValuationSpendingProposalForm.initialize();
App.EmbedVideo.initialize();
};
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 7183c3767..f21ceea9b 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
@spending_proposals = SpendingProposal.count
+
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..4eb933204 100644
--- a/app/models/concerns/verification.rb
+++ b/app/models/concerns/verification.rb
@@ -54,6 +54,17 @@ module Verification
!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 e043016be..9a9ecbfa8 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 6225f79c1..ea4fcb107 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 0f280f783..3841ccb4f 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 ab2066b70..01d0f0e01 100644
--- a/app/views/verification/letter/new.html.erb
+++ b/app/views/verification/letter/new.html.erb
@@ -1,4 +1,5 @@
+ <%track_event(category: "verification", action: "success_sms" )%>
diff --git a/app/views/verification/letter/show.html.erb b/app/views/verification/letter/show.html.erb
index f80a9690c..e5189a476 100644
--- a/app/views/verification/letter/show.html.erb
+++ b/app/views/verification/letter/show.html.erb
@@ -1,4 +1,5 @@
+ <%track_event(category: "verification", action: "start_letter" )%>
<%= link_to account_path, class: "back" do %>
diff --git a/app/views/verification/residence/new.html.erb b/app/views/verification/residence/new.html.erb
index 23c79ca0e..0949e9511 100644
--- a/app/views/verification/residence/new.html.erb
+++ b/app/views/verification/residence/new.html.erb
@@ -1,4 +1,5 @@
+ <%track_event(category: "verification", action: "start_census" )%>
diff --git a/app/views/verification/sms/edit.html.erb b/app/views/verification/sms/edit.html.erb
index 7e11af9d5..d1856e88c 100644
--- a/app/views/verification/sms/edit.html.erb
+++ b/app/views/verification/sms/edit.html.erb
@@ -1,4 +1,5 @@
+ <%track_event(category: "verification", action: "start_sms" )%>
diff --git a/app/views/verification/sms/new.html.erb b/app/views/verification/sms/new.html.erb
index 4af6a4dfb..06f679e36 100644
--- a/app/views/verification/sms/new.html.erb
+++ b/app/views/verification/sms/new.html.erb
@@ -1,4 +1,5 @@
+ <%track_event(category: "verification", action: "success_census" )%>
diff --git a/config/locales/admin.en.yml b/config/locales/admin.en.yml
index 96023f69c..912067443 100755
--- a/config/locales/admin.en.yml
+++ b/config/locales/admin.en.yml
@@ -206,6 +206,7 @@ en:
user_level_two: Level two users
users: Total users
verified_users: Verified users
+ verified_users_who_didnt_vote_proposals: Verified users who didn't votes proposals
visits: Visits
votes: Total votes
spending_proposals_title: Spending Proposals
diff --git a/config/locales/admin.es.yml b/config/locales/admin.es.yml
index 345a3716c..71c75914b 100644
--- a/config/locales/admin.es.yml
+++ b/config/locales/admin.es.yml
@@ -206,6 +206,7 @@ es:
user_level_two: Usuarios de nivel dos
users: Usuarios
verified_users: Usuarios verificados
+ verified_users_who_didnt_vote_proposals: Usuarios verificados que no han votado propuestas
visits: Visitas
votes: Votos
spending_proposals_title: Propuestas de inversión
diff --git a/db/dev_seeds.rb b/db/dev_seeds.rb
index e4365d244..5a97a3aec 100644
--- a/db/dev_seeds.rb
+++ b/db/dev_seeds.rb
@@ -25,7 +25,8 @@ Setting.create(key: 'feature.spending_proposal_features.voting_allowed', value:
Setting.create(key: 'feature.twitter_login', value: "true")
Setting.create(key: 'feature.facebook_login', value: "true")
Setting.create(key: 'feature.google_login', value: "true")
-
+Setting.create(key: 'per_page_code', value: "")
+Setting.create(key: 'comments_body_max_length', value: '1000')
puts "Creating Geozones"
('A'..'Z').each{ |i| Geozone.create(name: "District #{i}") }
diff --git a/spec/features/tracks_spec.rb b/spec/features/tracks_spec.rb
new file mode 100644
index 000000000..059d2f679
--- /dev/null
+++ b/spec/features/tracks_spec.rb
@@ -0,0 +1,134 @@
+require 'rails_helper'
+
+feature 'Tracking' do
+
+ context 'Custom variable' do
+
+ scenario 'Usertype anonymous' do
+ visit proposals_path
+
+ expect(page.html).to include "anonymous"
+ end
+
+ scenario 'Usertype level_1_user' do
+ create(:geozone)
+ user = create(:user)
+ login_as(user)
+
+ visit proposals_path
+
+ expect(page.html).to include "level_1_user"
+ end
+
+ scenario 'Usertype level_2_user' do
+ create(:geozone)
+ user = create(:user)
+ login_as(user)
+
+ visit account_path
+ click_link 'Verify my account'
+
+ verify_residence
+
+ fill_in 'sms_phone', with: "611111111"
+ click_button 'Send'
+
+ user = user.reload
+ fill_in 'sms_confirmation_code', with: user.sms_confirmation_code
+ click_button 'Send'
+
+ expect(page.html).to include "level_2_user"
+ end
+ end
+
+ context 'Tracking events' do
+ scenario 'Verification: start census' do
+ user = create(:user)
+ login_as(user)
+
+ visit account_path
+ click_link 'Verify my account'
+
+ expect(page.html).to include "data-track-event-category=verification"
+ expect(page.html).to include "data-track-event-action=start_census"
+ end
+
+ scenario 'Verification: success census' do
+ create(:geozone)
+ user = create(:user)
+ login_as(user)
+
+ visit account_path
+ click_link 'Verify my account'
+
+ verify_residence
+
+ fill_in 'sms_phone', with: "611111111"
+ click_button 'Send'
+
+ expect(page.html).to include "data-track-event-category=verification"
+ expect(page.html).to include "data-track-event-action=start_sms"
+ end
+
+ scenario 'Verification: start sms' do
+ create(:geozone)
+ user = create(:user)
+ login_as(user)
+
+ visit account_path
+ click_link 'Verify my account'
+
+ verify_residence
+
+ fill_in 'sms_phone', with: "611111111"
+ click_button 'Send'
+
+ expect(page.html).to include "data-track-event-category=verification"
+ expect(page.html).to include "data-track-event-action=start_sms"
+ end
+
+ scenario 'Verification: success sms' do
+ create(:geozone)
+ user = create(:user)
+ login_as(user)
+
+ visit account_path
+ click_link 'Verify my account'
+
+ verify_residence
+
+ fill_in 'sms_phone', with: "611111111"
+ click_button 'Send'
+
+ user = user.reload
+ fill_in 'sms_confirmation_code', with: user.sms_confirmation_code
+ click_button 'Send'
+
+ expect(page.html).to include "data-track-event-category=verification"
+ expect(page.html).to include "data-track-event-action=success_sms"
+ end
+
+ scenario 'Verification: letter' do
+ create(:geozone)
+ user = create(:user)
+ login_as(user)
+
+ visit account_path
+ click_link 'Verify my account'
+
+ verify_residence
+
+ fill_in 'sms_phone', with: "611111111"
+ click_button 'Send'
+
+ user = user.reload
+ fill_in 'sms_confirmation_code', with: user.sms_confirmation_code
+ click_button 'Send'
+
+ click_link "Send me a letter with the code"
+
+ expect(page.html).to include "data-track-event-category=verification"
+ expect(page.html).to include "data-track-event-action=start_letter"
+ end
+ end
+end