Sha256: 15bbf4a229586a4f6d6afa16ca8ecf90dde8c019b35f7fcba826b11ed23254ec
Contents?: true
Size: 1.69 KB
Versions: 2
Compression:
Stored size: 1.69 KB
Contents
class Rack::Tracker::GoogleGlobal < Rack::Tracker::Handler self.allowed_tracker_options = [:cookie_domain, :user_id, :link_attribution, :allow_display_features, :anonymize_ip, :custom_map, :optimize_id] class Page < OpenStruct def params Hash[to_h.slice(:title, :location, :path).map { |key, value| ["page_#{key}", value] }] end end class Event < OpenStruct PREFIXED_PARAMS = %i[category label] SKIP_PARAMS = %i[action] def params Hash[to_h.except(*SKIP_PARAMS).map { |key, value| [param_key(key), value] }] end private def param_key(key) PREFIXED_PARAMS.include?(key) ? "event_#{key}" : key.to_s end end def pages select_handler_events(Page) end alias handler_events events def events select_handler_events(Event) end def trackers @_trackers ||= build_trackers end def set_options @_set_options ||= build_set_options end private def build_trackers options[:trackers].map(&method(:call_tracker)).reject(&method(:invalid_tracker?)) end def call_tracker(tracker) if tracker[:id].respond_to?(:call) tracker.merge(id: tracker[:id].call(env)) else tracker end end def invalid_tracker?(tracker) if tracker[:id].to_s.strip == '' $stdout.puts <<~WARN WARNING: One of the trackers specified for Rack::Tracker handler 'google_global' is empty. Trackers: #{options[:trackers]} WARN true else false end end def build_set_options value = options[:set] value.respond_to?(:call) ? value.call(env) : value end def select_handler_events(klass) handler_events.select { |event| event.is_a?(klass) } end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rack-tracker-1.13.0 | lib/rack/tracker/google_global/google_global.rb |
rack-tracker-1.12.1 | lib/rack/tracker/google_global/google_global.rb |