dawarich/app/controllers/concerns/utm_trackable.rb
Amar Takhar bbcae26f91 Add missing module deceleration
Fixes a bug intoduced in 8e35b8e
2025-10-30 23:03:19 -04:00

35 lines
741 B
Ruby

# frozen_string_literal: true
module UtmTrackable
extend ActiveSupport::Concern
UTM_PARAMS = %w[utm_source utm_medium utm_campaign utm_term utm_content].freeze
def store_utm_params
UTM_PARAMS.each do |param|
session[param] = params[param] if params[param].present?
end
end
def assign_utm_params(record)
utm_data = extract_utm_data_from_session
return unless utm_data.any?
record.update_columns(utm_data)
clear_utm_session
end
private
def extract_utm_data_from_session
UTM_PARAMS.each_with_object({}) do |param, hash|
hash[param] = session[param] if session[param].present?
end
end
def clear_utm_session
UTM_PARAMS.each { |param| session.delete(param) }
end
end