spree_analytics_trackers 2.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +21 -0
  3. data/.rspec +3 -0
  4. data/.rubocop.yml +2 -0
  5. data/.travis.yml +44 -0
  6. data/Appraisals +11 -0
  7. data/Gemfile +7 -0
  8. data/LICENSE +26 -0
  9. data/README.md +77 -0
  10. data/Rakefile +21 -0
  11. data/app/assets/javascripts/spree/frontend/add_to_cart_analytics.js +46 -0
  12. data/app/controllers/spree/admin/trackers_controller.rb +6 -0
  13. data/app/controllers/spree_analytics_trackers/store_controller_decorator.rb +14 -0
  14. data/app/helpers/spree/trackers_helper.rb +70 -0
  15. data/app/models/spree/tracker.rb +25 -0
  16. data/app/models/spree_analytics_trackers/user_decorator.rb +9 -0
  17. data/app/overrides/add_analytics_to_admin_sidebar.rb +8 -0
  18. data/app/overrides/add_cart_viewed_to_orders_edit.rb +10 -0
  19. data/app/overrides/add_checkout_step_viewed_to_checkout_edit.rb +18 -0
  20. data/app/overrides/add_google_analytics_page_view_to_spree_application.rb +18 -0
  21. data/app/overrides/add_google_analytics_to_spree_application.rb +17 -0
  22. data/app/overrides/add_google_purchase_to_orders_show.rb +9 -0
  23. data/app/overrides/add_order_complete_to_orders_show.rb +10 -0
  24. data/app/overrides/add_product_list_filtered_to_taxons_show.rb +10 -0
  25. data/app/overrides/add_product_list_viewed_to_products_list.rb +10 -0
  26. data/app/overrides/add_product_viewed_to_products_show.rb +10 -0
  27. data/app/overrides/add_products_searched_to_products_list.rb +10 -0
  28. data/app/overrides/add_segment_initializer_to_layout.rb +18 -0
  29. data/app/overrides/add_segment_page_viewed_to_layout.rb +18 -0
  30. data/app/presenters/spree_analytics_trackers/base_presenter.rb +14 -0
  31. data/app/presenters/spree_analytics_trackers/segment/order_presenter.rb +32 -0
  32. data/app/presenters/spree_analytics_trackers/segment/product_presenter.rb +40 -0
  33. data/app/views/spree/admin/shared/_analytics_sidebar_menu.html.erb +3 -0
  34. data/app/views/spree/admin/trackers/_form.html.erb +36 -0
  35. data/app/views/spree/admin/trackers/edit.html.erb +13 -0
  36. data/app/views/spree/admin/trackers/index.html.erb +40 -0
  37. data/app/views/spree/admin/trackers/new.html.erb +13 -0
  38. data/app/views/spree/shared/trackers/google_analytics/_checkout_step_viewed.js.erb +21 -0
  39. data/app/views/spree/shared/trackers/google_analytics/_initializer.js.erb +11 -0
  40. data/app/views/spree/shared/trackers/google_analytics/_page_viewed.js.erb +13 -0
  41. data/app/views/spree/shared/trackers/google_analytics/_purchase.js.erb +19 -0
  42. data/app/views/spree/shared/trackers/segment/_cart_viewed.js.erb +22 -0
  43. data/app/views/spree/shared/trackers/segment/_checkout_step_viewed.js.erb +14 -0
  44. data/app/views/spree/shared/trackers/segment/_initializer.js.erb +7 -0
  45. data/app/views/spree/shared/trackers/segment/_order_complete.js.erb +8 -0
  46. data/app/views/spree/shared/trackers/segment/_page_viewed.js.erb +7 -0
  47. data/app/views/spree/shared/trackers/segment/_product_list_filtered.js.erb +21 -0
  48. data/app/views/spree/shared/trackers/segment/_product_list_viewed.js.erb +17 -0
  49. data/app/views/spree/shared/trackers/segment/_product_viewed.js.erb +10 -0
  50. data/app/views/spree/shared/trackers/segment/_products_searched.js.erb +12 -0
  51. data/bin/rails +7 -0
  52. data/config/locales/en.yml +18 -0
  53. data/config/locales/zh-TW.yml +19 -0
  54. data/config/routes.rb +5 -0
  55. data/db/migrate/20171013160337_create_spree_trackers.rb +20 -0
  56. data/gemfiles/.bundle/config +2 -0
  57. data/gemfiles/spree_4_1.gemfile +9 -0
  58. data/gemfiles/spree_master.gemfile +9 -0
  59. data/lib/generators/spree_analytics_trackers/install/install_generator.rb +27 -0
  60. data/lib/spree_analytics_trackers.rb +5 -0
  61. data/lib/spree_analytics_trackers/engine.rb +20 -0
  62. data/lib/spree_analytics_trackers/factories.rb +9 -0
  63. data/lib/spree_analytics_trackers/version.rb +18 -0
  64. data/spec/features/admin/configuration/analytics_tracker_spec.rb +52 -0
  65. data/spec/features/products_spec.rb +315 -0
  66. data/spec/fixtures/thinking-cat.jpg +0 -0
  67. data/spec/models/spree/tracker_spec.rb +17 -0
  68. data/spec/presenters/spree_analytics_trackers/segment/order_presenter_spec.rb +34 -0
  69. data/spec/spec_helper.rb +18 -0
  70. data/spec/support/custom_products.rb +26 -0
  71. data/spree_analytics_trackers.gemspec +31 -0
  72. metadata +202 -0
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::Tracker, type: :model do
4
+ describe 'current' do
5
+ it 'returns the first active tracker' do
6
+ tracker = create(:tracker)
7
+ tracker.clear_cache
8
+ expect(Spree::Tracker.current).to eq(tracker)
9
+ end
10
+
11
+ it 'does not return an inactive tracker' do
12
+ tracker = create(:tracker, active: false)
13
+ tracker.clear_cache
14
+ expect(Spree::Tracker.current).to be_nil
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ describe SpreeAnalyticsTrackers::Segment::OrderPresenter, type: :presenter do
4
+ let(:order) { create(:order_with_line_items) }
5
+
6
+ subject { described_class.new(order) }
7
+
8
+ describe '#to_json' do
9
+ let(:result) do
10
+ {
11
+ order_id: order.number.to_s,
12
+ total: order.total&.to_f,
13
+ shipping: order.shipment_total&.to_f,
14
+ tax: order.additional_tax_total&.to_f,
15
+ discount: order.promo_total&.to_f,
16
+ coupon: order.promo_code,
17
+ currency: order.currency,
18
+ products: order.line_items.map{ |line_item|
19
+ {
20
+ product_id: line_item.product_id&.to_s,
21
+ sku: line_item.sku&.to_s,
22
+ name: line_item.name,
23
+ price: line_item.price&.to_f,
24
+ quantity: line_item.quantity
25
+ }
26
+ }
27
+ }.to_json
28
+ end
29
+
30
+ it 'returns serialized object' do
31
+ expect(subject.to_json).to eq(result)
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,18 @@
1
+ # Configure Rails Environment
2
+ ENV['RAILS_ENV'] = 'test'
3
+
4
+ require File.expand_path('../dummy/config/environment.rb', __FILE__)
5
+
6
+ require 'spree_dev_tools/rspec/spec_helper'
7
+
8
+ # Requires supporting ruby files with custom matchers and macros, etc,
9
+ # in spec/support/ and its subdirectories.
10
+ Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].sort.each { |f| require f }
11
+
12
+ require 'spree_analytics_trackers/factories'
13
+
14
+ require 'spree/testing_support/image_helpers'
15
+
16
+ RSpec.configure do |config|
17
+ config.include Spree::TestingSupport::ImageHelpers
18
+ end
@@ -0,0 +1,26 @@
1
+ shared_context 'custom products' do
2
+ before do
3
+ taxonomy = FactoryBot.create(:taxonomy, name: 'Categories')
4
+ root = taxonomy.root
5
+ clothing_taxon = FactoryBot.create(:taxon, name: 'Clothing', parent_id: root.id)
6
+ trending_taxon = FactoryBot.create(:taxon, name: 'Trending')
7
+ bags_taxon = FactoryBot.create(:taxon, name: 'Bags', parent_id: root.id)
8
+ mugs_taxon = FactoryBot.create(:taxon, name: 'Mugs', parent_id: root.id)
9
+
10
+ taxonomy = FactoryBot.create(:taxonomy, name: 'Brands')
11
+ root = taxonomy.root
12
+ apache_taxon = FactoryBot.create(:taxon, name: 'Apache', parent_id: root.id)
13
+ rails_taxon = FactoryBot.create(:taxon, name: 'Ruby on Rails', parent_id: root.id)
14
+ ruby_taxon = FactoryBot.create(:taxon, name: 'Ruby', parent_id: root.id)
15
+
16
+ FactoryBot.create(:custom_product, name: 'Ruby on Rails Ringer T-Shirt', price: '159.99', taxons: [rails_taxon, clothing_taxon])
17
+ FactoryBot.create(:custom_product, name: 'Ruby on Rails Mug', price: '55.99', taxons: [rails_taxon, mugs_taxon, trending_taxon])
18
+ FactoryBot.create(:custom_product, name: 'Ruby on Rails Tote', price: '55.99', taxons: [rails_taxon, bags_taxon, trending_taxon])
19
+ FactoryBot.create(:custom_product, name: 'Ruby on Rails Bag', price: '102.99', taxons: [rails_taxon, bags_taxon])
20
+ FactoryBot.create(:custom_product, name: 'Ruby on Rails Baseball Jersey', price: '190.99', taxons: [rails_taxon, clothing_taxon])
21
+ FactoryBot.create(:custom_product, name: 'Ruby on Rails Stein', price: '156.99', taxons: [rails_taxon, mugs_taxon])
22
+ FactoryBot.create(:custom_product, name: 'Ruby on Rails Jr. Spaghetti', price: '190.99', taxons: [rails_taxon, clothing_taxon])
23
+ FactoryBot.create(:custom_product, name: 'Ruby Baseball Jersey', price: '250.99', taxons: [ruby_taxon, clothing_taxon])
24
+ FactoryBot.create(:custom_product, name: 'Apache Baseball Jersey', price: '250.99', taxons: [apache_taxon, clothing_taxon])
25
+ end
26
+ end
@@ -0,0 +1,31 @@
1
+ lib = File.expand_path('../lib/', __FILE__)
2
+ $LOAD_PATH.unshift lib unless $LOAD_PATH.include?(lib)
3
+
4
+ require 'spree_analytics_trackers/version'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.platform = Gem::Platform::RUBY
8
+ s.name = 'spree_analytics_trackers'
9
+ s.version = SpreeAnalyticsTrackers.version
10
+ s.summary = 'Adds analytics trackers functionality to Spree'
11
+ s.description = 'Supports Google Analytics '
12
+ s.required_ruby_version = '>= 2.5.0'
13
+
14
+ s.author = 'Spark Solutions'
15
+ s.email = 'we@sparksolutions.co'
16
+ s.homepage = 'https://github.com/spree-contrib/spree_analytics_trackers'
17
+ s.license = 'BSD-3-Clause'
18
+
19
+ s.files = `git ls-files`.split("\n")
20
+ s.test_files = `git ls-files -- spec/*`.split("\n")
21
+ s.require_path = 'lib'
22
+ s.requirements << 'none'
23
+
24
+ spree_version = '>= 4.1.0', '< 5.0'
25
+ s.add_dependency 'spree_core', spree_version
26
+ s.add_dependency 'spree_backend', spree_version
27
+ s.add_dependency 'spree_extension'
28
+ s.add_dependency 'deface', '~> 1.0'
29
+
30
+ s.add_development_dependency 'spree_dev_tools'
31
+ end
metadata ADDED
@@ -0,0 +1,202 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spree_analytics_trackers
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.0.rc1
5
+ platform: ruby
6
+ authors:
7
+ - Spark Solutions
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-07-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: spree_core
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 4.1.0
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '5.0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 4.1.0
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '5.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: spree_backend
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: 4.1.0
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: '5.0'
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 4.1.0
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: '5.0'
53
+ - !ruby/object:Gem::Dependency
54
+ name: spree_extension
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ type: :runtime
61
+ prerelease: false
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ - !ruby/object:Gem::Dependency
68
+ name: deface
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - "~>"
72
+ - !ruby/object:Gem::Version
73
+ version: '1.0'
74
+ type: :runtime
75
+ prerelease: false
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - "~>"
79
+ - !ruby/object:Gem::Version
80
+ version: '1.0'
81
+ - !ruby/object:Gem::Dependency
82
+ name: spree_dev_tools
83
+ requirement: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ description: 'Supports Google Analytics '
96
+ email: we@sparksolutions.co
97
+ executables: []
98
+ extensions: []
99
+ extra_rdoc_files: []
100
+ files:
101
+ - ".gitignore"
102
+ - ".rspec"
103
+ - ".rubocop.yml"
104
+ - ".travis.yml"
105
+ - Appraisals
106
+ - Gemfile
107
+ - LICENSE
108
+ - README.md
109
+ - Rakefile
110
+ - app/assets/javascripts/spree/frontend/add_to_cart_analytics.js
111
+ - app/controllers/spree/admin/trackers_controller.rb
112
+ - app/controllers/spree_analytics_trackers/store_controller_decorator.rb
113
+ - app/helpers/spree/trackers_helper.rb
114
+ - app/models/spree/tracker.rb
115
+ - app/models/spree_analytics_trackers/user_decorator.rb
116
+ - app/overrides/add_analytics_to_admin_sidebar.rb
117
+ - app/overrides/add_cart_viewed_to_orders_edit.rb
118
+ - app/overrides/add_checkout_step_viewed_to_checkout_edit.rb
119
+ - app/overrides/add_google_analytics_page_view_to_spree_application.rb
120
+ - app/overrides/add_google_analytics_to_spree_application.rb
121
+ - app/overrides/add_google_purchase_to_orders_show.rb
122
+ - app/overrides/add_order_complete_to_orders_show.rb
123
+ - app/overrides/add_product_list_filtered_to_taxons_show.rb
124
+ - app/overrides/add_product_list_viewed_to_products_list.rb
125
+ - app/overrides/add_product_viewed_to_products_show.rb
126
+ - app/overrides/add_products_searched_to_products_list.rb
127
+ - app/overrides/add_segment_initializer_to_layout.rb
128
+ - app/overrides/add_segment_page_viewed_to_layout.rb
129
+ - app/presenters/spree_analytics_trackers/base_presenter.rb
130
+ - app/presenters/spree_analytics_trackers/segment/order_presenter.rb
131
+ - app/presenters/spree_analytics_trackers/segment/product_presenter.rb
132
+ - app/views/spree/admin/shared/_analytics_sidebar_menu.html.erb
133
+ - app/views/spree/admin/trackers/_form.html.erb
134
+ - app/views/spree/admin/trackers/edit.html.erb
135
+ - app/views/spree/admin/trackers/index.html.erb
136
+ - app/views/spree/admin/trackers/new.html.erb
137
+ - app/views/spree/shared/trackers/google_analytics/_checkout_step_viewed.js.erb
138
+ - app/views/spree/shared/trackers/google_analytics/_initializer.js.erb
139
+ - app/views/spree/shared/trackers/google_analytics/_page_viewed.js.erb
140
+ - app/views/spree/shared/trackers/google_analytics/_purchase.js.erb
141
+ - app/views/spree/shared/trackers/segment/_cart_viewed.js.erb
142
+ - app/views/spree/shared/trackers/segment/_checkout_step_viewed.js.erb
143
+ - app/views/spree/shared/trackers/segment/_initializer.js.erb
144
+ - app/views/spree/shared/trackers/segment/_order_complete.js.erb
145
+ - app/views/spree/shared/trackers/segment/_page_viewed.js.erb
146
+ - app/views/spree/shared/trackers/segment/_product_list_filtered.js.erb
147
+ - app/views/spree/shared/trackers/segment/_product_list_viewed.js.erb
148
+ - app/views/spree/shared/trackers/segment/_product_viewed.js.erb
149
+ - app/views/spree/shared/trackers/segment/_products_searched.js.erb
150
+ - bin/rails
151
+ - config/locales/en.yml
152
+ - config/locales/zh-TW.yml
153
+ - config/routes.rb
154
+ - db/migrate/20171013160337_create_spree_trackers.rb
155
+ - gemfiles/.bundle/config
156
+ - gemfiles/spree_4_1.gemfile
157
+ - gemfiles/spree_master.gemfile
158
+ - lib/generators/spree_analytics_trackers/install/install_generator.rb
159
+ - lib/spree_analytics_trackers.rb
160
+ - lib/spree_analytics_trackers/engine.rb
161
+ - lib/spree_analytics_trackers/factories.rb
162
+ - lib/spree_analytics_trackers/version.rb
163
+ - spec/features/admin/configuration/analytics_tracker_spec.rb
164
+ - spec/features/products_spec.rb
165
+ - spec/fixtures/thinking-cat.jpg
166
+ - spec/models/spree/tracker_spec.rb
167
+ - spec/presenters/spree_analytics_trackers/segment/order_presenter_spec.rb
168
+ - spec/spec_helper.rb
169
+ - spec/support/custom_products.rb
170
+ - spree_analytics_trackers.gemspec
171
+ homepage: https://github.com/spree-contrib/spree_analytics_trackers
172
+ licenses:
173
+ - BSD-3-Clause
174
+ metadata: {}
175
+ post_install_message:
176
+ rdoc_options: []
177
+ require_paths:
178
+ - lib
179
+ required_ruby_version: !ruby/object:Gem::Requirement
180
+ requirements:
181
+ - - ">="
182
+ - !ruby/object:Gem::Version
183
+ version: 2.5.0
184
+ required_rubygems_version: !ruby/object:Gem::Requirement
185
+ requirements:
186
+ - - ">"
187
+ - !ruby/object:Gem::Version
188
+ version: 1.3.1
189
+ requirements:
190
+ - none
191
+ rubygems_version: 3.1.2
192
+ signing_key:
193
+ specification_version: 4
194
+ summary: Adds analytics trackers functionality to Spree
195
+ test_files:
196
+ - spec/features/admin/configuration/analytics_tracker_spec.rb
197
+ - spec/features/products_spec.rb
198
+ - spec/fixtures/thinking-cat.jpg
199
+ - spec/models/spree/tracker_spec.rb
200
+ - spec/presenters/spree_analytics_trackers/segment/order_presenter_spec.rb
201
+ - spec/spec_helper.rb
202
+ - spec/support/custom_products.rb