Every campaign has an end.

Drop ahoy, because it's more trouble than it's worth. This means dropping
visits, campaigns, targets.

Campaigns are better run to analytics, such as:
* https://matomo.org/docs/tracking-campaigns/
* https://matomo.org/docs/tracking-goals-web-analytics/
* https://support.google.com/analytics/answer/1012040?hl=en
This commit is contained in:
James Mason 2018-10-08 17:58:41 -07:00 committed by Henne Vogelsang
parent 62056fc044
commit b11001cdba
47 changed files with 19 additions and 1420 deletions

View file

@ -22,7 +22,6 @@
//= require bootstrap
//= require osem
//= require osem-dashboard
//= require ahoy
//= require jquery-smooth-scroll
//= require trianglify
//= require tinycolor

View file

@ -112,19 +112,4 @@ $(function () {
$("#registration-period-end-datepicker").on("dp.change",function (e) {
$('#registration-period-start-datepicker').data("DateTimePicker").setMaxDate(e.date);
});
$(".target-due-date-datepicker").datetimepicker({
pickTime: false,
format: "YYYY-MM-DD"
});
/* Appends the datetimepicker to new injected nested target fields. */
$('a:contains("Add target")').click(function () {
setTimeout(function () {
$('.target-due-date-datepicker').not('.hasDatepicker').datetimepicker({
pickTime: false,
format: "YYYY-MM-DD"
});
},
5)
});
} );

View file

@ -89,31 +89,6 @@ $(function () {
}
}
/**
/**
* Opens a prompt with the URL to copy to clipboard.
* Used in the campaign index view.
*/
$('.copyLink').on('click', function(){
var url = $(this).data('url');
copyToClipboard(url);
})
function copyToClipboard(text) {
window.prompt("Copy to clipboard: Ctrl+C, Enter", text);
}
/**
* Toggles the targets on the conference site with a more / less link.
*/
$('.show_targets').click(function () {
if($(this).text().trim() == 'more'){
$(this).text("less");
}else{
$(this).text("more");
}
$('#' + $(this).data('name')).toggle();
});
$(".comment-reply-link").click(function(){
$(".comment-reply", $(this).parent()).toggle();
return false;

View file

@ -1,56 +0,0 @@
# frozen_string_literal: true
module Admin
class CampaignsController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title
load_and_authorize_resource :campaign, through: :conference
def index
authorize! :index, Campaign.new(conference_id: @conference.id)
@campaigns = @conference.campaigns
end
def create
@campaign.attributes = campaign_params
if @conference.save
redirect_to admin_conference_campaigns_path(conference_id: @conference.short_title),
notice: 'Campaign successfully created.'
else
flash.now[:error] = 'Campaign creation failed. ' + @campaign.errors.full_messages.to_sentence
render action: 'new'
end
end
def new; end
def edit; end
def update
if @campaign.update_attributes(campaign_params)
redirect_to admin_conference_campaigns_path(conference_id: @conference.short_title),
notice: "Campaign '#{@campaign.name}' successfully updated."
else
flash.now[:error] = "Campaign update failed. #{@campaign.errors.full_messages.to_sentence}"
render action: 'edit'
end
end
def destroy
if @campaign.destroy
redirect_to admin_conference_campaigns_path(conference_id: @conference.short_title),
notice: "Campaign '#{@campaign.name}' successfully deleted."
else
redirect_to admin_conference_campaigns_path(conference_id: @conference.short_title),
error: "Delete of Campaign for #{@conference.short_title} failed."\
"#{@campaign.errors.full_messages.join('. ')}."
end
end
private
def campaign_params
params.require(:campaign).permit(:name, :utm_source, :utm_medium, :utm_term, :utm_content, :utm_campaign, :target_ids, :conference_id)
end
end
end

View file

@ -189,14 +189,6 @@ module Admin
@top_submitter = @conference.get_top_submitter
# get targets
@registration_targets = @conference.get_targets(Target.units[:registrations])
@submission_targets = @conference.get_targets(Target.units[:submissions])
@program_minutes_targets = @conference.get_targets(Target.units[:program_minutes])
# get campaigns
@campaigns = @conference.get_campaigns
respond_to do |format|
format.html
format.json { render json: @conference.to_json }
@ -225,8 +217,8 @@ module Admin
:use_vpositions, :use_vdays, :vdays_attributes,
:vpositions_attributes, :use_volunteers, :color,
:sponsorship_levels_attributes, :sponsors_attributes,
:targets, :targets_attributes,
:campaigns, :campaigns_attributes, :registration_limit, :organization_id, :ticket_layout, :booth_limit)
:registration_limit, :organization_id, :ticket_layout,
:booth_limit)
end
end
end

View file

@ -92,7 +92,6 @@ module Admin
@event.submitter = current_user
if @event.save
ahoy.track 'Event submission', title: 'New submission'
redirect_to admin_conference_program_events_path(@conference.short_title), notice: 'Event was successfully submitted.'
else
flash.now[:error] = "Could not submit proposal: #{@event.errors.full_messages.join(', ')}"

View file

@ -1,54 +0,0 @@
# frozen_string_literal: true
module Admin
class TargetsController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title
load_and_authorize_resource :target, through: :conference
def index; end
def new
@target = @conference.targets.new
end
def create
@target = @conference.targets.new(target_params)
if @target.save(target_params)
redirect_to admin_conference_targets_path(conference_id: @conference.short_title),
notice: 'Target successfully created.'
else
flash.now[:error] = "Creating target failed: #{@target.errors.full_messages.join('. ')}."
render :new
end
end
def edit; end
def update
if @target.update_attributes(target_params)
redirect_to admin_conference_targets_path(conference_id: @conference.short_title),
notice: 'Target successfully updated.'
else
flash.now[:error] = "Target update failed: #{@target.errors.full_messages.join('. ')}."
render :edit
end
end
def destroy
if @target.destroy
redirect_to admin_conference_targets_path(conference_id: @conference.short_title),
notice: 'Target successfully destroyed.'
else
redirect_to admin_conference_targets_path(conference_id: @conference.short_title),
error: "Could not delete target for #{@conference.title}: "\
"#{@target.errors.full_messages.join('. ')}."
end
end
private
def target_params
params.require(:target).permit(:due_date, :target_count, :unit, :conference_id)
end
end
end

View file

@ -52,9 +52,6 @@ class ConferenceRegistrationsController < ApplicationController
authorize! :create, @registration
if @registration.save
# Trigger ahoy event
ahoy.track 'Registered', title: 'New registration'
# Sign in the new user
unless current_user
sign_in(@registration.user)

View file

@ -61,7 +61,6 @@ class ProposalsController < ApplicationController
end
if @event.save
ahoy.track 'Event submission', title: 'New submission'
Mailbot.submitted_proposal_mail(@event).deliver_later if @conference.email_settings.send_on_submitted_proposal
redirect_to conference_program_proposals_path(@conference.short_title), notice: 'Proposal was successfully submitted.'
else

View file

@ -114,8 +114,6 @@ class AdminAbility
can :manage, Splashpage, conference_id: conf_ids
can :manage, Contact, conference_id: conf_ids
can :manage, EmailSettings, conference_id: conf_ids
can :manage, Campaign, conference_id: conf_ids
can :manage, Target, conference_id: conf_ids
can :manage, Commercial, commercialable_type: 'Conference',
commercialable_id: conf_ids
can :manage, Registration, conference_id: conf_ids

View file

@ -1,13 +0,0 @@
# frozen_string_literal: true
module Ahoy
class Event < ApplicationRecord
include Ahoy::QueryMethods
self.table_name = 'ahoy_events'
belongs_to :visit
belongs_to :user
serialize :properties, JSON
end
end

View file

@ -1,78 +0,0 @@
# frozen_string_literal: true
class Campaign < ApplicationRecord
validates :name, :utm_campaign, presence: true
has_many :targets, dependent: :nullify
belongs_to :conference
has_paper_trail ignore: [:updated_at], meta: { conference_id: :conference_id }
##
# Returns the utm parameters formatted as url.
#
# ====Returns
# * +String+ -> url parameters e.g. ?utm_source=facebook
def url_parameters
kv = []
get_parameters.each_pair do |k, v|
kv += ["#{k}=#{v}"]
end
'?' + kv.join('&') unless kv.empty?
end
##
# Returns the counted visits generated by this campaign.
#
# ====Returns
# * +Fixnum+ -> visits
def visits_count
Visit.where(get_parameters).where('started_at > ?', created_at).count
end
##
# Returns the counted registrations generated by this campaign.
#
# ====Returns
# * +Fixnum+ -> visits
def registrations_count
events_by_name('Registered')
end
##
# Returns the counted event submissions generated by this campaign.
#
# ====Returns
# * +Fixnum+ -> visits
def submissions_count
events_by_name('Event submission')
end
private
##
# Helper method for submissions and registrations.
#
# ====Returns
# * +Fixnum+ -> registrations / submissions
def events_by_name(event_name)
parameters = get_parameters
parameters['ahoy_events.name'] = event_name
Visit.joins(:ahoy_events).where(parameters).where('started_at > ?', created_at).count
end
##
# Helper method to get the parameters for queries.
#
# ====Returns
# * +Hash+ -> parameter => value
def get_parameters
conditions = {}
conditions[:utm_source] = self[:utm_source] unless self[:utm_source].blank?
conditions[:utm_medium] = self[:utm_medium] unless self[:utm_medium].blank?
conditions[:utm_term] = self[:utm_term] unless self[:utm_term].blank?
conditions[:utm_content] = self[:utm_content] unless self[:utm_content].blank?
conditions[:utm_campaign] = self[:utm_campaign] unless self[:utm_campaign].blank?
conditions
end
end

View file

@ -45,8 +45,6 @@ class Conference < ApplicationRecord
has_many :vpositions, dependent: :destroy
has_many :sponsorship_levels, -> { order('position ASC') }, dependent: :destroy
has_many :sponsors, dependent: :destroy
has_many :targets, dependent: :destroy
has_many :campaigns, dependent: :destroy
has_many :commercials, as: :commercialable, dependent: :destroy
has_many :subscriptions, dependent: :destroy
has_one :call_for_events, -> { where(cfp_type: 'events') }, through: :program, source: :cfps
@ -76,8 +74,6 @@ class Conference < ApplicationRecord
accepts_nested_attributes_for :questions, allow_destroy: true
accepts_nested_attributes_for :vdays, allow_destroy: true
accepts_nested_attributes_for :vpositions, allow_destroy: true
accepts_nested_attributes_for :targets, allow_destroy: true
accepts_nested_attributes_for :campaigns, allow_destroy: true
mount_uploader :picture, PictureUploader, mount_on: :logo_file_name
@ -640,35 +636,6 @@ class Conference < ApplicationRecord
]
end
##
# A map with all conference targets with progress in percent of a certain unit.
#
# ====Returns
# * +Map+ -> target => progress
def get_targets(target_unit)
conference_target = targets.where('unit = ?', target_unit)
result = {}
conference_target.each do |target|
result[target.to_s] = target.get_progress
end
result
end
##
# A map with all conference campaigns associated with targets.
#
# ====Returns
# * +Map+ -> campaign => {actual, target, progress}
def get_campaigns
result = {}
campaigns.each do |campaign|
campaign.targets.each do |target|
result["#{target} from #{campaign.name}"] = target.get_campaign
end
end
result
end
##
# Writes an snapshot of the actual event distribution to the database
# Triggered each every Sunday 11:55 pm form whenever (config/schedule.rb).

View file

@ -1,85 +0,0 @@
# frozen_string_literal: true
class Target < ApplicationRecord
include ActionView::Helpers::TextHelper
default_scope { order('due_date ASC') }
has_paper_trail ignore: [:updated_at], meta: { conference_id: :conference_id }
def self.units
{
registrations: 'Registration',
submissions: 'Submission',
program_minutes: 'Program minute'
}
end
validates :due_date, :target_count, :unit, presence: true
validates :target_count,
allow_nil: false,
numericality: { only_integer: true, greater_than: 0 }
validates :unit, allow_nil: false, inclusion: { in: Target.units.values }
belongs_to :conference
belongs_to :campaign
##
# Returns the actual progress of the target in percent.
#
# ====Returns
# * +String+ -> progress in percent
def get_progress
numerator =
case unit
when Target.units[:submissions]
conference.program.events.where('created_at < ?', due_date).count
when Target.units[:registrations]
conference.registrations.where('created_at < ?', due_date).count
when Target.units[:program_minutes]
conference.current_program_minutes
else
0
end
(100 * numerator / target_count).to_s
end
##
# Returns a hash with values of the corresponding campaign.
#
# ====Returns
# * +Hash+ -> target_name, campaign_name, value, unit, created_at, progress, days_left
def get_campaign
numerator = 0
if unit == Target.units[:submissions]
numerator = campaign.submissions_count
elsif unit == Target.units[:registrations]
numerator = campaign.registrations_count
elsif unit == Target.units[:program_minutes]
numerator = conference.current_program_minutes
end
progress = (numerator / target_count.to_f * 100).round(0).to_s
result = {
'target_name' => to_s,
'campaign_name' => campaign.name,
'value' => numerator,
'unit' => unit,
'created_at' => created_at,
'progress' => progress,
'days_left' => days_left
}
result
end
def to_s
"#{pluralize(target_count, unit)} by #{due_date}"
end
private
def days_left
(due_date - Date.today).to_i
end
end

View file

@ -1,6 +0,0 @@
# frozen_string_literal: true
class Visit < ApplicationRecord
has_many :ahoy_events, class_name: 'Ahoy::Event'
belongs_to :user
end

View file

@ -1,24 +0,0 @@
.row
.col-md-12
.page-header
%h1
- if @campaign.new_record?
New
Campaign
= @campaign.name
.row
.col-md-8
= semantic_form_for(@campaign, url: (@campaign.new_record? ? admin_conference_campaigns_path : admin_conference_campaign_path(@conference.short_title, @campaign))) do |f|
= f.inputs do
= f.input :name, input_html: { autofocus: true }
= f.inputs name: 'UTM Parameters' do
= f.input :utm_campaign, label: 'Campaign', hint: 'Groups all of the content from one campaign. E.g. 20percentpromocode'
= f.input :utm_source, label: 'Source', hint: 'Which website is sending you traffic. E.g. Facebook, google+, blog'
= f.input :utm_medium, label: 'Medium', hint: 'The type of marketing medium that the link is featured in. E.g. Facebook wallpost or facebook advertisement'
= f.input :utm_term, label: 'Term', hint: 'Campaign keywords. E.g. marketing+conference+opensource'
= f.input :utm_content, label: 'Content', hint: 'Used to track the different types of content that point to the same URL (A/B Test).'
= f.inputs name: 'Targets' do
= f.input :targets, collection: @conference.targets
%p.text-right
= f.action :submit, as: :button, button_html: { class: 'btn btn-primary' }

View file

@ -1,42 +0,0 @@
.row
.col-md-12
.page-header
%h1 Campaigns
%p.text-muted
Track where people come from
.row
.col-md-12
%table.table.table-hover#campaigns
%thead
%tr
%th Name
%th Visits
%th Registrations
%th Submissions
%th Link
%th Actions
%tbody
- @campaigns.each do |campaign|
%tr
%td{ 'id' => "name_#{campaign.id}" }
= campaign.name
%td{ 'id' => "visits_#{campaign.id}" }
= campaign.visits_count
%td{ 'id' => "registrations_#{campaign.id}" }
= campaign.registrations_count
%td{ 'id' => "submissions_#{campaign.id}" }
= campaign.submissions_count
%td
%a.copyLink{ 'href' => '#', 'data-url' => root_path + campaign.url_parameters }
Copy link
%td
.btn-group
= link_to 'Edit',
edit_admin_conference_campaign_path(@conference.short_title, campaign.id),
class: 'btn btn-primary'
= link_to 'Delete',
admin_conference_campaign_path(@conference.short_title, campaign.id),
method: :delete, class: 'btn btn-danger', data: { confirm: "Do you really want to delete the campaign #{campaign.name}?" }
.row
.col-md-12
= link_to 'New Campaign', new_admin_conference_campaign_path, class: 'btn btn-success pull-right'

View file

@ -1,40 +0,0 @@
- if campaigns && !campaigns.empty?
.row
.col-md-12
%p
Your target "#{campaigns.values[0]['target_name']}" from campaign "#{campaigns.values[0]['campaign_name']}" has generated
%strong
#{pluralize(campaigns.values[0]['value'], campaigns.values[0]['unit'])}
since #{campaigns.values[0]['created_at']}.
%p
That is
%strong{ 'style' => "color: #{target_progress_color(campaigns.values[0]['progress'])};" }
#{campaigns.values[0]['progress']} %
of your target, there are
%strong{ 'style' => "color: #{days_left_color(campaigns.values[0]['days_left'])};" }
#{pluralize(campaigns.values[0]['days_left'], 'day')} left.
.row
.col-md-12
%div{ 'style' => 'display: none;', 'id' => "#{name}" }
- campaigns.drop(1).each do |(_key, value)|
%div
%p
Your target "#{value['target_name']}" from campaign "#{value['campaign_name']}" has generated
%strong
#{pluralize(value['value'], value['unit'])}
since #{value['created_at']}.
%p
That is
%strong{ 'style' => "color: #{target_progress_color(value['progress'])};" }
#{value['progress']} %
of your target, there are
%strong{ 'style' => "color: #{days_left_color(value['days_left'])};" }
#{pluralize(value['days_left'], 'day')} left.
.row
.col-md-12
- if campaigns.length > 1
%a.show_targets{ 'href' => '#', 'data-name' => "#{name}" }
more
- else
%h5.text-warning.text-center
No Campaigns!

View file

@ -1,32 +0,0 @@
- if targets && !targets.empty?
.row
.col-md-8.col-md-offset-2
.row
.col-md-10
%h6.text-muted.pull-left
Target 1
.row
.col-md-10
.progress{ 'title' => "#{targets.keys[0]}" }
.progress-bar{ 'role' => 'progressbar', 'aria-valuenow' => " #{targets.values[0]}", 'aria-valuemin' => '0',
'aria-valuemax' => '100', 'style' => "width: #{targets.values[0]}%;" }
= "#{targets.values[0]} %"
.row
.col-md-8.col-md-offset-2
%div{ 'style' => 'display: none;', 'id' => "#{name}" }
- targets.drop(1).each_with_index do |(key, value), index|
.row
.col-md-10
%h6.text-muted.pull-left
= "Target #{index + 2}"
.row
.col-md-10
.progress{ 'title' => "#{key}" }
.progress-bar{ 'role' => 'progressbar', 'aria-valuenow' => "#{value}", 'aria-valuemin' => '0',
'aria-valuemax' => '100', 'style' => "width: #{value}%;" }
= "#{value} %"
.row
.col-md-2.col-md-offset-2
- if targets.length > 1
%a.show_targets{ 'href' => '#', 'data-name' => "#{name}" }
more

View file

@ -115,13 +115,6 @@
= render partial: 'recent_submissions', locals: {recent_events: @recent_events}
.col-md-4
= render partial: 'top_submitter', locals: {top_submitter: @top_submitter}
.row
.col-md-12
%h3
%span
%i.fa.fa-flag
Campaigns
= render partial: 'campaigns', locals: {campaigns: @campaigns, name: 'campaigns'}
:javascript
$('#recentTable a').click(function (e) {

View file

@ -1,15 +0,0 @@
.row
.col-md-12
.page-header
%h1
-if @target.new_record?
New
Target
.row
.col-md-8
= semantic_form_for(@target, url: (@target.new_record? ? admin_conference_targets_path : admin_conference_target_path(@conference.short_title, @target))) do |f|
= f.input :due_date, as: :string, input_html: { class: 'target-due-date-datepicker'}, label: 'Until when do you want to have '
= f.input :target_count, input_html: { autofocus: true }, label: 'this amount of '
= f.input :unit, as: :select, label: 'Unit', class: 'form-control', collection: Target.units.values, include_blank: false
%p.text-right
= f.action :submit, as: :button, button_html: { class: 'btn btn-primary' }

View file

@ -1,35 +0,0 @@
.row
.col-md-12
.page-header
%h1 Targets
%p.text-muted
Set up goals for your conference
.row
.col-md-12
%table.table.table-hover#targets
%thead
%tr
%th Due Date
%th Target Count
%th Unit
%th Actions
%tbody
- @targets.each do |target|
%tr
%td{'id'=> "due_date_#{target.id}"}
= target.due_date
%td{'id'=> "count#{target.id}"}
= target.target_count
%td{'id'=> "unit_#{target.id}"}
= target.unit
%td
.btn-group
= link_to 'Edit',
edit_admin_conference_target_path(@conference.short_title, target.id),
class: 'btn btn-primary'
= link_to 'Delete',
admin_conference_target_path(@conference.short_title, target.id),
method: :delete, class: 'btn btn-danger', data: { confirm: "Do you really want to delete this target?" }
.row
.col-md-12
= link_to 'New Target', new_admin_conference_target_path, class: 'btn btn-success pull-right'

View file

@ -74,10 +74,6 @@
= link_to (current_or_last_object_state('Event', event_id).try(:title) || 'deleted event'),
admin_conference_program_event_path(conference_short_title, event_id)
- when 'Target'
target
= link_if_alive version, object.to_s, admin_conference_targets_path(conference_short_title), conference
- when 'EventSchedule'
event
= link_to (current_or_last_object_state('Event', object.event_id).try(:title) || 'deleted'),
@ -187,12 +183,6 @@
admin_conference_ticket_path(conference_short_title, version.item_id),
conference
- when 'Campaign'
campaign
= link_if_alive version, object.name,
admin_conference_campaigns_path(conference_short_title),
conference
- when 'DifficultyLevel'
difficulty level
= link_if_alive version, object.title,admin_conference_program_difficulty_levels_path(conference_short_title), conference

View file

@ -121,18 +121,6 @@
= link_to admin_conference_booths_path(@conference.short_title) do
%span.fa.fa-shopping-bag
Booths
- if (can? :manage, @conference.targets.build) || (can? :manage, @conference.campaigns.build)
%li
%a
%span.fa.fa-money
Objectives
%ul
- if can? :update, @conference.campaigns.build
%li{class: active_nav_li(admin_conference_campaigns_path(@conference.short_title))}
= link_to 'Campaigns', admin_conference_campaigns_path(@conference.short_title)
- if can? :update, @conference.targets.build
%li{class: "#{active_nav_li(admin_conference_targets_path(@conference.short_title))}"}
= link_to 'Goals', admin_conference_targets_path(@conference.short_title)
- if can? :update, @conference.email_settings
%li{class: active_nav_li(admin_conference_emails_path(@conference.short_title))}
= link_to(admin_conference_emails_path(@conference.short_title)) do