mirror of
https://github.com/openSUSE/osem.git
synced 2026-08-13 19:54:02 +00:00
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:
parent
62056fc044
commit
b11001cdba
47 changed files with 19 additions and 1420 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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).
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Visit < ApplicationRecord
|
||||
has_many :ahoy_events, class_name: 'Ahoy::Event'
|
||||
belongs_to :user
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue