spree_analytics_trackers 2.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/assets/javascripts/spree/frontend/remove_from_cart_analytics.js +34 -0
- data/app/helpers/spree/trackers_helper.rb +16 -0
- data/app/overrides/add_google_analytics_to_spree_application.rb +1 -1
- data/app/overrides/add_segment_initializer_to_layout.rb +1 -1
- data/app/views/spree/shared/trackers/google_analytics/_checkout_step_viewed.js.erb +16 -15
- data/app/views/spree/shared/trackers/google_analytics/_initializer.js.erb +3 -3
- data/app/views/spree/shared/trackers/google_analytics/_page_viewed.js.erb +3 -3
- data/app/views/spree/shared/trackers/google_analytics/_purchase.js.erb +19 -17
- data/app/views/spree/shared/trackers/segment/_cart_viewed.js.erb +23 -18
- data/app/views/spree/shared/trackers/segment/_checkout_step_viewed.js.erb +18 -11
- data/app/views/spree/shared/trackers/segment/_initializer.js.erb +2 -2
- data/app/views/spree/shared/trackers/segment/_order_complete.js.erb +7 -4
- data/app/views/spree/shared/trackers/segment/_page_viewed.js.erb +1 -1
- data/app/views/spree/shared/trackers/segment/_product_list_filtered.js.erb +19 -17
- data/app/views/spree/shared/trackers/segment/_product_list_viewed.js.erb +15 -13
- data/app/views/spree/shared/trackers/segment/_product_viewed.js.erb +8 -6
- data/app/views/spree/shared/trackers/segment/_products_searched.js.erb +7 -9
- data/lib/generators/spree_analytics_trackers/install/install_generator.rb +1 -0
- data/lib/spree_analytics_trackers/version.rb +1 -1
- metadata +7 -6
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 502cf1fa8e70cb9ceb4e1b24ec08c257cb5314249e5ab3403aa61ae463fb69fc
         | 
| 4 | 
            +
              data.tar.gz: 4c44fd4f1c8172a51499a1e4bcef65538e185ad2c8ace20728a05c28e8347542
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 7824a5e18c3a7d0cd5afdb714f5ef4f727acfbc13e542ad7d33451b5478db03a530ae17dacb48a2dfc799084b3fd4a266417a6c6dfa2dd58d6d98a01c4625c2e
         | 
| 7 | 
            +
              data.tar.gz: 54f3aeb09eb35e8c0a285778b5e2c91a57dcdd5971b618343a006fcc8a5dbaf7073fbcf902d540c52788d630848992f8e83ff4ec5511dde26295ea64a9ffa959
         | 
| @@ -0,0 +1,34 @@ | |
| 1 | 
            +
            //= require spree/frontend
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            function gaRemoveFromCart(variant) {
         | 
| 4 | 
            +
              clearGAplugins();
         | 
| 5 | 
            +
              gtag(
         | 
| 6 | 
            +
                'event',
         | 
| 7 | 
            +
                'remove_from_cart',
         | 
| 8 | 
            +
                {
         | 
| 9 | 
            +
                  items: [{
         | 
| 10 | 
            +
                    id: variant.sku,
         | 
| 11 | 
            +
                    name: variant.name,
         | 
| 12 | 
            +
                    price: variant.price,
         | 
| 13 | 
            +
                    variant: variant.options,
         | 
| 14 | 
            +
                    quantity: variant.quantity
         | 
| 15 | 
            +
                  }]
         | 
| 16 | 
            +
                }
         | 
| 17 | 
            +
              );
         | 
| 18 | 
            +
            }
         | 
| 19 | 
            +
             | 
| 20 | 
            +
            Spree.ready(function(){
         | 
| 21 | 
            +
              $('body').on('product_remove_from_cart', function(event) {
         | 
| 22 | 
            +
                var variant = {
         | 
| 23 | 
            +
                  sku: event.variant_sku,
         | 
| 24 | 
            +
                  name: event.variant_name,
         | 
| 25 | 
            +
                  price: event.variant_price,
         | 
| 26 | 
            +
                  options: event.variant_options,
         | 
| 27 | 
            +
                  quantity: event.variant_quantity
         | 
| 28 | 
            +
                }
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                if (typeof gtag !== 'undefined') {
         | 
| 31 | 
            +
                  gaRemoveFromCart(variant)
         | 
| 32 | 
            +
                }
         | 
| 33 | 
            +
              })
         | 
| 34 | 
            +
            })
         | 
| @@ -66,5 +66,21 @@ module Spree | |
| 66 66 | 
             
                  end
         | 
| 67 67 | 
             
                  params_with_values
         | 
| 68 68 | 
             
                end
         | 
| 69 | 
            +
             | 
| 70 | 
            +
                def segment_tracker
         | 
| 71 | 
            +
                  @segment_tracker ||= Spree::Tracker.current(:segment, current_store)
         | 
| 72 | 
            +
                end
         | 
| 73 | 
            +
             | 
| 74 | 
            +
                def segment_enabled?
         | 
| 75 | 
            +
                  segment_tracker.present?
         | 
| 76 | 
            +
                end
         | 
| 77 | 
            +
             | 
| 78 | 
            +
                def ga_tracker
         | 
| 79 | 
            +
                  @ga_tracker ||= Spree::Tracker.current(:google_analytics, current_store)
         | 
| 80 | 
            +
                end
         | 
| 81 | 
            +
             | 
| 82 | 
            +
                def ga_enabled?
         | 
| 83 | 
            +
                  ga_tracker.present?
         | 
| 84 | 
            +
                end
         | 
| 69 85 | 
             
              end
         | 
| 70 86 | 
             
            end
         | 
| @@ -2,7 +2,7 @@ if Gem.loaded_specs['spree_core'].version >= Gem::Version.create('3.5.0.alpha') | |
| 2 2 | 
             
              Deface::Override.new(
         | 
| 3 3 | 
             
                virtual_path: 'spree/shared/_head',
         | 
| 4 4 | 
             
                name: 'add_google_analytics_initializer_to_spree_application',
         | 
| 5 | 
            -
                 | 
| 5 | 
            +
                insert_after: 'title',
         | 
| 6 6 | 
             
                partial: 'spree/shared/trackers/google_analytics/initializer.js',
         | 
| 7 7 | 
             
                original: 'cfa30a2831d9a41394c03229cd28b3c7eee69585'
         | 
| 8 8 | 
             
              )
         | 
| @@ -3,7 +3,7 @@ unless spree_version >= Gem::Version.create('3.3.0') && spree_version < Gem::Ver | |
| 3 3 | 
             
              Deface::Override.new(
         | 
| 4 4 | 
             
                virtual_path: 'spree/shared/_head',
         | 
| 5 5 | 
             
                name: 'add_segment_initializer_to_layout',
         | 
| 6 | 
            -
                 | 
| 6 | 
            +
                insert_after: 'title',
         | 
| 7 7 | 
             
                partial: 'spree/shared/trackers/segment/initializer.js',
         | 
| 8 8 | 
             
                original: '6841b819babbe4df1f03d0bc8e05dc81bf0d45ad'
         | 
| 9 9 | 
             
              )
         | 
| @@ -1,18 +1,19 @@ | |
| 1 | 
            -
            <% if @order.present? && !@order.completed?  | 
| 1 | 
            +
            <% if ga_enabled? && @order.present? && !@order.completed? %>
         | 
| 2 2 | 
             
              <script>
         | 
| 3 | 
            -
                 | 
| 4 | 
            -
                   | 
| 5 | 
            -
             | 
| 6 | 
            -
                     | 
| 7 | 
            -
             | 
| 8 | 
            -
                       | 
| 9 | 
            -
                         | 
| 10 | 
            -
             | 
| 11 | 
            -
             | 
| 12 | 
            -
             | 
| 13 | 
            -
             | 
| 14 | 
            -
             | 
| 15 | 
            -
             | 
| 16 | 
            -
             | 
| 3 | 
            +
                window.addEventListener('turbolinks:load', function() {
         | 
| 4 | 
            +
                  if (typeof gtag !== 'undefined') {
         | 
| 5 | 
            +
                    clearGAplugins();
         | 
| 6 | 
            +
                    gtag('event', 'checkout_progress', {
         | 
| 7 | 
            +
                      checkout_step: '<%= (@order.checkout_steps.index(@order.state) + 1) %>',
         | 
| 8 | 
            +
                      items: [
         | 
| 9 | 
            +
                        <% @order.line_items.each do |line_item| %>
         | 
| 10 | 
            +
                          <%= ga_line_item(line_item) %>,
         | 
| 11 | 
            +
                        <% end %>
         | 
| 12 | 
            +
                      ],
         | 
| 13 | 
            +
                      coupon: '<%= @order.promo_code %>',
         | 
| 14 | 
            +
                      checkout_option: '<%= @order.state %>'
         | 
| 15 | 
            +
                    });
         | 
| 16 | 
            +
                  };
         | 
| 17 | 
            +
                });
         | 
| 17 18 | 
             
              </script>
         | 
| 18 19 | 
             
            <% end %>
         | 
| @@ -1,12 +1,12 @@ | |
| 1 | 
            -
            <% if  | 
| 1 | 
            +
            <% if ga_enabled? %>
         | 
| 2 2 | 
             
              <!-- Global site tag (gtag.js) - Google Analytics -->
         | 
| 3 | 
            -
              <script async src="https://www.googletagmanager.com/gtag/js?id=<%=  | 
| 3 | 
            +
              <script async src="https://www.googletagmanager.com/gtag/js?id=<%= ga_tracker.analytics_id %>"></script>
         | 
| 4 4 | 
             
              <script>
         | 
| 5 5 | 
             
                window.dataLayer = window.dataLayer || [];
         | 
| 6 6 | 
             
                function gtag(){dataLayer.push(arguments);}
         | 
| 7 7 | 
             
                gtag('js', new Date());
         | 
| 8 8 |  | 
| 9 | 
            -
                gtag('config', '<%=  | 
| 9 | 
            +
                gtag('config', '<%= ga_tracker.analytics_id %>', { 'send_page_view': false });
         | 
| 10 10 | 
             
                gtag('set', 'allow_google_signals', true )
         | 
| 11 11 | 
             
                gtag('set', 'allow_ad_personalization_signals', true );
         | 
| 12 12 |  | 
| @@ -1,12 +1,12 @@ | |
| 1 | 
            -
            <% if  | 
| 1 | 
            +
            <% if ga_enabled? %>
         | 
| 2 2 | 
             
              <script>
         | 
| 3 3 | 
             
                if (typeof gtag !== 'undefined') {
         | 
| 4 4 | 
             
                  <% if user_id = try_spree_current_user.try(:id) %>
         | 
| 5 | 
            -
                    gtag('config', '<%=  | 
| 5 | 
            +
                    gtag('config', '<%= ga_tracker.analytics_id %>', {
         | 
| 6 6 | 
             
                      'user_id': '<%= user_id %>'
         | 
| 7 7 | 
             
                    });
         | 
| 8 8 | 
             
                  <% else %>
         | 
| 9 | 
            -
                    gtag('config', '<%=  | 
| 9 | 
            +
                    gtag('config', '<%= ga_tracker.analytics_id %>');
         | 
| 10 10 | 
             
                  <% end %>
         | 
| 11 11 | 
             
                }
         | 
| 12 12 | 
             
              </script>
         | 
| @@ -1,20 +1,22 @@ | |
| 1 | 
            -
            <% if @order.present? && order_just_completed?(@order)  | 
| 1 | 
            +
            <% if ga_enabled? && @order.present? && order_just_completed?(@order) %>
         | 
| 2 2 | 
             
              <script>
         | 
| 3 | 
            -
                 | 
| 4 | 
            -
                   | 
| 5 | 
            -
             | 
| 6 | 
            -
                     | 
| 7 | 
            -
             | 
| 8 | 
            -
             | 
| 9 | 
            -
             | 
| 10 | 
            -
             | 
| 11 | 
            -
             | 
| 12 | 
            -
             | 
| 13 | 
            -
                       | 
| 14 | 
            -
                         | 
| 15 | 
            -
             | 
| 16 | 
            -
             | 
| 17 | 
            -
             | 
| 18 | 
            -
             | 
| 3 | 
            +
                window.addEventListener('turbolinks:load', function() {
         | 
| 4 | 
            +
                  if (typeof gtag !== 'undefined') {
         | 
| 5 | 
            +
                    clearGAplugins();
         | 
| 6 | 
            +
                    gtag('event', 'purchase', {
         | 
| 7 | 
            +
                      transaction_id: '<%= @order.number %>',
         | 
| 8 | 
            +
                      value: <%= @order.total&.to_f %>,
         | 
| 9 | 
            +
                      currency: '<%= @order.currency %>',
         | 
| 10 | 
            +
                      tax: <%= @order.tax_total&.to_f %>,
         | 
| 11 | 
            +
                      shipping: <%= @order.shipment_total&.to_f %>,
         | 
| 12 | 
            +
                      coupon: '<%= @order.promo_code %>',
         | 
| 13 | 
            +
                      items: [
         | 
| 14 | 
            +
                        <% @order.line_items.each do |line_item| %>
         | 
| 15 | 
            +
                          <%= ga_line_item(line_item) %>,
         | 
| 16 | 
            +
                        <% end %>
         | 
| 17 | 
            +
                      ]
         | 
| 18 | 
            +
                    });
         | 
| 19 | 
            +
                  }
         | 
| 20 | 
            +
                });
         | 
| 19 21 | 
             
              </script>
         | 
| 20 22 | 
             
            <% end %>
         | 
| @@ -1,22 +1,27 @@ | |
| 1 | 
            -
            <% if @order.present? && !@order.complete?  | 
| 1 | 
            +
            <% if segment_enabled? && @order.present? && !@order.complete? %>
         | 
| 2 2 | 
             
              <script>
         | 
| 3 | 
            -
                 | 
| 4 | 
            -
                   | 
| 5 | 
            -
                     | 
| 6 | 
            -
             | 
| 7 | 
            -
             | 
| 8 | 
            -
             | 
| 9 | 
            -
             | 
| 10 | 
            -
             | 
| 11 | 
            -
             | 
| 12 | 
            -
             | 
| 13 | 
            -
             | 
| 14 | 
            -
             | 
| 15 | 
            -
             | 
| 16 | 
            -
             | 
| 3 | 
            +
                window.addEventListener('turbolinks:load', function() {
         | 
| 4 | 
            +
                  if (typeof analytics !== 'undefined') {
         | 
| 5 | 
            +
                    var segmentCartJson = {
         | 
| 6 | 
            +
                      cart_id: '<%= @order.number %>',
         | 
| 7 | 
            +
                      products: [
         | 
| 8 | 
            +
                        <% @order.line_items.each_with_index do |line_item, index| %>
         | 
| 9 | 
            +
                          <%=
         | 
| 10 | 
            +
                            product_for_segment(
         | 
| 11 | 
            +
                              line_item.product,
         | 
| 12 | 
            +
                              position: index+1,
         | 
| 13 | 
            +
                              quantity: line_item.quantity,
         | 
| 14 | 
            +
                              image: default_image_for_product_or_variant(line_item.variant)
         | 
| 15 | 
            +
                            )
         | 
| 16 | 
            +
                          %>,
         | 
| 17 | 
            +
                        <% end %>
         | 
| 18 | 
            +
                      ]
         | 
| 19 | 
            +
                    }
         | 
| 17 20 |  | 
| 18 | 
            -
             | 
| 19 | 
            -
             | 
| 20 | 
            -
             | 
| 21 | 
            +
                    analytics.track('Cart Viewed', segmentCartJson);
         | 
| 22 | 
            +
                    analytics.page('Cart Viewed', segmentCartJson);
         | 
| 23 | 
            +
                  }
         | 
| 24 | 
            +
                });
         | 
| 21 25 | 
             
              </script>
         | 
| 22 26 | 
             
            <% end %>
         | 
| 27 | 
            +
             | 
| @@ -1,14 +1,21 @@ | |
| 1 | 
            -
            <% if @order.present? && !@order.completed?  | 
| 1 | 
            +
            <% if segment_enabled? && @order.present? && !@order.completed? %>
         | 
| 2 2 | 
             
              <script>
         | 
| 3 | 
            -
                 | 
| 4 | 
            -
                   | 
| 5 | 
            -
                     | 
| 6 | 
            -
             | 
| 7 | 
            -
             | 
| 8 | 
            -
             | 
| 9 | 
            -
             | 
| 10 | 
            -
                     | 
| 11 | 
            -
             | 
| 12 | 
            -
             | 
| 3 | 
            +
                window.addEventListener('turbolinks:load', function() {
         | 
| 4 | 
            +
                  if (typeof analytics !== 'undefined') {
         | 
| 5 | 
            +
                    analytics.track('Checkout Step Viewed',
         | 
| 6 | 
            +
                      {
         | 
| 7 | 
            +
                        checkout_id: '<%= @order.number %>',
         | 
| 8 | 
            +
                        step: '<%= (@order.checkout_steps.index(@order.state) + 1) %>'
         | 
| 9 | 
            +
                      }
         | 
| 10 | 
            +
                    );
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                    analytics.page('Checkout Step Viewed',
         | 
| 13 | 
            +
                      {
         | 
| 14 | 
            +
                        checkout_id: '<%= @order.number %>',
         | 
| 15 | 
            +
                        step: '<%= (@order.checkout_steps.index(@order.state) + 1) %>'
         | 
| 16 | 
            +
                      }
         | 
| 17 | 
            +
                    );
         | 
| 18 | 
            +
                  }
         | 
| 19 | 
            +
                });
         | 
| 13 20 | 
             
              </script>
         | 
| 14 21 | 
             
            <% end %>  
         | 
| @@ -1,7 +1,7 @@ | |
| 1 | 
            -
            <% if  | 
| 1 | 
            +
            <% if segment_enabled? %>
         | 
| 2 2 | 
             
              <script>
         | 
| 3 3 | 
             
                !function(){var analytics=window.analytics=window.analytics||[];if(!analytics.initialize)if(analytics.invoked)window.console&&console.error&&console.error("Segment snippet included twice.");else{analytics.invoked=!0;analytics.methods=["trackSubmit","trackClick","trackLink","trackForm","pageview","identify","reset","group","track","ready","alias","debug","page","once","off","on"];analytics.factory=function(t){return function(){var e=Array.prototype.slice.call(arguments);e.unshift(t);analytics.push(e);return analytics}};for(var t=0;t<analytics.methods.length;t++){var e=analytics.methods[t];analytics[e]=analytics.factory(e)}analytics.load=function(t,e){var n=document.createElement("script");n.type="text/javascript";n.async=!0;n.src="https://cdn.segment.com/analytics.js/v1/"+t+"/analytics.min.js";var a=document.getElementsByTagName("script")[0];a.parentNode.insertBefore(n,a);analytics._loadOptions=e};analytics.SNIPPET_VERSION="4.1.0";
         | 
| 4 | 
            -
                  analytics.load('<%= | 
| 4 | 
            +
                  analytics.load('<%=segment_tracker.analytics_id%>'.replace(/^\s+|\s+$/g, ''));
         | 
| 5 5 | 
             
                }}();
         | 
| 6 6 | 
             
              </script>
         | 
| 7 7 | 
             
            <% end %>
         | 
| @@ -1,8 +1,11 @@ | |
| 1 | 
            -
            <% if @order.present? && order_just_completed?(@order)  | 
| 1 | 
            +
            <% if segment_enabled? && @order.present? && order_just_completed?(@order) %>
         | 
| 2 2 | 
             
              <% order_json = SpreeAnalyticsTrackers::Segment::OrderPresenter.new(@order).to_json %>
         | 
| 3 3 | 
             
              <script>
         | 
| 4 | 
            -
                 | 
| 5 | 
            -
                   | 
| 6 | 
            -
             | 
| 4 | 
            +
                window.addEventListener('turbolinks:load', function() {
         | 
| 5 | 
            +
                  if (typeof analytics !== 'undefined') {
         | 
| 6 | 
            +
                    analytics.page('Order Completed', <%= order_json.html_safe %>);
         | 
| 7 | 
            +
                    analytics.track('Order Completed', <%= order_json.html_safe %>);
         | 
| 8 | 
            +
                  }
         | 
| 9 | 
            +
                });
         | 
| 7 10 | 
             
              </script>
         | 
| 8 11 | 
             
            <% end %>
         | 
| @@ -1,21 +1,23 @@ | |
| 1 | 
            -
            <% if  | 
| 1 | 
            +
            <% if segment_enabled? && any_filtering_params? %>
         | 
| 2 2 | 
             
              <script>
         | 
| 3 | 
            -
                 | 
| 4 | 
            -
                   | 
| 5 | 
            -
                     | 
| 6 | 
            -
                       | 
| 7 | 
            -
                         | 
| 8 | 
            -
             | 
| 9 | 
            -
             | 
| 10 | 
            -
             | 
| 11 | 
            -
             | 
| 12 | 
            -
             | 
| 13 | 
            -
             | 
| 14 | 
            -
             | 
| 15 | 
            -
             | 
| 3 | 
            +
                window.addEventListener('turbolinks:load', function() {
         | 
| 4 | 
            +
                  if (typeof analytics !== 'undefined') {
         | 
| 5 | 
            +
                    var segmentProductListFilteredJson = {
         | 
| 6 | 
            +
                      filters: [
         | 
| 7 | 
            +
                        <% filtering_params_with_values.each do |type, value| %>
         | 
| 8 | 
            +
                          <%= { type: type, value: value } .to_json.html_safe %>,
         | 
| 9 | 
            +
                        <% end %>
         | 
| 10 | 
            +
                      ],
         | 
| 11 | 
            +
                      products: [
         | 
| 12 | 
            +
                        <% @products.each_with_index do |product, index| %>
         | 
| 13 | 
            +
                          <%= product_for_segment(product, position: index + 1) %>,
         | 
| 14 | 
            +
                        <% end %>
         | 
| 15 | 
            +
                      ]
         | 
| 16 | 
            +
                    }
         | 
| 16 17 |  | 
| 17 | 
            -
             | 
| 18 | 
            -
             | 
| 19 | 
            -
             | 
| 18 | 
            +
                    analytics.track('Product List Filtered', segmentProductListFilteredJson);
         | 
| 19 | 
            +
                    analytics.page('Product List Filtered', segmentProductListFilteredJson);
         | 
| 20 | 
            +
                  }
         | 
| 21 | 
            +
                });
         | 
| 20 22 | 
             
              </script>
         | 
| 21 23 | 
             
            <% end %>
         | 
| @@ -1,17 +1,19 @@ | |
| 1 | 
            -
            <% if defined?(products) && products.present?  | 
| 1 | 
            +
            <% if segment_enabled? && defined?(products) && products.present? %>
         | 
| 2 2 | 
             
              <script>
         | 
| 3 | 
            -
                 | 
| 4 | 
            -
                   | 
| 5 | 
            -
                     | 
| 6 | 
            -
             | 
| 7 | 
            -
             | 
| 8 | 
            -
             | 
| 9 | 
            -
             | 
| 10 | 
            -
             | 
| 11 | 
            -
             | 
| 3 | 
            +
                window.addEventListener('turbolinks:load', function() {
         | 
| 4 | 
            +
                  if (typeof analytics !== 'undefined') {
         | 
| 5 | 
            +
                    var segmentProductListViewedJson = {
         | 
| 6 | 
            +
                      category: '<%= @taxon&.name %>',
         | 
| 7 | 
            +
                      products: [
         | 
| 8 | 
            +
                        <% products.each_with_index do |product, index| %>
         | 
| 9 | 
            +
                          <%= product_for_segment(product, position: index+1, image: default_image_for_product_or_variant(product)) %>,
         | 
| 10 | 
            +
                        <% end %>
         | 
| 11 | 
            +
                      ]
         | 
| 12 | 
            +
                    }
         | 
| 12 13 |  | 
| 13 | 
            -
             | 
| 14 | 
            -
             | 
| 15 | 
            -
             | 
| 14 | 
            +
                    analytics.track('Product List Viewed', segmentProductListViewedJson);
         | 
| 15 | 
            +
                    analytics.page('Product List Viewed', segmentProductListViewedJson);
         | 
| 16 | 
            +
                  }
         | 
| 17 | 
            +
                });
         | 
| 16 18 | 
             
              </script>
         | 
| 17 19 | 
             
            <% end %>
         | 
| @@ -1,10 +1,12 @@ | |
| 1 | 
            -
            <% if @product.present?  | 
| 1 | 
            +
            <% if segment_enabled? && @product.present? %>
         | 
| 2 2 | 
             
              <script>
         | 
| 3 | 
            -
                 | 
| 4 | 
            -
                   | 
| 3 | 
            +
                window.addEventListener('turbolinks:load', function() {
         | 
| 4 | 
            +
                  if (typeof analytics !== 'undefined') {
         | 
| 5 | 
            +
                    var segmentProductViewed = <%= product_for_segment(@product, image: default_image_for_product_or_variant(@product)) %>;
         | 
| 5 6 |  | 
| 6 | 
            -
             | 
| 7 | 
            -
             | 
| 8 | 
            -
             | 
| 7 | 
            +
                    analytics.page('Product Viewed', segmentProductViewed);
         | 
| 8 | 
            +
                    analytics.track('Product Viewed', segmentProductViewed);
         | 
| 9 | 
            +
                  }
         | 
| 10 | 
            +
                });
         | 
| 9 11 | 
             
              </script>
         | 
| 10 12 | 
             
            <% end %>
         | 
| @@ -1,12 +1,10 @@ | |
| 1 | 
            -
            <% if params.key?(:keywords) && params[:keywords].present?  | 
| 1 | 
            +
            <% if segment_enabled? && params.key?(:keywords) && params[:keywords].present? %>
         | 
| 2 2 | 
             
              <script>
         | 
| 3 | 
            -
                 | 
| 4 | 
            -
                   | 
| 5 | 
            -
                    query: '<%= params[:keywords] %>' | 
| 6 | 
            -
             | 
| 7 | 
            -
                   | 
| 8 | 
            -
             | 
| 9 | 
            -
                  });
         | 
| 10 | 
            -
                }
         | 
| 3 | 
            +
                window.addEventListener('turbolinks:load', function() {
         | 
| 4 | 
            +
                  if (typeof analytics !== 'undefined') {
         | 
| 5 | 
            +
                    analytics.track('Products Searched', { query: '<%= params[:keywords] %>' });
         | 
| 6 | 
            +
                    analytics.page('Products Searched', { query: '<%= params[:keywords] %>' });
         | 
| 7 | 
            +
                  }
         | 
| 8 | 
            +
                });
         | 
| 11 9 | 
             
              </script>
         | 
| 12 10 | 
             
            <% end %>
         | 
| @@ -8,6 +8,7 @@ module SpreeAnalyticsTrackers | |
| 8 8 | 
             
                    return unless File.file?(javascripts_path)
         | 
| 9 9 |  | 
| 10 10 | 
             
                    append_file 'vendor/assets/javascripts/spree/frontend/all.js', "//= require spree/frontend/add_to_cart_analytics\n"
         | 
| 11 | 
            +
                    append_file 'vendor/assets/javascripts/spree/frontend/all.js', "//= require spree/frontend/remove_from_cart_analytics\n"
         | 
| 11 12 | 
             
                  end
         | 
| 12 13 |  | 
| 13 14 | 
             
                  def add_migrations
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: spree_analytics_trackers
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 2. | 
| 4 | 
            +
              version: 2.1.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Spark Solutions
         | 
| 8 | 
            -
            autorequire: | 
| 8 | 
            +
            autorequire:
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date:  | 
| 11 | 
            +
            date: 2021-01-18 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: spree_core
         | 
| @@ -109,6 +109,7 @@ files: | |
| 109 109 | 
             
            - README.md
         | 
| 110 110 | 
             
            - Rakefile
         | 
| 111 111 | 
             
            - app/assets/javascripts/spree/frontend/add_to_cart_analytics.js
         | 
| 112 | 
            +
            - app/assets/javascripts/spree/frontend/remove_from_cart_analytics.js
         | 
| 112 113 | 
             
            - app/controllers/spree/admin/trackers_controller.rb
         | 
| 113 114 | 
             
            - app/controllers/spree_analytics_trackers/store_controller_decorator.rb
         | 
| 114 115 | 
             
            - app/helpers/spree/trackers_helper.rb
         | 
| @@ -174,7 +175,7 @@ homepage: https://github.com/spree-contrib/spree_analytics_trackers | |
| 174 175 | 
             
            licenses:
         | 
| 175 176 | 
             
            - BSD-3-Clause
         | 
| 176 177 | 
             
            metadata: {}
         | 
| 177 | 
            -
            post_install_message: | 
| 178 | 
            +
            post_install_message:
         | 
| 178 179 | 
             
            rdoc_options: []
         | 
| 179 180 | 
             
            require_paths:
         | 
| 180 181 | 
             
            - lib
         | 
| @@ -190,8 +191,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 190 191 | 
             
                  version: '0'
         | 
| 191 192 | 
             
            requirements:
         | 
| 192 193 | 
             
            - none
         | 
| 193 | 
            -
            rubygems_version: 3.1. | 
| 194 | 
            -
            signing_key: | 
| 194 | 
            +
            rubygems_version: 3.1.4
         | 
| 195 | 
            +
            signing_key:
         | 
| 195 196 | 
             
            specification_version: 4
         | 
| 196 197 | 
             
            summary: Adds analytics trackers functionality to Spree
         | 
| 197 198 | 
             
            test_files:
         |