Sha256: 1d85ea3922b24905e8429158ce081d8ba4383949e010fda0fb4466cf6c98522d

Contents?: true

Size: 1.23 KB

Versions: 14

Compression:

Stored size: 1.23 KB

Contents

require 'mixpanel'

module AbPanel
  module Mixpanel
    class Tracker < ::Mixpanel::Tracker
      def initialize(options = {})
        return if !should_track?

        @tracker = ::Mixpanel::Tracker.new Config.token, ab_panel_options.merge(options)
      end

      def ab_panel_options
        opts = {
          env:     AbPanel.env,
          persist: true
        }

        AbPanel.funnels.each do |funnel|
          opts["funnel_#{funnel}"] = true
        end

        opts
      end

      def track(event_name, properties)
        return if !should_track?

        @tracker.append_track event_name, properties
      end

      def identify(distinct_id)
        return if !should_track?

        @tracker.append_identify distinct_id
      end

      private

      def should_track?
        @should_track ||= Config.environments.include?(Rails.env)
      end
    end

    class Config
      def self.token
        config[Rails.env]['token']
      end

      def self.environments
        config.keys
      end

      def self.config
        @settings ||= load_config
      end

      private

      def self.load_config
        file = File.read(File.join(Rails.root, 'config', 'mixpanel.yml'))
        YAML.load(file)
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
ab_panel-0.4.4 lib/ab_panel/mixpanel.rb
ab_panel-0.4.3 lib/ab_panel/mixpanel.rb
ab_panel-0.4.2 lib/ab_panel/mixpanel.rb
ab_panel-0.4.1 lib/ab_panel/mixpanel.rb
ab_panel-0.4.0 lib/ab_panel/mixpanel.rb
ab_panel-0.3.3 lib/ab_panel/mixpanel.rb
ab_panel-0.3.2 lib/ab_panel/mixpanel.rb
ab_panel-0.3.1 lib/ab_panel/mixpanel.rb
ab_panel-0.3.0 lib/ab_panel/mixpanel.rb
ab_panel-0.2.0 lib/ab_panel/mixpanel.rb
ab_panel-0.1.3 lib/ab_panel/mixpanel.rb
ab_panel-0.1.2 lib/ab_panel/mixpanel.rb
ab_panel-0.1.1 lib/ab_panel/mixpanel.rb
ab_panel-0.1.0 lib/ab_panel/mixpanel.rb