track user verification and add statistics of verified users who did not vote proposals
This commit is contained in:
@@ -41,6 +41,7 @@
|
|||||||
//= require registration_form
|
//= require registration_form
|
||||||
//= require suggest
|
//= require suggest
|
||||||
//= require forms
|
//= require forms
|
||||||
|
//= require tracks
|
||||||
|
|
||||||
var initialize_modules = function() {
|
var initialize_modules = function() {
|
||||||
App.Comments.initialize();
|
App.Comments.initialize();
|
||||||
@@ -57,6 +58,7 @@ var initialize_modules = function() {
|
|||||||
App.RegistrationForm.initialize();
|
App.RegistrationForm.initialize();
|
||||||
App.Suggest.initialize();
|
App.Suggest.initialize();
|
||||||
App.Forms.initialize();
|
App.Forms.initialize();
|
||||||
|
App.Tracks.initialize();
|
||||||
};
|
};
|
||||||
|
|
||||||
$(function(){
|
$(function(){
|
||||||
|
|||||||
28
app/assets/javascripts/tracks.js.coffee
Normal file
28
app/assets/javascripts/tracks.js.coffee
Normal file
@@ -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)
|
||||||
@@ -18,6 +18,10 @@ class Admin::StatsController < Admin::BaseController
|
|||||||
@verified_users = User.with_hidden.level_two_or_three_verified.count
|
@verified_users = User.with_hidden.level_two_or_three_verified.count
|
||||||
@unverified_users = User.with_hidden.unverified.count
|
@unverified_users = User.with_hidden.unverified.count
|
||||||
@users = User.with_hidden.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
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
12
app/helpers/tracks_helper.rb
Normal file
12
app/helpers/tracks_helper.rb
Normal file
@@ -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
|
||||||
@@ -54,6 +54,17 @@ module Verification
|
|||||||
!verification_sms_sent?
|
!verification_sms_sent?
|
||||||
end
|
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?
|
def sms_code_not_confirmed?
|
||||||
!sms_verified?
|
!sms_verified?
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -76,6 +76,13 @@
|
|||||||
<%= t "admin.stats.show.summary.user_level_three" %><br>
|
<%= t "admin.stats.show.summary.user_level_three" %><br>
|
||||||
<span class="number"><%= number_with_delimiter(@user_level_three) %></span>
|
<span class="number"><%= number_with_delimiter(@user_level_three) %></span>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<%= t "admin.stats.show.summary.verified_users_who_didnt_vote_proposals" %><br>
|
||||||
|
<span class="number">
|
||||||
|
<%=number_with_delimiter(@user_ids_who_didnt_vote_proposals)%>
|
||||||
|
</span>
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
1
app/views/layouts/_tracking_data.html.erb
Normal file
1
app/views/layouts/_tracking_data.html.erb
Normal file
@@ -0,0 +1 @@
|
|||||||
|
<meta name="tracking_data" data-track-usertype="<%=current_user ? current_user.user_type : :anonymous%>" <%= yield(:track_event) %>/>
|
||||||
@@ -4,6 +4,7 @@
|
|||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||||
|
<%=render "layouts/tracking_data"%>
|
||||||
<title><%= content_for?(:title) ? yield(:title) : setting['org_name'] %></title>
|
<title><%= content_for?(:title) ? yield(:title) : setting['org_name'] %></title>
|
||||||
<%= stylesheet_link_tag "application" %>
|
<%= stylesheet_link_tag "application" %>
|
||||||
<%= javascript_include_tag "application", 'data-turbolinks-track' => true %>
|
<%= javascript_include_tag "application", 'data-turbolinks-track' => true %>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<div class="row verify">
|
<div class="row verify">
|
||||||
|
<%track_event(category: "verification", action: "edit_letter" )%>
|
||||||
<div class="small-12 medium-9 large-6 small-centered column">
|
<div class="small-12 medium-9 large-6 small-centered column">
|
||||||
<div class="text-center">
|
<div class="text-center">
|
||||||
<h1>
|
<h1>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<div class="verification account row">
|
<div class="verification account row">
|
||||||
|
<%track_event(category: "verification", action: "success_sms" )%>
|
||||||
<div class="small-12 column">
|
<div class="small-12 column">
|
||||||
|
|
||||||
<div class="text-center">
|
<div class="text-center">
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
|
<%track_event(category: "verification", action: "start_letter" )%>
|
||||||
<div class="small-12 column">
|
<div class="small-12 column">
|
||||||
|
|
||||||
<%= link_to account_path, class: "back" do %>
|
<%= link_to account_path, class: "back" do %>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<div class="verification account row">
|
<div class="verification account row">
|
||||||
|
<%track_event(category: "verification", action: "start_census" )%>
|
||||||
<div class="small-12 column">
|
<div class="small-12 column">
|
||||||
|
|
||||||
<div class="text-center">
|
<div class="text-center">
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<div class="verification account row">
|
<div class="verification account row">
|
||||||
|
<%track_event(category: "verification", action: "start_sms" )%>
|
||||||
<div class="small-12 column">
|
<div class="small-12 column">
|
||||||
<div class="text-center">
|
<div class="text-center">
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<div class="verification account row">
|
<div class="verification account row">
|
||||||
|
<%track_event(category: "verification", action: "success_census" )%>
|
||||||
<div class="small-12 column">
|
<div class="small-12 column">
|
||||||
<div class="text-center">
|
<div class="text-center">
|
||||||
|
|
||||||
|
|||||||
@@ -198,6 +198,7 @@ en:
|
|||||||
user_level_two: Level two users
|
user_level_two: Level two users
|
||||||
users: Total users
|
users: Total users
|
||||||
verified_users: Verified users
|
verified_users: Verified users
|
||||||
|
verified_users_who_didnt_vote_proposals: Verified users who didn't votes proposals
|
||||||
visits: Visits
|
visits: Visits
|
||||||
votes: Total votes
|
votes: Total votes
|
||||||
visits_title: Visits
|
visits_title: Visits
|
||||||
|
|||||||
@@ -198,6 +198,7 @@ es:
|
|||||||
user_level_two: Usuarios de nivel dos
|
user_level_two: Usuarios de nivel dos
|
||||||
users: Usuarios
|
users: Usuarios
|
||||||
verified_users: Usuarios verificados
|
verified_users: Usuarios verificados
|
||||||
|
verified_users_who_didnt_vote_proposals: Usuarios verificados que no han votado propuestas
|
||||||
visits: Visitas
|
visits: Visitas
|
||||||
votes: Votos
|
votes: Votos
|
||||||
visits_title: Visitas
|
visits_title: Visitas
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ Setting.create(key: 'feature.spending_proposals', value: "true")
|
|||||||
Setting.create(key: 'feature.twitter_login', value: "true")
|
Setting.create(key: 'feature.twitter_login', value: "true")
|
||||||
Setting.create(key: 'feature.facebook_login', value: "true")
|
Setting.create(key: 'feature.facebook_login', value: "true")
|
||||||
Setting.create(key: 'feature.google_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')
|
Setting.create(key: 'comments_body_max_length', value: '1000')
|
||||||
|
|
||||||
puts "Creating Geozones"
|
puts "Creating Geozones"
|
||||||
|
|||||||
134
spec/features/tracks_spec.rb
Normal file
134
spec/features/tracks_spec.rb
Normal file
@@ -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
|
||||||
Reference in New Issue
Block a user