Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Clean up analytics config API but still make it backwards compatible (#13315)

Damian Legawieca100d2b1c9b2
diff --git a/core/lib/spree/analytics.rb b/core/lib/spree/analytics.rb
index 6a1d3d554d..59853b3b23 100644
--- a/core/lib/spree/analytics.rb
+++ b/core/lib/spree/analytics.rb
@@ -1,11 +1,11 @@
module Spree
module Analytics
def self.events
- @@supported_events ||= Spree.analytics_events
+ @@supported_events ||= Spree.analytics.events
end
def self.event_handlers
- @@event_handlers ||= Spree.analytics_event_handlers
+ @@event_handlers ||= Spree.analytics.handlers
end
end
end
diff --git a/core/lib/spree/core.rb b/core/lib/spree/core.rb
index 059f813067..fb7c046ddc 100644
--- a/core/lib/spree/core.rb
+++ b/core/lib/spree/core.rb
@@ -280,22 +280,6 @@ module Spree
Rails.application.config.spree.metafields
end
- def self.analytics_events
- Rails.application.config.spree.analytics_events
- end
-
- def self.analytics_events=(value)
- Rails.application.config.spree.analytics_events = value
- end
-
- def self.analytics_event_handlers
- Rails.application.config.spree.analytics_event_handlers
- end
-
- def self.analytics_event_handlers=(value)
- Rails.application.config.spree.analytics_event_handlers = value
- end
-
def self.integrations
Rails.application.config.spree.integrations
end
@@ -351,6 +335,29 @@ module Spree
end
end
+ def self.analytics
+ @analytics ||= AnalyticsConfig.new
+ end
+
+ # Group analytics configuration options together, but still make it backwards compatible.
+ class AnalyticsConfig
+ def events
+ Rails.application.config.spree.analytics_events
+ end
+
+ def events=(value)
+ Rails.application.config.spree.analytics_events = value
+ end
+
+ def handlers
+ Rails.application.config.spree.analytics_event_handlers
+ end
+
+ def handlers=(value)
+ Rails.application.config.spree.analytics_event_handlers = value
+ end
+ end
+
module Core
autoload :ProductFilters, 'spree/core/product_filters'
autoload :TokenGenerator, 'spree/core/token_generator'
diff --git a/core/spec/lib/spree/core_environment_spec.rb b/core/spec/lib/spree/core_environment_spec.rb
index 183eaf0c63..944d6f50bd 100644
--- a/core/spec/lib/spree/core_environment_spec.rb
+++ b/core/spec/lib/spree/core_environment_spec.rb
@@ -78,14 +78,14 @@ RSpec.describe 'Spree environment accessors' do
expect(Spree.metafields.enabled_resources).to be_an(Array)
end
- it 'provides access to analytics_events' do
- expect(Spree.analytics_events).to eq(Rails.application.config.spree.analytics_events)
- expect(Spree.analytics_events).to be_a(Hash)
+ it 'provides access to analytics.events' do
+ expect(Spree.analytics.events).to eq(Rails.application.config.spree.analytics_events)
+ expect(Spree.analytics.events).to be_a(Hash)
end
- it 'provides access to analytics_event_handlers' do
- expect(Spree.analytics_event_handlers).to eq(Rails.application.config.spree.analytics_event_handlers)
- expect(Spree.analytics_event_handlers).to be_an(Array)
+ it 'provides access to analytics.handlers' do
+ expect(Spree.analytics.handlers).to eq(Rails.application.config.spree.analytics_event_handlers)
+ expect(Spree.analytics.handlers).to be_an(Array)
end
it 'provides access to integrations' do