spree_analytics_trackers 1.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.bundle/config +2 -0
- data/.gitignore +21 -0
- data/.rspec +3 -0
- data/.rubocop.yml +2 -0
- data/.travis.yml +44 -0
- data/Appraisals +11 -0
- data/Gemfile +7 -0
- data/LICENSE +26 -0
- data/README.md +77 -0
- data/Rakefile +21 -0
- data/app/assets/javascripts/spree/frontend/add_to_cart_analytics.js +50 -0
- data/app/assets/javascripts/spree/frontend/remove_from_cart_analytics.js +34 -0
- data/app/controllers/spree/admin/trackers_controller.rb +14 -0
- data/app/controllers/spree_analytics_trackers/store_controller_decorator.rb +14 -0
- data/app/helpers/spree/trackers_helper.rb +86 -0
- data/app/models/spree/tracker.rb +31 -0
- data/app/models/spree_analytics_trackers/user_decorator.rb +9 -0
- data/app/overrides/add_analytics_to_admin_sidebar.rb +8 -0
- data/app/overrides/add_cart_viewed_to_orders_edit.rb +10 -0
- data/app/overrides/add_checkout_step_viewed_to_checkout_edit.rb +18 -0
- data/app/overrides/add_google_analytics_page_view_to_spree_application.rb +10 -0
- data/app/overrides/add_google_analytics_to_spree_application.rb +9 -0
- data/app/overrides/add_google_purchase_to_orders_show.rb +9 -0
- data/app/overrides/add_order_complete_to_orders_show.rb +10 -0
- data/app/overrides/add_product_list_filtered_to_taxons_show.rb +10 -0
- data/app/overrides/add_product_list_viewed_to_products_list.rb +10 -0
- data/app/overrides/add_product_viewed_to_products_show.rb +10 -0
- data/app/overrides/add_products_searched_to_products_list.rb +10 -0
- data/app/overrides/add_segment_initializer_to_layout.rb +10 -0
- data/app/overrides/add_segment_page_viewed_to_layout.rb +10 -0
- data/app/presenters/spree_analytics_trackers/base_presenter.rb +14 -0
- data/app/presenters/spree_analytics_trackers/segment/order_presenter.rb +32 -0
- data/app/presenters/spree_analytics_trackers/segment/product_presenter.rb +40 -0
- data/app/views/spree/admin/shared/_analytics_sidebar_menu.html.erb +3 -0
- data/app/views/spree/admin/trackers/_form.html.erb +42 -0
- data/app/views/spree/admin/trackers/edit.html.erb +13 -0
- data/app/views/spree/admin/trackers/index.html.erb +42 -0
- data/app/views/spree/admin/trackers/new.html.erb +13 -0
- data/app/views/spree/shared/trackers/google_analytics/_checkout_step_viewed.js.erb +19 -0
- data/app/views/spree/shared/trackers/google_analytics/_initializer.js.erb +25 -0
- data/app/views/spree/shared/trackers/google_analytics/_page_viewed.js.erb +13 -0
- data/app/views/spree/shared/trackers/google_analytics/_purchase.js.erb +22 -0
- data/app/views/spree/shared/trackers/segment/_cart_viewed.js.erb +27 -0
- data/app/views/spree/shared/trackers/segment/_checkout_step_viewed.js.erb +21 -0
- data/app/views/spree/shared/trackers/segment/_initializer.js.erb +7 -0
- data/app/views/spree/shared/trackers/segment/_order_complete.js.erb +11 -0
- data/app/views/spree/shared/trackers/segment/_page_viewed.js.erb +7 -0
- data/app/views/spree/shared/trackers/segment/_product_list_filtered.js.erb +23 -0
- data/app/views/spree/shared/trackers/segment/_product_list_viewed.js.erb +19 -0
- data/app/views/spree/shared/trackers/segment/_product_viewed.js.erb +12 -0
- data/app/views/spree/shared/trackers/segment/_products_searched.js.erb +10 -0
- data/bin/rails +7 -0
- data/config/locales/en.yml +18 -0
- data/config/locales/zh-TW.yml +19 -0
- data/config/routes.rb +5 -0
- data/db/migrate/20171013160337_create_spree_trackers.rb +20 -0
- data/db/migrate/20200721163729_add_store_id_to_spree_trackers.rb +14 -0
- data/gemfiles/.bundle/config +2 -0
- data/gemfiles/spree_4_1.gemfile +9 -0
- data/gemfiles/spree_master.gemfile +9 -0
- data/lib/generators/spree_analytics_trackers/install/install_generator.rb +28 -0
- data/lib/spree_analytics_trackers.rb +5 -0
- data/lib/spree_analytics_trackers/engine.rb +20 -0
- data/lib/spree_analytics_trackers/factories.rb +10 -0
- data/lib/spree_analytics_trackers/version.rb +17 -0
- data/spec/features/admin/configuration/analytics_tracker_spec.rb +61 -0
- data/spec/features/products_spec.rb +315 -0
- data/spec/fixtures/thinking-cat.jpg +0 -0
- data/spec/models/spree/tracker_spec.rb +32 -0
- data/spec/presenters/spree_analytics_trackers/segment/order_presenter_spec.rb +34 -0
- data/spec/spec_helper.rb +18 -0
- data/spec/support/custom_products.rb +26 -0
- data/spree_analytics_trackers.gemspec +31 -0
- metadata +98 -200
@@ -0,0 +1,31 @@
|
|
1
|
+
module Spree
|
2
|
+
class Tracker < Spree::Base
|
3
|
+
TRACKING_ENGINES = %i(google_analytics segment).freeze
|
4
|
+
enum engine: TRACKING_ENGINES
|
5
|
+
|
6
|
+
after_commit :clear_cache
|
7
|
+
|
8
|
+
validates :analytics_id, presence: true, uniqueness: { scope: [:engine, :store_id], case_sensitive: false }
|
9
|
+
validates :store, presence: true
|
10
|
+
|
11
|
+
scope :active, -> { where(active: true) }
|
12
|
+
|
13
|
+
belongs_to :store
|
14
|
+
|
15
|
+
def self.current(engine = nil, store = nil)
|
16
|
+
engine ||= TRACKING_ENGINES.first
|
17
|
+
store ||= Spree::Store.default
|
18
|
+
|
19
|
+
tracker = Rails.cache.fetch("current_tracker/#{engine}/#{store.id}") do
|
20
|
+
active.find_by(store: store, engine: engine)
|
21
|
+
end
|
22
|
+
tracker.analytics_id.present? ? tracker : nil if tracker
|
23
|
+
end
|
24
|
+
|
25
|
+
def clear_cache
|
26
|
+
TRACKING_ENGINES.each do |engine|
|
27
|
+
Rails.cache.delete("current_tracker/#{engine}/#{store_id}")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
if Gem.loaded_specs['spree_core'].version >= Gem::Version.create('3.5.0')
|
2
|
+
Deface::Override.new(
|
3
|
+
virtual_path: 'spree/admin/shared/sub_menu/_configuration',
|
4
|
+
name: 'add_analytics_to_admin_sidebar',
|
5
|
+
insert_bottom: '[data-hook="admin_configurations_sidebar_menu"]',
|
6
|
+
partial: 'spree/admin/shared/analytics_sidebar_menu'
|
7
|
+
)
|
8
|
+
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/orders/edit',
|
5
|
+
name: 'add_cart_viewed_to_orders_edit',
|
6
|
+
insert_top: '[data-hook="cart_container"]',
|
7
|
+
partial: 'spree/shared/trackers/segment/cart_viewed.js',
|
8
|
+
original: 'e0a3dcdf759c4ec9fad085cd8a5360c8d68167f5'
|
9
|
+
)
|
10
|
+
end
|
@@ -0,0 +1,18 @@
|
|
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/checkout/edit',
|
5
|
+
name: 'add_segment_checkout_step_viewed_to_checkout_edit',
|
6
|
+
insert_after: '[data-hook="checkout_content"]',
|
7
|
+
partial: 'spree/shared/trackers/segment/checkout_step_viewed.js',
|
8
|
+
original: '806d2120a1ca1050fb093962fee10363c0944b0a'
|
9
|
+
)
|
10
|
+
|
11
|
+
Deface::Override.new(
|
12
|
+
virtual_path: 'spree/checkout/edit',
|
13
|
+
name: 'add_ga_checkout_step_viewed_to_checkout_edit',
|
14
|
+
insert_after: '[data-hook="checkout_content"]',
|
15
|
+
partial: 'spree/shared/trackers/google_analytics/checkout_step_viewed.js',
|
16
|
+
original: '0ac5c18a2db215bf8ba30470a0e5d69e00d0313a'
|
17
|
+
)
|
18
|
+
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') && spree_version != Gem::Version.create('3.5.0.alpha')
|
3
|
+
Deface::Override.new(
|
4
|
+
virtual_path: 'spree/shared/_head',
|
5
|
+
name: 'add_google_analytics_page_viewed_to_spree_application',
|
6
|
+
insert_before: 'meta',
|
7
|
+
partial: 'spree/shared/trackers/google_analytics/page_viewed.js',
|
8
|
+
original: '6841b819babbe4df1f03d0bc8e05dc81bf0d45ad'
|
9
|
+
)
|
10
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
if Gem.loaded_specs['spree_core'].version >= Gem::Version.create('3.5.0.alpha')
|
2
|
+
Deface::Override.new(
|
3
|
+
virtual_path: 'spree/shared/_head',
|
4
|
+
name: 'add_google_analytics_initializer_to_spree_application',
|
5
|
+
insert_after: 'title',
|
6
|
+
partial: 'spree/shared/trackers/google_analytics/initializer.js',
|
7
|
+
original: 'cfa30a2831d9a41394c03229cd28b3c7eee69585'
|
8
|
+
)
|
9
|
+
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,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') && spree_version != Gem::Version.create('3.5.0.alpha')
|
3
|
+
Deface::Override.new(
|
4
|
+
virtual_path: 'spree/shared/_head',
|
5
|
+
name: 'add_segment_initializer_to_layout',
|
6
|
+
insert_after: 'title',
|
7
|
+
partial: 'spree/shared/trackers/segment/initializer.js',
|
8
|
+
original: '6841b819babbe4df1f03d0bc8e05dc81bf0d45ad'
|
9
|
+
)
|
10
|
+
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') && spree_version != Gem::Version.create('3.5.0.alpha')
|
3
|
+
Deface::Override.new(
|
4
|
+
virtual_path: 'spree/shared/_head',
|
5
|
+
name: 'add_segment_page_tracker_to_body',
|
6
|
+
insert_before: 'meta',
|
7
|
+
partial: 'spree/shared/trackers/segment/page_viewed.js',
|
8
|
+
original: '6841b819babbe4df1f03d0bc8e05dc81bf0d45ad'
|
9
|
+
)
|
10
|
+
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,42 @@
|
|
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, @engines, {}, { 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">
|
34
|
+
<div data-hook="store" class="form-group">
|
35
|
+
<%= label_tag :tracker_store, Spree.t(:store) %>
|
36
|
+
<%= collection_select(:tracker, :store_id, @stores, :id, :name, { include_blank: true }, {id: 'store_id', class: 'select2'}) %>
|
37
|
+
</div>
|
38
|
+
</div>
|
39
|
+
<div class="col-12 col-lg-6" data-hook="additional_tracker_fields"></div>
|
40
|
+
</div>
|
41
|
+
|
42
|
+
<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,42 @@
|
|
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><%= Spree.t(:store) %></th>
|
16
|
+
<th class="text-center"><%= Spree.t(:active) %></th>
|
17
|
+
<th class="actions"></th>
|
18
|
+
</tr>
|
19
|
+
</thead>
|
20
|
+
<tbody>
|
21
|
+
<% @trackers.each do |tracker|%>
|
22
|
+
<tr id="<%= spree_dom_id tracker %>" data-hook="admin_trackers_index_rows">
|
23
|
+
<td><%= tracker.analytics_id %></td>
|
24
|
+
<td><%= tracker.engine.humanize %></td>
|
25
|
+
<td><%= tracker.store&.name %></td>
|
26
|
+
<td class="text-center">
|
27
|
+
<%= tracker.active ? Spree.t(:say_yes) : Spree.t(:say_no) %>
|
28
|
+
</td>
|
29
|
+
<td class="actions text-right">
|
30
|
+
<%= link_to_edit(tracker, no_text: true) if can? :edit, tracker %>
|
31
|
+
<%= link_to_delete(tracker, no_text: true) if can? :delete, tracker %>
|
32
|
+
</td>
|
33
|
+
</tr>
|
34
|
+
<% end %>
|
35
|
+
</tbody>
|
36
|
+
</table>
|
37
|
+
<% else %>
|
38
|
+
<div class="alert alert-info">
|
39
|
+
<%= Spree.t(:no_resource_found, resource: plural_resource_name(Spree::Tracker)) %>,
|
40
|
+
<%= link_to(Spree.t(:add_one), new_object_url) if can? :create, Spree::Tracker %>!
|
41
|
+
</div>
|
42
|
+
<% 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,19 @@
|
|
1
|
+
<% if ga_enabled? && @order.present? && !@order.completed? %>
|
2
|
+
<script>
|
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
|
+
});
|
18
|
+
</script>
|
19
|
+
<% end %>
|
@@ -0,0 +1,25 @@
|
|
1
|
+
<% if ga_enabled? %>
|
2
|
+
<!-- Global site tag (gtag.js) - Google Analytics -->
|
3
|
+
<script async src="https://www.googletagmanager.com/gtag/js?id=<%= ga_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', '<%= ga_tracker.analytics_id %>', { 'send_page_view': false });
|
10
|
+
gtag('set', 'allow_google_signals', true )
|
11
|
+
gtag('set', 'allow_ad_personalization_signals', true );
|
12
|
+
|
13
|
+
function clearGAplugins() {
|
14
|
+
if (typeof ga !== "undefined" && typeof ga.getAll === "function") {
|
15
|
+
var trackingDom = ga.getAll()[0].get('trackingId');
|
16
|
+
if (trackingDom !== undefined) {
|
17
|
+
var trackingId = trackingDom.split('-').join('_')
|
18
|
+
if (trackingId !== undefined && ga.o !== undefined && ga.o["gtag_" + trackingId] !== undefined) {
|
19
|
+
delete ga.o["gtag_" + trackingId].plugins_
|
20
|
+
}
|
21
|
+
}
|
22
|
+
}
|
23
|
+
}
|
24
|
+
</script>
|
25
|
+
<% end %>
|