mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-10 17:21:38 -05:00
34 lines
740 B
Ruby
34 lines
740 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
|