spree_analytics_trackers 1.0.1 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +4 -4
  2. data/.bundle/config +2 -0
  3. data/.rubocop.yml +2 -0
  4. data/.travis.yml +30 -15
  5. data/Appraisals +3 -9
  6. data/LICENSE +1 -1
  7. data/README.md +7 -3
  8. data/app/assets/javascripts/spree/frontend/add_to_cart_analytics.js +50 -0
  9. data/app/assets/javascripts/spree/frontend/remove_from_cart_analytics.js +34 -0
  10. data/app/controllers/spree/admin/trackers_controller.rb +8 -0
  11. data/app/controllers/spree_analytics_trackers/checkout_controller_decorator.rb +11 -0
  12. data/app/controllers/spree_analytics_trackers/store_controller_decorator.rb +13 -0
  13. data/app/controllers/spree_analytics_trackers/user_confirmations_controller_decorator.rb +11 -0
  14. data/app/controllers/spree_analytics_trackers/user_passwords_controller_decorator.rb +11 -0
  15. data/app/controllers/spree_analytics_trackers/user_registrations_controller_decorator.rb +11 -0
  16. data/app/controllers/spree_analytics_trackers/user_sessions_controller_decorator.rb +11 -0
  17. data/app/helpers/spree/trackers_helper.rb +79 -16
  18. data/app/models/spree/tracker.rb +11 -5
  19. data/app/models/spree_analytics_trackers/user_decorator.rb +9 -0
  20. data/app/overrides/add_analytics_to_admin_sidebar.rb +2 -3
  21. data/app/overrides/add_cart_viewed_to_orders_edit.rb +1 -1
  22. data/app/overrides/add_checkout_step_viewed_to_checkout_edit.rb +11 -3
  23. data/app/overrides/add_google_analytics_page_view_to_spree_application.rb +10 -0
  24. data/app/overrides/add_google_analytics_to_spree_application.rb +4 -4
  25. data/app/overrides/add_google_purchase_to_orders_show.rb +1 -1
  26. data/app/overrides/add_product_list_filtered_to_taxons_show.rb +1 -1
  27. data/app/overrides/add_product_list_viewed_to_products_list.rb +1 -1
  28. data/app/overrides/add_product_viewed_to_products_show.rb +2 -2
  29. data/app/overrides/add_products_searched_to_products_list.rb +2 -2
  30. data/app/overrides/add_segment_initializer_to_layout.rb +3 -3
  31. data/app/overrides/add_segment_page_viewed_to_layout.rb +10 -0
  32. data/app/presenters/spree_analytics_trackers/base_presenter.rb +14 -0
  33. data/app/presenters/spree_analytics_trackers/segment/order_presenter.rb +32 -0
  34. data/app/presenters/spree_analytics_trackers/segment/product_presenter.rb +40 -0
  35. data/app/views/spree/admin/shared/_analytics_sidebar_menu.html.erb +3 -5
  36. data/app/views/spree/admin/trackers/_form.html.erb +13 -7
  37. data/app/views/spree/admin/trackers/index.html.erb +6 -8
  38. data/app/views/spree/shared/trackers/google_analytics/_checkout_step_viewed.js.erb +19 -0
  39. data/app/views/spree/shared/trackers/google_analytics/_initializer.js.erb +25 -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 +22 -0
  42. data/app/views/spree/shared/trackers/segment/_cart_viewed.js.erb +24 -19
  43. data/app/views/spree/shared/trackers/segment/_checkout_step_viewed.js.erb +20 -11
  44. data/app/views/spree/shared/trackers/segment/_initializer.js.erb +2 -3
  45. data/app/views/spree/shared/trackers/segment/_order_complete.js.erb +8 -45
  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 +19 -28
  48. data/app/views/spree/shared/trackers/segment/_product_list_viewed.js.erb +17 -20
  49. data/app/views/spree/shared/trackers/segment/_product_viewed.js.erb +12 -6
  50. data/app/views/spree/shared/trackers/segment/_products_searched.js.erb +7 -9
  51. data/config/locales/en.yml +0 -2
  52. data/config/locales/zh-TW.yml +19 -0
  53. data/db/migrate/20200721163729_add_store_id_to_spree_trackers.rb +14 -0
  54. data/gemfiles/{spree_3_5.gemfile → spree_4_1.gemfile} +2 -2
  55. data/gemfiles/spree_master.gemfile +0 -1
  56. data/lib/generators/spree_analytics_trackers/install/install_generator.rb +8 -0
  57. data/lib/spree_analytics_trackers.rb +1 -0
  58. data/lib/spree_analytics_trackers/factories.rb +1 -0
  59. data/lib/spree_analytics_trackers/version.rb +3 -9
  60. data/spec/features/admin/configuration/analytics_tracker_spec.rb +18 -7
  61. data/spec/features/checkout_spec.rb +15 -0
  62. data/spec/features/products_spec.rb +315 -0
  63. data/spec/features/user_login_spec.rb +7 -0
  64. data/spec/features/user_password_recovery_spec.rb +7 -0
  65. data/spec/features/user_registration_spec.rb +7 -0
  66. data/spec/fixtures/thinking-cat.jpg +0 -0
  67. data/spec/models/spree/tracker_spec.rb +15 -0
  68. data/spec/presenters/spree_analytics_trackers/segment/order_presenter_spec.rb +34 -0
  69. data/spec/spec_helper.rb +7 -82
  70. data/spec/support/custom_products.rb +26 -0
  71. data/spree_analytics_trackers.gemspec +4 -17
  72. metadata +56 -212
  73. data/app/controllers/spree/store_controller_decorator.rb +0 -5
  74. data/app/models/spree/line_item_decorator.rb +0 -6
  75. data/app/models/spree/order_decorator.rb +0 -7
  76. data/app/models/spree/product_decorator.rb +0 -11
  77. data/app/models/spree/user_decorator.rb +0 -5
  78. data/app/overrides/add_google_checkout_to_checkout_edit.rb +0 -9
  79. data/app/overrides/add_product_added_to_orders_edit.rb +0 -10
  80. data/app/views/spree/shared/_google_add_items.html.erb +0 -13
  81. data/app/views/spree/shared/_google_analytics.html.erb +0 -18
  82. data/app/views/spree/shared/_google_checkout.html.erb +0 -14
  83. data/app/views/spree/shared/_google_purchase.html.erb +0 -19
  84. data/app/views/spree/shared/trackers/segment/_product_added.js.erb +0 -9
  85. data/gemfiles/spree_3_7.gemfile +0 -9
@@ -1,5 +0,0 @@
1
- if defined?(Spree::StoreController)
2
- Spree::StoreController.class_eval do
3
- helper Spree::TrackersHelper
4
- end
5
- end
@@ -1,6 +0,0 @@
1
- if Gem.loaded_specs['spree_core'].version < Gem::Version.create('3.2.0')
2
- Spree::LineItem.class_eval do
3
- delegate :brand, :category, to: :product
4
- delegate :options_text, to: :variant
5
- end
6
- end
@@ -1,7 +0,0 @@
1
- if Gem.loaded_specs['spree_core'].version < Gem::Version.create('3.3.0')
2
- Spree::Order.class_eval do
3
- def promo_code
4
- promotions.pluck(:code).compact.first
5
- end
6
- end
7
- end
@@ -1,11 +0,0 @@
1
- if Gem.loaded_specs['spree_core'].version < Gem::Version.create('3.2.0')
2
- Spree::Product.class_eval do
3
- def category
4
- taxons.joins(:taxonomy).find_by(spree_taxonomies: { name: Spree.t(:taxonomy_categories_name) })
5
- end
6
-
7
- def brand
8
- taxons.joins(:taxonomy).find_by(spree_taxonomies: { name: Spree.t(:taxonomy_brands_name) })
9
- end
10
- end
11
- end
@@ -1,5 +0,0 @@
1
- Spree.user_class.class_eval do
2
- def analytics_id
3
- id
4
- end
5
- end
@@ -1,9 +0,0 @@
1
- if Gem.loaded_specs['spree_core'].version >= Gem::Version.create('3.5.0')
2
- Deface::Override.new(
3
- virtual_path: 'spree/checkout/edit',
4
- name: 'add_google_checkout_to_checkout_edit',
5
- insert_before: "#checkout",
6
- partial: 'spree/shared/google_checkout',
7
- original: '1bc9409097210501fee61bc448df937682546308'
8
- )
9
- end
@@ -1,10 +0,0 @@
1
- spree_version = Gem.loaded_specs['spree_core'].version
2
- unless spree_version >= Gem::Version.create('3.4.0') && spree_version < Gem::Version.create('3.5.0')
3
- Deface::Override.new(
4
- virtual_path: 'spree/orders/edit',
5
- name: 'add_product_added_to_orders_edit',
6
- insert_top: "[data-hook='cart_container']",
7
- partial: 'spree/shared/trackers/segment/product_added.js',
8
- original: '75a9171ce7647353a00bdfa178b131872e7f9bdc'
9
- )
10
- end
@@ -1,13 +0,0 @@
1
- if (typeof ga !== 'undefined') {
2
- <% @order.line_items.each do |line_item| %>
3
- ga('ec:addProduct', { // Provide product details in a productFieldObject.
4
- 'id': '<%= j (line_item.sku.present? ? line_item.sku : line_item.variant_id.to_s) %>', // Product ID (string).
5
- 'name': '<%= j line_item.name %>', // Product name (string).
6
- 'category': '<%= j line_item.category.try(:name) %>', // Product category (string).
7
- 'brand': '<%= j line_item.brand.try(:name) %>', // Product brand (string).
8
- 'variant': '<%= j line_item.options_text %>', // Product variant (string).
9
- 'price': '<%= line_item.price %>',
10
- 'quantity': <%= line_item.quantity %>
11
- });
12
- <% end %>
13
- }
@@ -1,18 +0,0 @@
1
- <% if tracker = Spree::Tracker.current(:google_analytics) %>
2
- <script>
3
- (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
4
- (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
5
- m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
6
- })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
7
-
8
- <% if user_analytics_id = try_spree_current_user.try(:analytics_id) %>
9
- ga('create', { 'trackingId': '<%= tracker.analytics_id %>', 'cookieDomain': 'auto', 'userId': '<%= user_analytics_id %>' });
10
- <% else %>
11
- ga('create', '<%= tracker.analytics_id %>', 'auto');
12
- <% end %>
13
-
14
- ga('require', 'displayfeatures');
15
- <%= yield :google_analytics %>
16
- ga('send', 'pageview');
17
- </script>
18
- <% end %>
@@ -1,14 +0,0 @@
1
- <%# more info: https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce %>
2
- <script>
3
- if (typeof ga !== 'undefined') {
4
- ga('require', 'ec');
5
- ga('set', '&cu', '<%= current_currency %>');
6
-
7
- <%= render partial: 'spree/shared/google_add_items', locals: { order: @order } %>
8
-
9
- // Add the step number and additional info about the checkout to the action.
10
- ga('ec:setAction','checkout', {
11
- 'step': <%= (@order.checkout_steps.index(@order.state) + 1) %>
12
- });
13
- }
14
- </script>
@@ -1,19 +0,0 @@
1
- <% if order_just_completed?(@order) %>
2
- <script>
3
- <%# more info: https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce %>
4
- if (typeof ga !== 'undefined') {
5
- ga('require', 'ec');
6
- ga('set', '&cu', '<%= current_currency %>');
7
-
8
- <%= render partial: 'spree/shared/google_add_items', locals: { order: @order } %>
9
-
10
- ga('ec:setAction', 'purchase', { // Transaction details are provided in an actionFieldObject.
11
- 'id': '<%= j @order.number %>', // Transaction ID. Required.
12
- 'affiliation': '<%= current_store.name %>', // Affiliation (string).
13
- 'revenue': '<%= @order.total %>', // Revenue (currency).
14
- 'tax': '<%= @order.tax_total %>', // Tax.
15
- 'shipping': '<%= @order.ship_total %>' // Shipping.
16
- });
17
- }
18
- </script>
19
- <% end %>
@@ -1,9 +0,0 @@
1
- <% if @variant %>
2
- <script>
3
- if (typeof analytics !== 'undefined') {
4
- analytics.track('Product Added', <%= product_for_segment(@variant.product, cart_id: @order.number) %>);
5
- analytics.page('Product Added', <%= product_for_segment(@variant.product, cart_id: @order.number) %>);
6
-
7
- }
8
- </script>
9
- <% end %>
@@ -1,9 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "spree", "~> 3.7.0"
6
- gem "spree_auth_devise", "~> 3.5.0"
7
- gem "rails-controller-testing"
8
-
9
- gemspec path: "../"