Sha256: cade4c34ad93193dca9376d8be9241f52baa4e880438b846611c36aa0a063f4e

Contents?: true

Size: 793 Bytes

Versions: 2

Compression:

Stored size: 793 Bytes

Contents

module Mixpal
  module Integration
    extend ActiveSupport::Concern

    included do
      helper_method :mixpanel
      after_filter :store_mixpanel_if_redirecting

      class_attribute :mixpanel_identity_data
      def self.mixpanel_identity(object_method, attribute_method)
        self.mixpanel_identity_data = {
          object_method: object_method,
          attribute_method: attribute_method,
        }
      end
    end

    def mixpanel
      @mixpanel ||= begin
        identity = if data = self.class.mixpanel_identity_data
          send(data[:object_method]).try(data[:attribute_method])
        end

        Mixpal::Tracker.new(identity: identity)
      end
    end

    private

    def store_mixpanel_if_redirecting
      mixpanel.store! if status == 302
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mixpal-0.0.5 lib/mixpal/integration.rb
mixpal-0.0.4 lib/mixpal/integration.rb