Sha256: d7ce27d3d201b57dbc0cc35e51d2f0be438825fb1074b17e06509073e69374d8

Contents?: true

Size: 858 Bytes

Versions: 4

Compression:

Stored size: 858 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).tap { |t| t.restore!(session) }
      end
    end

    private

    def store_mixpanel_if_redirecting
      mixpanel.store!(session) if status == 302
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
mixpal-0.3.0 lib/mixpal/integration.rb
mixpal-0.2.1 lib/mixpal/integration.rb
mixpal-0.2.0 lib/mixpal/integration.rb
mixpal-0.1.0 lib/mixpal/integration.rb