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,18 @@
1
+ spree_version = Gem.loaded_specs['spree_core'].version
2
+ unless spree_version >= Gem::Version.create('3.3.0') && spree_version < Gem::Version.create('3.5.0') && spree_version != Gem::Version.create('3.5.0.alpha')
3
+ Deface::Override.new(
4
+ virtual_path: 'spree/layouts/spree_application',
5
+ name: 'add_google_analytics_page_viewed_to_spree_application',
6
+ insert_bottom: "[data-hook='body']",
7
+ partial: 'spree/shared/trackers/google_analytics/page_viewed.js',
8
+ original: '6841b819babbe4df1f03d0bc8e05dc81bf0d45ad'
9
+ )
10
+
11
+ Deface::Override.new(
12
+ virtual_path: 'spree/layouts/checkout',
13
+ name: 'add_google_analytics_page_viewed_to_spree_checkout',
14
+ insert_bottom: "[data-hook='body']",
15
+ partial: 'spree/shared/trackers/google_analytics/page_viewed.js',
16
+ original: '6841b819babbe4df1f03d0bc8e05dc81bf0d45ad'
17
+ )
18
+ end
@@ -0,0 +1,17 @@
1
+ if Gem.loaded_specs['spree_core'].version >= Gem::Version.create('3.5.0.alpha')
2
+ Deface::Override.new(
3
+ virtual_path: 'spree/layouts/spree_application',
4
+ name: 'add_google_analytics_initializer_to_spree_application',
5
+ insert_top: '[data-hook="inside_head"]',
6
+ partial: 'spree/shared/trackers/google_analytics/initializer.js',
7
+ original: 'cfa30a2831d9a41394c03229cd28b3c7eee69585'
8
+ )
9
+
10
+ Deface::Override.new(
11
+ virtual_path: 'spree/layouts/checkout',
12
+ name: 'add_google_analytics_initializer_to_spree_checkout',
13
+ insert_top: '[data-hook="inside_head"]',
14
+ partial: 'spree/shared/trackers/google_analytics/initializer.js',
15
+ original: 'ca3d46a134b93856baf937cf2e473da66d9d8efc'
16
+ )
17
+ end
@@ -0,0 +1,9 @@
1
+ if Gem.loaded_specs['spree_core'].version >= Gem::Version.create('3.5.0')
2
+ Deface::Override.new(
3
+ virtual_path: 'spree/orders/show',
4
+ name: 'add_google_purchase_to_orders_show',
5
+ insert_before: "#order_summary",
6
+ partial: 'spree/shared/trackers/google_analytics/purchase.js',
7
+ original: 'ac7f302922a3c1bb080095296ccc20e42bab2967'
8
+ )
9
+ end
@@ -0,0 +1,10 @@
1
+ spree_version = Gem.loaded_specs['spree_core'].version
2
+ unless spree_version >= Gem::Version.create('3.3.0') && spree_version < Gem::Version.create('3.5.0')
3
+ Deface::Override.new(
4
+ virtual_path: 'spree/orders/show',
5
+ name: 'add_order_complete_to_orders_show',
6
+ insert_before: "#order_summary",
7
+ partial: 'spree/shared/trackers/segment/order_complete.js',
8
+ original: 'ac7f302922a3c1bb080095296ccc20e42bab2967'
9
+ )
10
+ end
@@ -0,0 +1,10 @@
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/taxons/_header',
5
+ name: 'add_product_list_filtered_to_taxons_show',
6
+ insert_before: ".taxon-title",
7
+ original: '2d71d85f4cb141a6ff90264e48915493d6856e9b',
8
+ partial: 'spree/shared/trackers/segment/product_list_filtered.js'
9
+ )
10
+ end
@@ -0,0 +1,10 @@
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/shared/_products',
5
+ name: 'add_product_list_viewed_to_products_list',
6
+ insert_before: '[data-hook="homepage_products"]',
7
+ partial: 'spree/shared/trackers/segment/product_list_viewed.js',
8
+ original: '8b47dddca9dfaaacca3d462459c6c1ef06c09926'
9
+ )
10
+ end
@@ -0,0 +1,10 @@
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/products/show',
5
+ name: 'add_product_viewed_to_products_show',
6
+ insert_bottom: '[data-hook="product_show"]',
7
+ partial: 'spree/shared/trackers/segment/product_viewed.js',
8
+ original: '5426c263ccfe477b270b55024abebc77cf951c91'
9
+ )
10
+ end
@@ -0,0 +1,10 @@
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/products/index',
5
+ name: 'add_products_searched_to_products_list',
6
+ insert_before: '[data-hook="search_results"]',
7
+ partial: 'spree/shared/trackers/segment/products_searched.js',
8
+ original: '8b47dddca9dfaaacca3d462459c6c1ef06c09926'
9
+ )
10
+ end
@@ -0,0 +1,18 @@
1
+ spree_version = Gem.loaded_specs['spree_core'].version
2
+ unless spree_version >= Gem::Version.create('3.3.0') && spree_version < Gem::Version.create('3.5.0') && spree_version != Gem::Version.create('3.5.0.alpha')
3
+ Deface::Override.new(
4
+ virtual_path: 'spree/layouts/spree_application',
5
+ name: 'add_segment_initializer_to_layout',
6
+ insert_bottom: '[data-hook="inside_head"]',
7
+ partial: 'spree/shared/trackers/segment/initializer.js',
8
+ original: '6841b819babbe4df1f03d0bc8e05dc81bf0d45ad'
9
+ )
10
+
11
+ Deface::Override.new(
12
+ virtual_path: 'spree/layouts/checkout',
13
+ name: 'add_segment_initializer_to_spree_checkout',
14
+ insert_bottom: '[data-hook="inside_head"]',
15
+ partial: 'spree/shared/trackers/segment/initializer.js',
16
+ original: '6841b819babbe4df1f03d0bc8e05dc81bf0d45ad'
17
+ )
18
+ end
@@ -0,0 +1,18 @@
1
+ spree_version = Gem.loaded_specs['spree_core'].version
2
+ unless spree_version >= Gem::Version.create('3.3.0') && spree_version < Gem::Version.create('3.5.0') && spree_version != Gem::Version.create('3.5.0.alpha')
3
+ Deface::Override.new(
4
+ virtual_path: 'spree/layouts/spree_application',
5
+ name: 'add_segment_page_tracker_to_body',
6
+ insert_bottom: "[data-hook='body']",
7
+ partial: 'spree/shared/trackers/segment/page_viewed.js',
8
+ original: '6841b819babbe4df1f03d0bc8e05dc81bf0d45ad'
9
+ )
10
+
11
+ Deface::Override.new(
12
+ virtual_path: 'spree/layouts/checkout',
13
+ name: 'add_segment_page_tracker_to_spree_checkout',
14
+ insert_bottom: "[data-hook='body']",
15
+ partial: 'spree/shared/trackers/segment/page_viewed.js',
16
+ original: '6841b819babbe4df1f03d0bc8e05dc81bf0d45ad'
17
+ )
18
+ end
@@ -0,0 +1,14 @@
1
+ module SpreeAnalyticsTrackers
2
+ class BasePresenter
3
+ include Rails.application.routes.url_helpers
4
+
5
+ def initialize(resource = {}, options = {})
6
+ @resource = resource
7
+ @options = options
8
+ end
9
+
10
+ def to_json
11
+ serialize_resource(@resource, @options).to_json
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,32 @@
1
+ module SpreeAnalyticsTrackers
2
+ module Segment
3
+ class OrderPresenter < SpreeAnalyticsTrackers::BasePresenter
4
+ private
5
+
6
+ def serialize_resource(resource, options = {})
7
+ {
8
+ order_id: resource.number.to_s,
9
+ total: resource.total&.to_f,
10
+ shipping: resource.shipment_total&.to_f,
11
+ tax: resource.additional_tax_total&.to_f,
12
+ discount: resource.promo_total&.to_f,
13
+ coupon: resource.promo_code,
14
+ currency: resource.currency,
15
+ products: resource.line_items.map { |li| serialize_line_item(li) }
16
+ }
17
+ end
18
+
19
+ private
20
+
21
+ def serialize_line_item(line_item)
22
+ {
23
+ product_id: line_item.product_id&.to_s,
24
+ sku: line_item.sku&.to_s,
25
+ name: line_item.name,
26
+ price: line_item.price&.to_f,
27
+ quantity: line_item.quantity
28
+ }
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,40 @@
1
+ module SpreeAnalyticsTrackers
2
+ module Segment
3
+ class ProductPresenter < SpreeAnalyticsTrackers::BasePresenter
4
+ private
5
+
6
+ def serialize_resource(resource, options = {})
7
+ {
8
+ resource_id: resource.id.to_s,
9
+ sku: resource.sku&.to_s,
10
+ category: resource.category&.name,
11
+ name: resource.name,
12
+ brand: brand_name,
13
+ price: resource.price_in(current_currency).amount&.to_f,
14
+ currency: current_currency,
15
+ url: resource_url(resource)
16
+ }.tap do |hash|
17
+ hash[:image_url] = segment_image_url(hash, options)
18
+ end.merge(options)
19
+ end
20
+
21
+ def segment_image_url(hash, options)
22
+
23
+ end
24
+
25
+ def brand_name
26
+ resource.vendor.name if defined?(SpreeMultiVendor) && resource.defined?(:vendor) && resource.vendor.present?
27
+
28
+ resource.brand&.name
29
+ end
30
+
31
+ def current_currency
32
+ @current_currency ||= options[:current_currency]
33
+ end
34
+
35
+ def locale
36
+ @locale ||= options[:locale]
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,3 @@
1
+ <%= configurations_sidebar_menu_item(
2
+ Spree.t(:analytics), spree.admin_trackers_path
3
+ ) if can? :manage, Spree::Config %>
@@ -0,0 +1,36 @@
1
+ <div data-hook="admin_tracker_form_fields" class="row">
2
+ <div class="col-12 col-lg-6" data-hook="analytics_engine">
3
+ <%= f.field_container :engine, class: ["form-group"], "data-hook" => "analytics_engine" do %>
4
+ <%= f.label :engine, Spree.t(:analytics_engine) %>
5
+ <%= f.select :engine, Spree::Tracker.engines.keys.sort.map { |k| [k.humanize, k] }, {}, { class: 'select2' } %>
6
+ <%= f.error_message_on :engine %>
7
+ <% end %>
8
+ </div>
9
+ <div class="col-12 col-lg-6">
10
+ <div data-hook="active" class="form-group">
11
+ <%= label_tag nil, Spree.t(:active) %>
12
+ <div class="radio">
13
+ <%= label_tag :tracker_active_true do %>
14
+ <%= radio_button(:tracker, :active, true) %>
15
+ <%= Spree.t(:say_yes) %>
16
+ <% end %>
17
+ </div>
18
+ <div class="radio">
19
+ <%= label_tag :tracker_active_false do %>
20
+ <%= radio_button(:tracker, :active, false) %>
21
+ <%= Spree.t(:say_no) %>
22
+ <% end %>
23
+ </div>
24
+ </div>
25
+ </div>
26
+ <div class="col-12 col-lg-6" data-hook="analytics_id">
27
+ <%= f.field_container :analytics_id, class: ["form-group"], "data-hook" => "analytics_id" do %>
28
+ <%= f.label :analytics_id, Spree.t(:google_analytics_id) %>
29
+ <%= f.text_field :analytics_id, class: 'form-control' %>
30
+ <%= f.error_message_on :analytics_id %>
31
+ <% end %>
32
+ </div>
33
+ <div class="col-12 col-lg-6" data-hook="additional_tracker_fields"></div>
34
+ </div>
35
+
36
+ <div data-hook="admin_tracker_form_fields" class="row"></div>
@@ -0,0 +1,13 @@
1
+ <% content_for :page_title do %>
2
+ <%= link_to Spree.t(:analytics_trackers), spree.admin_trackers_url %> /
3
+ <%= @tracker.analytics_id %>
4
+ <% end %>
5
+
6
+ <%= render partial: 'spree/admin/shared/error_messages', locals: { target: @tracker } %>
7
+
8
+ <%= form_for [:admin, @tracker] do |f| %>
9
+ <fieldset>
10
+ <%= render partial: 'form', locals: { f: f } %>
11
+ <%= render partial: 'spree/admin/shared/edit_resource_links' %>
12
+ </fieldset>
13
+ <% end %>
@@ -0,0 +1,40 @@
1
+ <% content_for :page_title do %>
2
+ <%= Spree.t(:analytics_trackers) %>
3
+ <% end %>
4
+
5
+ <% content_for :page_actions do %>
6
+ <%= button_link_to Spree.t(:new_tracker), new_object_url, class: "btn-success", icon: 'add', id: 'admin_new_tracker_link' %>
7
+ <% end if can? :create, Spree::Tracker %>
8
+
9
+ <% if @trackers.any? %>
10
+ <table class="table">
11
+ <thead>
12
+ <tr data-hook="admin_trackers_index_headers">
13
+ <th><%= Spree.t(:google_analytics_id) %></th>
14
+ <th><%= Spree.t(:analytics_engine) %></th>
15
+ <th class="text-center"><%= Spree.t(:active) %></th>
16
+ <th class="actions"></th>
17
+ </tr>
18
+ </thead>
19
+ <tbody>
20
+ <% @trackers.each do |tracker|%>
21
+ <tr id="<%= spree_dom_id tracker %>" data-hook="admin_trackers_index_rows">
22
+ <td><%= tracker.analytics_id %></td>
23
+ <td><%= tracker.engine.humanize %></td>
24
+ <td class="text-center">
25
+ <%= tracker.active ? Spree.t(:say_yes) : Spree.t(:say_no) %>
26
+ </td>
27
+ <td class="actions text-right">
28
+ <%= link_to_edit(tracker, no_text: true) if can? :edit, tracker %>
29
+ <%= link_to_delete(tracker, no_text: true) if can? :delete, tracker %>
30
+ </td>
31
+ </tr>
32
+ <% end %>
33
+ </tbody>
34
+ </table>
35
+ <% else %>
36
+ <div class="alert alert-info">
37
+ <%= Spree.t(:no_resource_found, resource: plural_resource_name(Spree::Tracker)) %>,
38
+ <%= link_to(Spree.t(:add_one), new_object_url) if can? :create, Spree::Tracker %>!
39
+ </div>
40
+ <% end %>
@@ -0,0 +1,13 @@
1
+ <% content_for :page_title do %>
2
+ <%= link_to Spree.t(:analytics_trackers), spree.admin_trackers_url %> /
3
+ <%= Spree.t(:new_tracker) %>
4
+ <% end %>
5
+
6
+ <%= render partial: 'spree/admin/shared/error_messages', locals: { target: @tracker } %>
7
+
8
+ <%= form_for [:admin, @tracker] do |f| %>
9
+ <fieldset>
10
+ <%= render partial: 'form', locals: { f: f } %>
11
+ <%= render partial: 'spree/admin/shared/new_resource_links' %>
12
+ </fieldset>
13
+ <% end %>
@@ -0,0 +1,21 @@
1
+ <% if @order.present? && !@order.completed? && Spree::Tracker.current(:google_analytics) %>
2
+ <script>
3
+ if (typeof gtag !== 'undefined') {
4
+ gtag('event', 'checkout_progress', {
5
+ checkout_step: '<%= (@order.checkout_steps.index(@order.state) + 1) %>',
6
+ items: [
7
+ <% @order.line_items.each do |line_item| %>
8
+ <%= ga_line_item(line_item) %>,
9
+ <% end %>
10
+ ],
11
+
12
+ coupon: '<%= @order.promo_code %>',
13
+ });
14
+
15
+ gtag('event', 'set_checkout_option', {
16
+ 'checkout_step': '<%= (@order.checkout_steps.index(@order.state) + 1) %>',
17
+ 'checkout_option': '<%= @order.state %>'
18
+ });
19
+ };
20
+ </script>
21
+ <% end %>
@@ -0,0 +1,11 @@
1
+ <% if tracker = Spree::Tracker.current(:google_analytics) %>
2
+ <!-- Global site tag (gtag.js) - Google Analytics -->
3
+ <script async src="https://www.googletagmanager.com/gtag/js?id=<%= tracker.analytics_id %>"></script>
4
+ <script>
5
+ window.dataLayer = window.dataLayer || [];
6
+ function gtag(){dataLayer.push(arguments);}
7
+ gtag('js', new Date());
8
+
9
+ gtag('config', '<%= tracker.analytics_id %>', { 'send_page_view': false });
10
+ </script>
11
+ <% end %>
@@ -0,0 +1,13 @@
1
+ <% if tracker = Spree::Tracker.current(:google_analytics) %>
2
+ <script>
3
+ if (typeof gtag !== 'undefined') {
4
+ <% if user_id = try_spree_current_user.try(:id) %>
5
+ gtag('config', '<%= tracker.analytics_id %>', {
6
+ 'user_id': '<%= user_id %>'
7
+ });
8
+ <% else %>
9
+ gtag('config', '<%= tracker.analytics_id %>');
10
+ <% end %>
11
+ }
12
+ </script>
13
+ <% end %>
@@ -0,0 +1,19 @@
1
+ <% if @order.present? && order_just_completed?(@order) && Spree::Tracker.current(:google_analytics) %>
2
+ <script>
3
+ if (typeof gtag !== 'undefined') {
4
+ gtag('event', 'purchase', {
5
+ transaction_id: '<%= @order.number %>',
6
+ value: <%= @order.total&.to_f %>,
7
+ currency: '<%= @order.currency %>',
8
+ tax: <%= @order.tax_total&.to_f %>,
9
+ shipping: <%= @order.shipment_total&.to_f %>,
10
+ coupon: '<%= @order.promo_code %>',
11
+ items: [
12
+ <% @order.line_items.each do |line_item| %>
13
+ <%= ga_line_item(line_item) %>,
14
+ <% end %>
15
+ ]
16
+ });
17
+ }
18
+ </script>
19
+ <% end %>
@@ -0,0 +1,22 @@
1
+ <% if @order.present? && !@order.complete? && Spree::Tracker.current(:segment) %>
2
+ <script>
3
+ if (typeof analytics !== 'undefined') {
4
+ var segmentCartJson = {
5
+ cart_id: '<%= @order.number %>',
6
+ products: [
7
+ <% @order.line_items.each_with_index do |line_item, index| %>
8
+ <%= product_for_segment(
9
+ line_item.product,
10
+ position: index+1,
11
+ quantity: line_item.quantity,
12
+ image: default_image_for_product_or_variant(line_item.variant)
13
+ ) %>,
14
+ <% end %>
15
+ ]
16
+ }
17
+
18
+ analytics.track('Cart Viewed', segmentCartJson);
19
+ analytics.page('Cart Viewed', segmentCartJson);
20
+ }
21
+ </script>
22
+ <% end %>