Sha256: 95bd62cb55f5216419b8d3c5374723817767fb9e58faab227ac1df97ebec6bca

Contents?: true

Size: 957 Bytes

Versions: 1

Compression:

Stored size: 957 Bytes

Contents

module Staccato
  module SessionTracking
    def self.included(controller)
      controller.class_eval do
        alias_method :tracker, :staccato_tracker unless defined?(tracker)
      end
    end

    def global_context
      {}
    end

    def hit_context
      {}
    end

    def staccato_tracker
      @staccato_tracker ||= Staccato.tracker(staccato_tracker_id, staccato_client_id, global_context)
    end

    # pull tracker id from config
    def staccato_tracker_id
      Rails.configuration.staccato.tracker_id
    end

    # load or set new uuid in session
    def staccato_client_id
      session['staccato.client_id'] ||= Staccato.build_client_id
    end

    # This is called in an `ensure` block by actionpack
    #   errors raised here _may_ be particularly dangerous
    def append_info_to_payload(payload)
      super

      payload["staccato.tracker"] = staccato_tracker
      payload["staccato.context"] = hit_context
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
staccato-rails-0.1.0 lib/staccato/session_tracking.rb