tracks visits from different email templates
This commit is contained in:
@@ -11,6 +11,7 @@ class ApplicationController < ActionController::Base
|
|||||||
|
|
||||||
before_action :ensure_signup_complete
|
before_action :ensure_signup_complete
|
||||||
before_action :set_locale
|
before_action :set_locale
|
||||||
|
before_action :track_email_campaign
|
||||||
|
|
||||||
check_authorization unless: :devise_controller?
|
check_authorization unless: :devise_controller?
|
||||||
self.responder = ApplicationResponder
|
self.responder = ApplicationResponder
|
||||||
@@ -107,4 +108,11 @@ class ApplicationController < ActionController::Base
|
|||||||
redirect_to(account_path, notice: t('verification.redirect_notices.already_verified'))
|
redirect_to(account_path, notice: t('verification.redirect_notices.already_verified'))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def track_email_campaign
|
||||||
|
if params[:track_id]
|
||||||
|
campaign = Campaign.where(track_id: params[:track_id]).first
|
||||||
|
ahoy.track campaign.name if campaign.present?
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
2
app/models/campaign.rb
Normal file
2
app/models/campaign.rb
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
class Campaign < ActiveRecord::Base
|
||||||
|
end
|
||||||
10
db/migrate/20151020135111_create_campaigns.rb
Normal file
10
db/migrate/20151020135111_create_campaigns.rb
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
class CreateCampaigns < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
create_table :campaigns do |t|
|
||||||
|
t.string :name
|
||||||
|
t.string :track_id
|
||||||
|
|
||||||
|
t.timestamps null: false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -12,7 +12,6 @@
|
|||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20151021113348) do
|
ActiveRecord::Schema.define(version: 20151021113348) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
|
|
||||||
@@ -48,6 +47,13 @@ ActiveRecord::Schema.define(version: 20151021113348) do
|
|||||||
add_index "ahoy_events", ["user_id"], name: "index_ahoy_events_on_user_id", using: :btree
|
add_index "ahoy_events", ["user_id"], name: "index_ahoy_events_on_user_id", using: :btree
|
||||||
add_index "ahoy_events", ["visit_id"], name: "index_ahoy_events_on_visit_id", using: :btree
|
add_index "ahoy_events", ["visit_id"], name: "index_ahoy_events_on_visit_id", using: :btree
|
||||||
|
|
||||||
|
create_table "campaigns", force: :cascade do |t|
|
||||||
|
t.string "name"
|
||||||
|
t.string "track_id"
|
||||||
|
t.datetime "created_at", null: false
|
||||||
|
t.datetime "updated_at", null: false
|
||||||
|
end
|
||||||
|
|
||||||
create_table "comments", force: :cascade do |t|
|
create_table "comments", force: :cascade do |t|
|
||||||
t.integer "commentable_id"
|
t.integer "commentable_id"
|
||||||
t.string "commentable_type"
|
t.string "commentable_type"
|
||||||
|
|||||||
8
lib/tasks/campaigns.rake
Normal file
8
lib/tasks/campaigns.rake
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
namespace :campagins do
|
||||||
|
|
||||||
|
desc "Recalculates all the comment counters for debates and proposals"
|
||||||
|
task create: :environment do
|
||||||
|
3.times { |i| Campaign.create!(name: "Campaign#{i+1}", track_id: rand(2**32..2**64)) }
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
@@ -268,4 +268,9 @@ FactoryGirl.define do
|
|||||||
started_at DateTime.now
|
started_at DateTime.now
|
||||||
end
|
end
|
||||||
|
|
||||||
|
factory :campaign do
|
||||||
|
sequence(:name) { |n| "Campaign #{n}" }
|
||||||
|
sequence(:track_id) { |n| "#{n}" }
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
33
spec/features/campaigns_spec.rb
Normal file
33
spec/features/campaigns_spec.rb
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
feature 'Email campaigns' do
|
||||||
|
|
||||||
|
background do
|
||||||
|
@campaign1 = create(:campaign)
|
||||||
|
@campaign2 = create(:campaign)
|
||||||
|
|
||||||
|
admin = create(:administrator)
|
||||||
|
login_as(admin.user)
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Track email templates" do
|
||||||
|
3.times { visit root_url(track_id: @campaign1.track_id) }
|
||||||
|
5.times { visit root_url(track_id: @campaign2.track_id) }
|
||||||
|
|
||||||
|
visit admin_stats_path
|
||||||
|
|
||||||
|
expect(page).to have_content "#{@campaign1.name} (3)"
|
||||||
|
expect(page).to have_content "#{@campaign2.name} (5)"
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Do not track erroneous track_ids" do
|
||||||
|
visit root_url(track_id: @campaign1.track_id)
|
||||||
|
visit root_url(track_id: "999")
|
||||||
|
|
||||||
|
visit admin_stats_path
|
||||||
|
|
||||||
|
expect(page).to have_content "#{@campaign1.name} (1)"
|
||||||
|
expect(page).to_not have_content "#{@campaign2.name}"
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user