Sha256: 4f3604e855cfb7c71462a8ade50a5b6d9473bc6ee487d0ff4cbf218046e9b4c6

Contents?: true

Size: 1.21 KB

Versions: 16

Compression:

Stored size: 1.21 KB

Contents

module Ahoy
  module Stores
    class LogStore < BaseStore
      def track_visit(options, &block)
        data = {
          id: ahoy.visit_id,
          visitor_id: ahoy.visitor_id
        }.merge(visit_properties.to_hash)
        data[:user_id] = user.id if user
        data[:started_at] = options[:started_at]

        yield(data) if block_given?

        log_visit(data)
      end

      def track_event(name, properties, options, &block)
        data = {
          id: options[:id],
          name: name,
          properties: properties,
          visit_id: ahoy.visit_id,
          visitor_id: ahoy.visitor_id
        }
        data[:user_id] = user.id if user
        data[:time] = options[:time]

        yield(data) if block_given?

        log_event(data)
      end

      protected

      def log_visit(data)
        visit_logger.info data.to_json
      end

      def log_event(data)
        event_logger.info data.to_json
      end

      # TODO disable header
      def visit_logger
        @visit_logger ||= ActiveSupport::Logger.new(Rails.root.join("log/visits.log"))
      end

      def event_logger
        @event_logger ||= ActiveSupport::Logger.new(Rails.root.join("log/events.log"))
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
ahoy_matey-1.6.1 lib/ahoy/stores/log_store.rb
ahoy_matey-1.6.0 lib/ahoy/stores/log_store.rb
ahoy_matey-1.5.5 lib/ahoy/stores/log_store.rb
ahoy_matey-1.5.4 lib/ahoy/stores/log_store.rb
ahoy_matey-1.5.3 lib/ahoy/stores/log_store.rb
ahoy_matey-1.5.2 lib/ahoy/stores/log_store.rb
ahoy_matey-1.5.1 lib/ahoy/stores/log_store.rb
ahoy_matey-1.5.0 lib/ahoy/stores/log_store.rb
ahoy_matey-1.4.2 lib/ahoy/stores/log_store.rb
ahoy_matey-1.4.1 lib/ahoy/stores/log_store.rb
ahoy_matey-1.4.0 lib/ahoy/stores/log_store.rb
ahoy_matey-1.3.1 lib/ahoy/stores/log_store.rb
ahoy_matey-1.3.0 lib/ahoy/stores/log_store.rb
ahoy_matey-1.2.2 lib/ahoy/stores/log_store.rb
ahoy_matey-1.2.1 lib/ahoy/stores/log_store.rb
ahoy_matey-1.2.0 lib/ahoy/stores/log_store.rb