Sha256: 5b34fbbfb477beb215e91afff23bc4b13b445ba99e677794f67478dcd40ac5a5

Contents?: true

Size: 695 Bytes

Versions: 21

Compression:

Stored size: 695 Bytes

Contents

module Spree
  class Tracker < Spree::Base
    TRACKING_ENGINES = %i(google_analytics segment).freeze
    enum engine: TRACKING_ENGINES

    after_commit :clear_cache

    validates :analytics_id, presence: true, uniqueness: { scope: :engine, case_sensitive: false }

    scope :active, -> { where(active: true) }

    def self.current(engine = TRACKING_ENGINES.first)
      tracker = Rails.cache.fetch("current_tracker/#{engine}") do
        send(engine).active.first
      end
      tracker.analytics_id.present? ? tracker : nil if tracker
    end

    def clear_cache
      TRACKING_ENGINES.each do |engine|
        Rails.cache.delete("current_tracker/#{engine}")
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 2 rubygems

Version Path
spree_analytics_trackers-2.0.0.rc1 app/models/spree/tracker.rb
spree_core-3.4.6 app/models/spree/tracker.rb
spree_analytics_trackers-1.1.0 app/models/spree/tracker.rb
spree_analytics_trackers-1.0.1 app/models/spree/tracker.rb
spree_core-3.3.6 app/models/spree/tracker.rb
spree_core-3.4.5 app/models/spree/tracker.rb
spree_core-3.3.5 app/models/spree/tracker.rb
spree_core-3.4.4 app/models/spree/tracker.rb
spree_core-3.4.3 app/models/spree/tracker.rb
spree_core-3.3.4 app/models/spree/tracker.rb
spree_core-3.4.2 app/models/spree/tracker.rb
spree_core-3.3.3 app/models/spree/tracker.rb
spree_core-3.4.1 app/models/spree/tracker.rb
spree_core-3.4.0 app/models/spree/tracker.rb
spree_core-3.4.0.rc2 app/models/spree/tracker.rb
spree_core-3.4.0.rc1 app/models/spree/tracker.rb
spree_core-3.3.2 app/models/spree/tracker.rb
spree_core-3.3.1 app/models/spree/tracker.rb
spree_core-3.3.0 app/models/spree/tracker.rb
spree_core-3.3.0.rc4 app/models/spree/tracker.rb