Sha256: 121479d4332275af2a0702ad6e9ca7c0c27a1e046228d122d0ecdccf093eaf97

Contents?: true

Size: 1.13 KB

Versions: 1

Compression:

Stored size: 1.13 KB

Contents

class Rack::Tracker::Zanox < Rack::Tracker::Handler

  # name of the handler
  # everything after is passed as options
  class Mastertag < OpenStruct
    def write
      to_h.except(:id).map do |k,v|
        "var zx_#{k} = #{v.to_json};"
      end.join("\n")
    end
  end

  class Lead < OpenStruct
    # Example: OrderID=[[DEFC-4321]]&CurrencySymbol=[[EUR]]&TotalPrice=[[23.40]]
    def write
      to_h.map do |k,v|
        "#{k.to_s.camelize}=[[#{v}]]"
      end.join('&')
    end
  end

  Sale = Class.new(Lead)

  self.position = :body

  def mastertag
    # First event should be stronger, e.g. one signs up and gets redirected to homepage
    # "sign up" should be tracked instead of "view homepage"
    events.select{ |event| event.class.to_s.demodulize == 'Mastertag' }.first
  end

  def lead_events
    events.select{ |event| event.class.to_s.demodulize == 'Lead' }
  end

  def sale_events
    events.select{ |event| event.class.to_s.demodulize == 'Sale' }
  end

  # this is called with additional arguments to t.zanox
  def self.track(name, *event)
    { name.to_s => [event.last.merge('class_name' => event.first.to_s.capitalize)] }
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rack-tracker-1.4.0 lib/rack/tracker/zanox/zanox.rb