Sha256: 6ef78bbfc13b7eebcc911b053645cf929f91253f2a4da2bddd0bf81ce73977c4

Contents?: true

Size: 913 Bytes

Versions: 1

Compression:

Stored size: 913 Bytes

Contents

module Ahoy
  class Tracker

    def initialize(options = {})
      @controller = options[:controller]
    end

    def track(name, properties = {}, options = {})
      if !(@controller and Ahoy.exclude_method and Ahoy.exclude_method.call(@controller))
        # publish to each subscriber
        options = options.dup
        if @controller
          options[:controller] ||= @controller
          options[:user] ||= Ahoy.fetch_user(@controller)
          if @controller.respond_to?(:current_visit)
            options[:visit] ||= @controller.current_visit
          end
        end
        options[:time] ||= Time.zone.now

        subscribers = Ahoy.subscribers
        if subscribers.any?
          subscribers.each do |subscriber|
            subscriber.track(name, properties, options)
          end
        else
          $stderr.puts "No subscribers"
        end
      end

      true
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ahoy_matey-0.2.2 lib/ahoy/tracker.rb