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.
- checksums.yaml +4 -4
- data/.bundle/config +2 -0
- data/.rubocop.yml +2 -0
- data/.travis.yml +30 -15
- data/Appraisals +3 -9
- data/LICENSE +1 -1
- data/README.md +7 -3
- 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 +8 -0
- data/app/controllers/spree_analytics_trackers/checkout_controller_decorator.rb +11 -0
- data/app/controllers/spree_analytics_trackers/store_controller_decorator.rb +13 -0
- data/app/controllers/spree_analytics_trackers/user_confirmations_controller_decorator.rb +11 -0
- data/app/controllers/spree_analytics_trackers/user_passwords_controller_decorator.rb +11 -0
- data/app/controllers/spree_analytics_trackers/user_registrations_controller_decorator.rb +11 -0
- data/app/controllers/spree_analytics_trackers/user_sessions_controller_decorator.rb +11 -0
- data/app/helpers/spree/trackers_helper.rb +79 -16
- data/app/models/spree/tracker.rb +11 -5
- data/app/models/spree_analytics_trackers/user_decorator.rb +9 -0
- data/app/overrides/add_analytics_to_admin_sidebar.rb +2 -3
- data/app/overrides/add_cart_viewed_to_orders_edit.rb +1 -1
- data/app/overrides/add_checkout_step_viewed_to_checkout_edit.rb +11 -3
- data/app/overrides/add_google_analytics_page_view_to_spree_application.rb +10 -0
- data/app/overrides/add_google_analytics_to_spree_application.rb +4 -4
- data/app/overrides/add_google_purchase_to_orders_show.rb +1 -1
- data/app/overrides/add_product_list_filtered_to_taxons_show.rb +1 -1
- data/app/overrides/add_product_list_viewed_to_products_list.rb +1 -1
- data/app/overrides/add_product_viewed_to_products_show.rb +2 -2
- data/app/overrides/add_products_searched_to_products_list.rb +2 -2
- data/app/overrides/add_segment_initializer_to_layout.rb +3 -3
- 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 -5
- data/app/views/spree/admin/trackers/_form.html.erb +13 -7
- data/app/views/spree/admin/trackers/index.html.erb +6 -8
- 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 +24 -19
- data/app/views/spree/shared/trackers/segment/_checkout_step_viewed.js.erb +20 -11
- data/app/views/spree/shared/trackers/segment/_initializer.js.erb +2 -3
- data/app/views/spree/shared/trackers/segment/_order_complete.js.erb +8 -45
- 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 +19 -28
- data/app/views/spree/shared/trackers/segment/_product_list_viewed.js.erb +17 -20
- data/app/views/spree/shared/trackers/segment/_product_viewed.js.erb +12 -6
- data/app/views/spree/shared/trackers/segment/_products_searched.js.erb +7 -9
- data/config/locales/en.yml +0 -2
- data/config/locales/zh-TW.yml +19 -0
- data/db/migrate/20200721163729_add_store_id_to_spree_trackers.rb +14 -0
- data/gemfiles/{spree_3_5.gemfile → spree_4_1.gemfile} +2 -2
- data/gemfiles/spree_master.gemfile +0 -1
- data/lib/generators/spree_analytics_trackers/install/install_generator.rb +8 -0
- data/lib/spree_analytics_trackers.rb +1 -0
- data/lib/spree_analytics_trackers/factories.rb +1 -0
- data/lib/spree_analytics_trackers/version.rb +3 -9
- data/spec/features/admin/configuration/analytics_tracker_spec.rb +18 -7
- data/spec/features/checkout_spec.rb +15 -0
- data/spec/features/products_spec.rb +315 -0
- data/spec/features/user_login_spec.rb +7 -0
- data/spec/features/user_password_recovery_spec.rb +7 -0
- data/spec/features/user_registration_spec.rb +7 -0
- data/spec/fixtures/thinking-cat.jpg +0 -0
- data/spec/models/spree/tracker_spec.rb +15 -0
- data/spec/presenters/spree_analytics_trackers/segment/order_presenter_spec.rb +34 -0
- data/spec/spec_helper.rb +7 -82
- data/spec/support/custom_products.rb +26 -0
- data/spree_analytics_trackers.gemspec +4 -17
- metadata +56 -212
- data/app/controllers/spree/store_controller_decorator.rb +0 -5
- data/app/models/spree/line_item_decorator.rb +0 -6
- data/app/models/spree/order_decorator.rb +0 -7
- data/app/models/spree/product_decorator.rb +0 -11
- data/app/models/spree/user_decorator.rb +0 -5
- data/app/overrides/add_google_checkout_to_checkout_edit.rb +0 -9
- data/app/overrides/add_product_added_to_orders_edit.rb +0 -10
- data/app/views/spree/shared/_google_add_items.html.erb +0 -13
- data/app/views/spree/shared/_google_analytics.html.erb +0 -18
- data/app/views/spree/shared/_google_checkout.html.erb +0 -14
- data/app/views/spree/shared/_google_purchase.html.erb +0 -19
- data/app/views/spree/shared/trackers/segment/_product_added.js.erb +0 -9
- data/gemfiles/spree_3_7.gemfile +0 -9
@@ -1,9 +1,8 @@
|
|
1
1
|
if Gem.loaded_specs['spree_core'].version >= Gem::Version.create('3.5.0')
|
2
2
|
Deface::Override.new(
|
3
3
|
virtual_path: 'spree/admin/shared/sub_menu/_configuration',
|
4
|
-
name: '
|
4
|
+
name: 'add_analytics_to_admin_sidebar',
|
5
5
|
insert_bottom: '[data-hook="admin_configurations_sidebar_menu"]',
|
6
|
-
|
7
|
-
text: '<%= configurations_sidebar_menu_item(Spree.t(:analytics_trackers), spree.admin_trackers_path) if can? :manage, Spree::Tracker %>'
|
6
|
+
partial: 'spree/admin/shared/analytics_sidebar_menu'
|
8
7
|
)
|
9
8
|
end
|
@@ -3,7 +3,7 @@ unless spree_version >= Gem::Version.create('3.4.0') && spree_version < Gem::Ver
|
|
3
3
|
Deface::Override.new(
|
4
4
|
virtual_path: 'spree/orders/edit',
|
5
5
|
name: 'add_cart_viewed_to_orders_edit',
|
6
|
-
insert_top:
|
6
|
+
insert_top: '[data-hook="cart_container"]',
|
7
7
|
partial: 'spree/shared/trackers/segment/cart_viewed.js',
|
8
8
|
original: 'e0a3dcdf759c4ec9fad085cd8a5360c8d68167f5'
|
9
9
|
)
|
@@ -2,9 +2,17 @@ spree_version = Gem.loaded_specs['spree_core'].version
|
|
2
2
|
unless spree_version >= Gem::Version.create('3.4.0') && spree_version < Gem::Version.create('3.5.0')
|
3
3
|
Deface::Override.new(
|
4
4
|
virtual_path: 'spree/checkout/edit',
|
5
|
-
name: '
|
6
|
-
|
5
|
+
name: 'add_segment_checkout_step_viewed_to_checkout_edit',
|
6
|
+
insert_after: '[data-hook="checkout_content"]',
|
7
7
|
partial: 'spree/shared/trackers/segment/checkout_step_viewed.js',
|
8
|
-
original: '
|
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'
|
9
17
|
)
|
10
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
|
@@ -1,9 +1,9 @@
|
|
1
1
|
if Gem.loaded_specs['spree_core'].version >= Gem::Version.create('3.5.0.alpha')
|
2
2
|
Deface::Override.new(
|
3
|
-
virtual_path: 'spree/
|
4
|
-
name: '
|
5
|
-
|
6
|
-
partial: 'spree/shared/google_analytics',
|
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
7
|
original: 'cfa30a2831d9a41394c03229cd28b3c7eee69585'
|
8
8
|
)
|
9
9
|
end
|
@@ -3,7 +3,7 @@ if Gem.loaded_specs['spree_core'].version >= Gem::Version.create('3.5.0')
|
|
3
3
|
virtual_path: 'spree/orders/show',
|
4
4
|
name: 'add_google_purchase_to_orders_show',
|
5
5
|
insert_before: "#order_summary",
|
6
|
-
partial: 'spree/shared/
|
6
|
+
partial: 'spree/shared/trackers/google_analytics/purchase.js',
|
7
7
|
original: 'ac7f302922a3c1bb080095296ccc20e42bab2967'
|
8
8
|
)
|
9
9
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
spree_version = Gem.loaded_specs['spree_core'].version
|
2
2
|
unless spree_version >= Gem::Version.create('3.4.0') && spree_version < Gem::Version.create('3.5.0')
|
3
3
|
Deface::Override.new(
|
4
|
-
virtual_path: 'spree/taxons/
|
4
|
+
virtual_path: 'spree/taxons/_header',
|
5
5
|
name: 'add_product_list_filtered_to_taxons_show',
|
6
6
|
insert_before: ".taxon-title",
|
7
7
|
original: '2d71d85f4cb141a6ff90264e48915493d6856e9b',
|
@@ -3,7 +3,7 @@ unless spree_version >= Gem::Version.create('3.4.0') && spree_version < Gem::Ver
|
|
3
3
|
Deface::Override.new(
|
4
4
|
virtual_path: 'spree/shared/_products',
|
5
5
|
name: 'add_product_list_viewed_to_products_list',
|
6
|
-
insert_before:
|
6
|
+
insert_before: '[data-hook="homepage_products"]',
|
7
7
|
partial: 'spree/shared/trackers/segment/product_list_viewed.js',
|
8
8
|
original: '8b47dddca9dfaaacca3d462459c6c1ef06c09926'
|
9
9
|
)
|
@@ -3,8 +3,8 @@ unless spree_version >= Gem::Version.create('3.4.0') && spree_version < Gem::Ver
|
|
3
3
|
Deface::Override.new(
|
4
4
|
virtual_path: 'spree/products/show',
|
5
5
|
name: 'add_product_viewed_to_products_show',
|
6
|
-
|
6
|
+
insert_bottom: '[data-hook="product_show"]',
|
7
7
|
partial: 'spree/shared/trackers/segment/product_viewed.js',
|
8
|
-
original: '5426c263ccfe477b270b55024abebc77cf951c91'
|
8
|
+
original: '5426c263ccfe477b270b55024abebc77cf951c91'
|
9
9
|
)
|
10
10
|
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
spree_version = Gem.loaded_specs['spree_core'].version
|
2
2
|
unless spree_version >= Gem::Version.create('3.4.0') && spree_version < Gem::Version.create('3.5.0')
|
3
3
|
Deface::Override.new(
|
4
|
-
virtual_path: 'spree/
|
4
|
+
virtual_path: 'spree/products/index',
|
5
5
|
name: 'add_products_searched_to_products_list',
|
6
|
-
insert_before:
|
6
|
+
insert_before: '[data-hook="search_results"]',
|
7
7
|
partial: 'spree/shared/trackers/segment/products_searched.js',
|
8
8
|
original: '8b47dddca9dfaaacca3d462459c6c1ef06c09926'
|
9
9
|
)
|
@@ -1,10 +1,10 @@
|
|
1
1
|
spree_version = Gem.loaded_specs['spree_core'].version
|
2
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
3
|
Deface::Override.new(
|
4
|
-
virtual_path: 'spree/
|
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
|
-
original: '
|
8
|
+
original: '6841b819babbe4df1f03d0bc8e05dc81bf0d45ad'
|
9
9
|
)
|
10
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
|
@@ -1,5 +1,3 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
</ul>
|
5
|
-
<% end %>
|
1
|
+
<%= configurations_sidebar_menu_item(
|
2
|
+
Spree.t(:analytics), spree.admin_trackers_path
|
3
|
+
) if can? :manage, Spree::Config %>
|
@@ -1,12 +1,12 @@
|
|
1
1
|
<div data-hook="admin_tracker_form_fields" class="row">
|
2
|
-
<div class="col-
|
2
|
+
<div class="col-12 col-lg-6" data-hook="analytics_engine">
|
3
3
|
<%= f.field_container :engine, class: ["form-group"], "data-hook" => "analytics_engine" do %>
|
4
4
|
<%= f.label :engine, Spree.t(:analytics_engine) %>
|
5
|
-
<%= f.select :engine,
|
5
|
+
<%= f.select :engine, @engines, {}, { class: 'select2' } %>
|
6
6
|
<%= f.error_message_on :engine %>
|
7
7
|
<% end %>
|
8
8
|
</div>
|
9
|
-
<div class="col-
|
9
|
+
<div class="col-12 col-lg-6">
|
10
10
|
<div data-hook="active" class="form-group">
|
11
11
|
<%= label_tag nil, Spree.t(:active) %>
|
12
12
|
<div class="radio">
|
@@ -23,14 +23,20 @@
|
|
23
23
|
</div>
|
24
24
|
</div>
|
25
25
|
</div>
|
26
|
-
<div class="col-
|
26
|
+
<div class="col-12 col-lg-6" data-hook="analytics_id">
|
27
27
|
<%= f.field_container :analytics_id, class: ["form-group"], "data-hook" => "analytics_id" do %>
|
28
28
|
<%= f.label :analytics_id, Spree.t(:google_analytics_id) %>
|
29
29
|
<%= f.text_field :analytics_id, class: 'form-control' %>
|
30
30
|
<%= f.error_message_on :analytics_id %>
|
31
31
|
<% end %>
|
32
32
|
</div>
|
33
|
-
<div
|
34
|
-
|
35
|
-
|
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>
|
36
40
|
</div>
|
41
|
+
|
42
|
+
<div data-hook="admin_tracker_form_fields" class="row"></div>
|
@@ -8,16 +8,11 @@
|
|
8
8
|
|
9
9
|
<% if @trackers.any? %>
|
10
10
|
<table class="table">
|
11
|
-
<colgroup>
|
12
|
-
<col style="width: 30%">
|
13
|
-
<col style="width: 40%">
|
14
|
-
<col style="width: 15%">
|
15
|
-
<col style="width: 15%">
|
16
|
-
</colgroup>
|
17
11
|
<thead>
|
18
12
|
<tr data-hook="admin_trackers_index_headers">
|
19
13
|
<th><%= Spree.t(:google_analytics_id) %></th>
|
20
14
|
<th><%= Spree.t(:analytics_engine) %></th>
|
15
|
+
<th><%= Spree.t(:store) %></th>
|
21
16
|
<th class="text-center"><%= Spree.t(:active) %></th>
|
22
17
|
<th class="actions"></th>
|
23
18
|
</tr>
|
@@ -27,7 +22,10 @@
|
|
27
22
|
<tr id="<%= spree_dom_id tracker %>" data-hook="admin_trackers_index_rows">
|
28
23
|
<td><%= tracker.analytics_id %></td>
|
29
24
|
<td><%= tracker.engine.humanize %></td>
|
30
|
-
<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>
|
31
29
|
<td class="actions text-right">
|
32
30
|
<%= link_to_edit(tracker, no_text: true) if can? :edit, tracker %>
|
33
31
|
<%= link_to_delete(tracker, no_text: true) if can? :delete, tracker %>
|
@@ -37,7 +35,7 @@
|
|
37
35
|
</tbody>
|
38
36
|
</table>
|
39
37
|
<% else %>
|
40
|
-
<div class="alert alert-
|
38
|
+
<div class="alert alert-info">
|
41
39
|
<%= Spree.t(:no_resource_found, resource: plural_resource_name(Spree::Tracker)) %>,
|
42
40
|
<%= link_to(Spree.t(:add_one), new_object_url) if can? :create, Spree::Tracker %>!
|
43
41
|
</div>
|
@@ -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 %>
|
@@ -0,0 +1,13 @@
|
|
1
|
+
<% if ga_enabled? %>
|
2
|
+
<script>
|
3
|
+
if (typeof gtag !== 'undefined') {
|
4
|
+
<% if user_id = try_spree_current_user.try(:id) %>
|
5
|
+
gtag('config', '<%= ga_tracker.analytics_id %>', {
|
6
|
+
'user_id': '<%= user_id %>'
|
7
|
+
});
|
8
|
+
<% else %>
|
9
|
+
gtag('config', '<%= ga_tracker.analytics_id %>');
|
10
|
+
<% end %>
|
11
|
+
}
|
12
|
+
</script>
|
13
|
+
<% end %>
|
@@ -0,0 +1,22 @@
|
|
1
|
+
<% if ga_enabled? && @order.present? && order_just_completed?(@order) %>
|
2
|
+
<script>
|
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
|
+
});
|
21
|
+
</script>
|
22
|
+
<% end %>
|
@@ -1,22 +1,27 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
1
|
+
<% if segment_enabled? && @order.present? && !@order.complete? %>
|
2
|
+
<script>
|
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
|
+
}
|
11
20
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
<% @order.line_items.each_with_index do |line_item, index| %>
|
16
|
-
<%= product_for_segment(line_item, position: index+1, quantity: line_item.quantity) %>,
|
17
|
-
<% end %>
|
18
|
-
]
|
21
|
+
analytics.track('Cart Viewed', segmentCartJson);
|
22
|
+
analytics.page('Cart Viewed', segmentCartJson);
|
23
|
+
}
|
19
24
|
});
|
25
|
+
</script>
|
26
|
+
<% end %>
|
20
27
|
|
21
|
-
}
|
22
|
-
</script>
|