Sha256: 06b1456dea7795f5f704171b44334e231a5061f662a28668c553b8254e1c31b4

Contents?: true

Size: 1.04 KB

Versions: 5

Compression:

Stored size: 1.04 KB

Contents

class Rack::Tracker::Criteo <  Rack::Tracker::Handler

  TRACKER_EVENTS = {
    # event name => event key name, e.g. { event: 'setSiteType', type: '' }
    set_site_type: :type,
    set_account: :account,
    set_customer_id: :id
  }

  class Event < OpenStruct
    def write
      to_h.to_json
    end
  end

  self.position = :body

  # global events (setSiteType, setAccount, ...) for each tracker instance
  def tracker_events
    @tracker_events ||= [].tap do |tracker_events|
      options.slice(*TRACKER_EVENTS.keys).each do |key, value|
        if option_value = value.respond_to?(:call) ? value.call(env) : value
          tracker_events << Event.new(:event => "#{key}".camelize(:lower),  TRACKER_EVENTS[key] => "#{option_value}")
        end
      end
    end
  end

  def render
    Tilt.new( File.join( File.dirname(__FILE__), 'template', 'criteo.erb') ).render(self)
  end

  def self.track(name, event_name, event_args = {})
    { name.to_s => [{ 'class_name' => 'Event', 'event' => event_name.to_s.camelize(:lower) }.merge(event_args)] }
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rack-tracker-1.0.2 lib/rack/tracker/criteo/criteo.rb
rack-tracker-1.0.1 lib/rack/tracker/criteo/criteo.rb
rack-tracker-1.0.0 lib/rack/tracker/criteo/criteo.rb
rack-tracker-0.4.2 lib/rack/tracker/criteo/criteo.rb
rack-tracker-0.4.1 lib/rack/tracker/criteo/criteo.rb