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.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Clean up analytics configuration API (#13314)
Damian Legawiec31c8d51ed7fb
diff --git a/core/app/models/spree/base_analytics_event_handler.rb b/core/app/models/spree/base_analytics_event_handler.rbindex 5bb6b7de80..e1680d5802 100644--- a/core/app/models/spree/base_analytics_event_handler.rb+++ b/core/app/models/spree/base_analytics_event_handler.rb@@ -35,7 +35,7 @@ module Spree# @param event_name [String] eg. 'order_completed'# @return [String] eg. 'Order Completed'def event_human_name(event_name)- Analytics.events[event_name.to_sym]+ Spree.analytics.events[event_name.to_sym]endprotecteddiff --git a/core/lib/spree/analytics.rb b/core/lib/spree/analytics.rbdeleted file mode 100644index 6a1d3d554d..0000000000--- a/core/lib/spree/analytics.rb+++ /dev/null@@ -1,11 +0,0 @@-module Spree- module Analytics- def self.events- @@supported_events ||= Spree.analytics_events- end-- def self.event_handlers- @@event_handlers ||= Spree.analytics_event_handlers- end- end-enddiff --git a/core/lib/spree/core.rb b/core/lib/spree/core.rbindex 059f813067..beb0c8770b 100644--- a/core/lib/spree/core.rb+++ b/core/lib/spree/core.rb@@ -280,20 +280,8 @@ module SpreeRails.application.config.spree.metafieldsend- 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+ def self.analytics+ Rails.application.config.spree.analyticsenddef self.integrations@@ -373,7 +361,6 @@ require 'spree/money'require 'spree/permitted_attributes'require 'spree/service_module'require 'spree/database_type_utilities'-require 'spree/analytics'require 'spree/core/partials'require 'spree/core/importer'diff --git a/core/lib/spree/core/engine.rb b/core/lib/spree/core/engine.rbindex 6f734b6979..7e6969cf49 100644--- a/core/lib/spree/core/engine.rb+++ b/core/lib/spree/core/engine.rb@@ -25,13 +25,13 @@ module Spree:reports,:translatable_resources,:metafields,- :analytics_events,- :analytics_event_handlers,+ :analytics,:integrations)SpreeCalculators = Struct.new(:shipping_methods, :tax_rates, :promotion_actions_create_adjustments, :promotion_actions_create_item_adjustments)PromoEnvironment = Struct.new(:rules, :actions)SpreeValidators = Struct.new(:addresses)MetafieldsEnvironment = Struct.new(:types, :enabled_resources)+ AnalyticsEnvironment = Struct.new(:events, :handlers)isolate_namespace Spreeengine_name 'spree'@@ -72,6 +72,12 @@ module Spreeapp.config.spree.metafields.enabled_resources = []end+ initializer 'spree.register.analytics' do |app|+ app.config.spree.analytics = AnalyticsEnvironment.new+ app.config.spree.analytics.events = {}+ app.config.spree.analytics.handlers = []+ end+# We need to define promotions rules here so extensions and existing apps# can add their custom classes on their initializer filesinitializer 'spree.promo.environment' do |app|@@ -309,7 +315,7 @@ module SpreeSpree.user_class]- Rails.application.config.spree.analytics_events = {+ Rails.application.config.spree.analytics.events = {product_viewed: 'Product Viewed',product_list_viewed: 'Product List Viewed',product_searched: 'Product Searched',@@ -334,7 +340,7 @@ module Spreecheckout_step_completed: 'Checkout Step Completed',order_completed: 'Order Completed',}- Rails.application.config.spree.analytics_event_handlers = []+ Rails.application.config.spree.analytics.handlers = []Rails.application.config.spree.integrations = []diff --git a/core/spec/lib/spree/core_environment_spec.rb b/core/spec/lib/spree/core_environment_spec.rbindex 183eaf0c63..b22d167939 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' doexpect(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.handlers)+ expect(Spree.analytics.handlers).to be_an(Array)endit 'provides access to integrations' dodiff --git a/storefront/app/helpers/spree/analytics_helper.rb b/storefront/app/helpers/spree/analytics_helper.rbindex 30d4f06568..82ebc42175 100644--- a/storefront/app/helpers/spree/analytics_helper.rb+++ b/storefront/app/helpers/spree/analytics_helper.rb@@ -1,7 +1,7 @@module Spreemodule AnalyticsHelperdef analytics_event_handlers- @analytics_event_handlers ||= Spree::Analytics.event_handlers.map do |handler|+ @analytics_event_handlers ||= Spree.analytics.handlers.map do |handler|handler.new(user: try_spree_current_user, session: session, request: request, store: Spree::Store.current, visitor_id: visitor_id)endend@@ -26,7 +26,7 @@ module Spreeenddef unsupported_event?(event_name)- !Spree::Analytics.events.key?(event_name.to_sym)+ !Spree.analytics.events.key?(event_name.to_sym)endendend