class Staccato::Rack::PageView

Proxy Class to do page views

Public Class Methods

new() click to toggle source
Calls superclass method
# File lib/staccato/rack/page_view.rb, line 7
def initialize
  super
  @custom_metrics = []
  @custom_dimensions = []
end

Public Instance Methods

add_custom_dimension(position, value) click to toggle source
# File lib/staccato/rack/page_view.rb, line 17
def add_custom_dimension(position, value)
  @custom_dimensions << [position, value]
end
add_custom_metric(position, value) click to toggle source
# File lib/staccato/rack/page_view.rb, line 13
def add_custom_metric(position, value)
  @custom_metrics << [position, value]
end
track!(default_tracker, tracking_id, request) click to toggle source
# File lib/staccato/rack/page_view.rb, line 21
def track!(default_tracker, tracking_id, request)
  page_view_params = marshal_dump
  if page_view_params[:client_id]
    tracker = Staccato.tracker(tracking_id, page_view_params[:client_id]) do |c|
      c.adapter = FaradayAsyncHttpAdaper.new(logger) unless tracking_id.nil?
    end
  else
    tracker = default_tracker
  end
  track_hit(tracker, page_view_params, request)
end

Private Instance Methods

add_custom_to_hit(hit) click to toggle source
# File lib/staccato/rack/page_view.rb, line 44
def add_custom_to_hit(hit)
  @custom_metrics.each do |p, v|
    hit.add_custom_metric(p, v)
  end
  @custom_dimensions.each do |p, v|
    hit.add_custom_dimension(p, v)
  end
end
track_hit(tracker, page_view_params, request) click to toggle source
# File lib/staccato/rack/page_view.rb, line 35
def track_hit(tracker, page_view_params, request)
  hit = Staccato::Pageview.new(tracker, { path: request.fullpath,
                                          user_agent: request.env['HTTP_USER_AGENT'],
                                          user_ip: request.ip }.merge(page_view_params))
  add_custom_to_hit(hit)
  hit.track!
  hit
end