ba_spree_google_analytics 1.1.2
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 +7 -0
- data/LICENSE +10 -0
- data/README.md +105 -0
- data/Rakefile +25 -0
- data/app/.gitkeep +0 -0
- data/app/assets/config/spree_google_analytics_manifest.js +5 -0
- data/app/assets/images/integration_icons/google-analytics-logo.png +0 -0
- data/app/controllers/.gitkeep +0 -0
- data/app/controllers/spree_google_analytics/store_controller_decorator.rb +20 -0
- data/app/helpers/spree_google_analytics/base_helper.rb +229 -0
- data/app/javascript/spree_google_analytics/application.js +16 -0
- data/app/javascript/spree_google_analytics/controllers/spree_google_analytics_controller.js +41 -0
- data/app/models/.gitkeep +0 -0
- data/app/models/spree/integrations/google_analytics.rb +21 -0
- data/app/presenters/spree_google_analytics/checkout_presenter.rb +12 -0
- data/app/presenters/spree_google_analytics/order_presenter.rb +59 -0
- data/app/presenters/spree_google_analytics/payment_presenter.rb +7 -0
- data/app/presenters/spree_google_analytics/product_presenter.rb +54 -0
- data/app/serializers/.gitkeep +0 -0
- data/app/services/.gitkeep +0 -0
- data/app/views/spree/admin/integrations/forms/_google_analytics.html.erb +22 -0
- data/app/views/spree_google_analytics/_add_to_cart.html.erb +15 -0
- data/app/views/spree_google_analytics/_add_to_wishlist.erb +15 -0
- data/app/views/spree_google_analytics/_body_end.html.erb +125 -0
- data/app/views/spree_google_analytics/_body_start.html.erb +12 -0
- data/app/views/spree_google_analytics/_cart.html.erb +6 -0
- data/app/views/spree_google_analytics/_checkout_complete.html.erb +31 -0
- data/app/views/spree_google_analytics/_head.html.erb +57 -0
- data/app/views/spree_google_analytics/_product.html.erb +15 -0
- data/app/views/spree_google_analytics/_remove_from_cart.html.erb +15 -0
- data/config/importmap.rb +6 -0
- data/config/initializers/spree.rb +18 -0
- data/config/locales/en.yml +13 -0
- data/config/routes.rb +3 -0
- data/lib/ba_spree_google_analytics.rb +5 -0
- data/lib/generators/spree_google_analytics/install/install_generator.rb +20 -0
- data/lib/spree_google_analytics/configuration.rb +13 -0
- data/lib/spree_google_analytics/engine.rb +39 -0
- data/lib/spree_google_analytics/factories.rb +3 -0
- data/lib/spree_google_analytics/testing_support/factories/google_analytics_integration.rb +7 -0
- data/lib/spree_google_analytics/version.rb +7 -0
- data/lib/spree_google_analytics.rb +5 -0
- data/vendor/javascript/.keep +0 -0
- data/vendor/stylesheets/.keep +0 -0
- metadata +146 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<% if store_integration('google_analytics').present? && @wished_item&.variant.present? %>
|
|
2
|
+
<script>
|
|
3
|
+
<% safely do %>
|
|
4
|
+
<% if use_gtm? %>
|
|
5
|
+
if (window.dataLayer) {
|
|
6
|
+
dataLayer.push(<%= google_analytics_add_to_wishlist_event_json(@wished_item.variant) %>);
|
|
7
|
+
}
|
|
8
|
+
<% else %>
|
|
9
|
+
if (window.gtag) {
|
|
10
|
+
gtag('event', 'add_to_wishlist', <%= google_analytics_add_to_wishlist_event_json(@wished_item.variant) %>);
|
|
11
|
+
}
|
|
12
|
+
<% end %>
|
|
13
|
+
<% end %>
|
|
14
|
+
</script>
|
|
15
|
+
<% end %>
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
<% if store_integration('google_analytics').present? %>
|
|
2
|
+
<% if use_gtm? %>
|
|
3
|
+
<script>
|
|
4
|
+
if (window.dataLayer) {
|
|
5
|
+
<% if controller_name == 'checkout' %>
|
|
6
|
+
<% if @order && session[:checkout_started] %>
|
|
7
|
+
<% safely do %>
|
|
8
|
+
dataLayer.push(<%= google_analytics_checkout_json %>);
|
|
9
|
+
<% end %>
|
|
10
|
+
<% end %>
|
|
11
|
+
|
|
12
|
+
<% if @order && session[:checkout_step_completed] == 'delivery' %>
|
|
13
|
+
<% safely do %>
|
|
14
|
+
<% @order.shipments.each do |shipment| %>
|
|
15
|
+
dataLayer.push({
|
|
16
|
+
event: 'add_shipping_info',
|
|
17
|
+
ecommerce: <%= google_analytics_add_shipping_info_json(shipment) %>
|
|
18
|
+
});
|
|
19
|
+
<% end %>
|
|
20
|
+
<% end %>
|
|
21
|
+
<% end %>
|
|
22
|
+
|
|
23
|
+
<%# [#1063] 支払いステップ完了時に add_payment_info を送る。
|
|
24
|
+
元の gem は注文完了時(_checkout_complete)に purchase と同時に送っており、
|
|
25
|
+
ファネル上 add_payment_info が purchase と重なってしまうため、ここへ移動した。 %>
|
|
26
|
+
<% if @order && session[:checkout_step_completed] == 'payment' %>
|
|
27
|
+
<% safely do %>
|
|
28
|
+
dataLayer.push(<%= google_analytics_payment_json %>);
|
|
29
|
+
<% end %>
|
|
30
|
+
<% end %>
|
|
31
|
+
<% end %>
|
|
32
|
+
|
|
33
|
+
<% if controller_name == 'search' && action_name == 'show' && query.present? %>
|
|
34
|
+
<% safely do %>
|
|
35
|
+
dataLayer.push({
|
|
36
|
+
event: 'search',
|
|
37
|
+
search_term: "<%= ERB::Util.html_escape(query) %>"
|
|
38
|
+
});
|
|
39
|
+
<% end %>
|
|
40
|
+
<% end %>
|
|
41
|
+
|
|
42
|
+
<%# [#1063] view_cart はカートのスライドオーバー(ドロワー)が開いた時に送る。
|
|
43
|
+
ドロワーは全ページ共通のヘッダーから開けるため、特定パーシャル
|
|
44
|
+
(_cart は /cart のみ、_add_to_cart はカート追加時のみ)に依存すると
|
|
45
|
+
「任意ページで右上カートアイコン→ドロワー」の主動線で発火しない。
|
|
46
|
+
全ページで描画されるこの _body_end に slideover:open リスナーを置き、
|
|
47
|
+
全動線を1箇所でカバーする。
|
|
48
|
+
Turbo遷移でカート内容が変わるため、ページ描画ごとに最新の payload を
|
|
49
|
+
持つリスナーへ貼り替える(古いリスナーを removeEventListener してから
|
|
50
|
+
addEventListener)。これで多重登録も古いpayload送信も防ぐ。 %>
|
|
51
|
+
<% if current_order.present? && current_order.line_items.any? %>
|
|
52
|
+
<% safely do %>
|
|
53
|
+
if (window.__spreeGAViewCartListener) {
|
|
54
|
+
window.removeEventListener('slideover:open', window.__spreeGAViewCartListener);
|
|
55
|
+
}
|
|
56
|
+
window.__spreeGAViewCartListener = function() {
|
|
57
|
+
if (window.dataLayer) {
|
|
58
|
+
dataLayer.push(<%= google_analytics_gtm_view_cart_json %>);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
window.addEventListener('slideover:open', window.__spreeGAViewCartListener);
|
|
62
|
+
<% end %>
|
|
63
|
+
<% end %>
|
|
64
|
+
}
|
|
65
|
+
</script>
|
|
66
|
+
<% else %>
|
|
67
|
+
<script>
|
|
68
|
+
if (window.gtag) {
|
|
69
|
+
<% if controller_name == 'checkout' %>
|
|
70
|
+
<% if @order && session[:checkout_started] %>
|
|
71
|
+
<% safely do %>
|
|
72
|
+
gtag('event', 'begin_checkout', <%= google_analytics_checkout_json %>);
|
|
73
|
+
<% end %>
|
|
74
|
+
<% end %>
|
|
75
|
+
|
|
76
|
+
<% if @order && session[:checkout_step_completed] == 'delivery' %>
|
|
77
|
+
<% safely do %>
|
|
78
|
+
<% @order.shipments.each do |shipment| %>
|
|
79
|
+
gtag('event', 'add_shipping_info', <%= google_analytics_add_shipping_info_json(shipment) %>);
|
|
80
|
+
<% end %>
|
|
81
|
+
<% end %>
|
|
82
|
+
<% end %>
|
|
83
|
+
|
|
84
|
+
<%# [#1063] 支払いステップ完了時に add_payment_info を送る。
|
|
85
|
+
元の gem は注文完了時(_checkout_complete)に purchase と同時に送っており、
|
|
86
|
+
ファネル上 add_payment_info が purchase と重なってしまうため、ここへ移動した。 %>
|
|
87
|
+
<% if @order && session[:checkout_step_completed] == 'payment' %>
|
|
88
|
+
<% safely do %>
|
|
89
|
+
gtag('event', 'add_payment_info', <%= google_analytics_payment_json %>);
|
|
90
|
+
<% end %>
|
|
91
|
+
<% end %>
|
|
92
|
+
<% end %>
|
|
93
|
+
|
|
94
|
+
<% if controller_name == 'search' && action_name == 'show' && query.present? %>
|
|
95
|
+
<% safely do %>
|
|
96
|
+
gtag('event', 'search', <%= raw({ search_term: ERB::Util.html_escape(query) }.to_json) %>);
|
|
97
|
+
<% end %>
|
|
98
|
+
<% end %>
|
|
99
|
+
|
|
100
|
+
<%# [#1063] view_cart はカートのスライドオーバー(ドロワー)が開いた時に送る。
|
|
101
|
+
ドロワーは全ページ共通のヘッダーから開けるため、特定パーシャル
|
|
102
|
+
(_cart は /cart のみ、_add_to_cart はカート追加時のみ)に依存すると
|
|
103
|
+
「任意ページで右上カートアイコン→ドロワー」の主動線で発火しない。
|
|
104
|
+
全ページで描画されるこの _body_end に slideover:open リスナーを置き、
|
|
105
|
+
全動線を1箇所でカバーする。
|
|
106
|
+
Turbo遷移でカート内容が変わるため、ページ描画ごとに最新の payload を
|
|
107
|
+
持つリスナーへ貼り替える(古いリスナーを removeEventListener してから
|
|
108
|
+
addEventListener)。これで多重登録も古いpayload送信も防ぐ。 %>
|
|
109
|
+
<% if current_order.present? && current_order.line_items.any? %>
|
|
110
|
+
<% safely do %>
|
|
111
|
+
if (window.__spreeGAViewCartListener) {
|
|
112
|
+
window.removeEventListener('slideover:open', window.__spreeGAViewCartListener);
|
|
113
|
+
}
|
|
114
|
+
window.__spreeGAViewCartListener = function() {
|
|
115
|
+
if (window.gtag) {
|
|
116
|
+
gtag('event', 'view_cart', <%= google_analytics_view_cart_json %>);
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
window.addEventListener('slideover:open', window.__spreeGAViewCartListener);
|
|
120
|
+
<% end %>
|
|
121
|
+
<% end %>
|
|
122
|
+
}
|
|
123
|
+
</script>
|
|
124
|
+
<% end %>
|
|
125
|
+
<% end %>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<% if store_integration('google_analytics').present? && use_gtm? %>
|
|
2
|
+
<!-- Google Tag Manager (noscript) -->
|
|
3
|
+
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=<%= store_integration('google_analytics').preferred_google_tag_manager_id %>"
|
|
4
|
+
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
|
|
5
|
+
<!-- End Google Tag Manager (noscript) -->
|
|
6
|
+
<% end %>
|
|
7
|
+
|
|
8
|
+
<%# [#1063] Turbo遷移でpage_viewを再送するStimulusコントローラのマウント要素。
|
|
9
|
+
body内に置くことで data-controller が有効になる。 %>
|
|
10
|
+
<% if store_integration('google_analytics').present? %>
|
|
11
|
+
<div data-controller="spree_google_analytics" style="display:none"></div>
|
|
12
|
+
<% end %>
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
<%# [#1063] view_cart は _body_end の slideover:open リスナーに集約した。
|
|
2
|
+
(ここ _cart は /cart ページでしか描画されず、右上カートアイコンから
|
|
3
|
+
任意ページでドロワーを開く主動線をカバーできないため。)
|
|
4
|
+
add_to_cart 動線(_add_to_cart)・/cart 動線(ここ)・右上アイコン動線を
|
|
5
|
+
_body_end の1リスナーで一元化し、view_cart の二重発火も解消する。
|
|
6
|
+
パーシャル登録自体は initializer に残っているため、空でも問題ない。 %>
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
<% if store_integration('google_analytics').present? %>
|
|
2
|
+
<script>
|
|
3
|
+
<% safely do %>
|
|
4
|
+
<% if use_gtm? %>
|
|
5
|
+
if (window.dataLayer) {
|
|
6
|
+
<% if @order.user.present? && !try_spree_current_user %>
|
|
7
|
+
dataLayer.push({
|
|
8
|
+
user_id: "<%= @order.user_id %>",
|
|
9
|
+
user_properties: <%= google_analytics_user_properties_json(@order.user) %>
|
|
10
|
+
});
|
|
11
|
+
<% end %>
|
|
12
|
+
|
|
13
|
+
<%# [#1063] add_payment_info は支払いステップ完了時(_body_end)に送るため、
|
|
14
|
+
ここ(注文完了時)では purchase のみ送る。 %>
|
|
15
|
+
dataLayer.push(<%= google_analytics_purchase_json %>);
|
|
16
|
+
}
|
|
17
|
+
<% else %>
|
|
18
|
+
if (window.gtag) {
|
|
19
|
+
<% if @order.user.present? && !try_spree_current_user %>
|
|
20
|
+
gtag('set', 'user_id', "<%= @order.user_id %>");
|
|
21
|
+
gtag('set', 'user_properties', <%= google_analytics_user_properties_json(@order.user) %>);
|
|
22
|
+
<% end %>
|
|
23
|
+
|
|
24
|
+
<%# [#1063] add_payment_info は支払いステップ完了時(_body_end)に送るため、
|
|
25
|
+
ここ(注文完了時)では purchase のみ送る。 %>
|
|
26
|
+
gtag('event', 'purchase', <%= google_analytics_purchase_json %>);
|
|
27
|
+
}
|
|
28
|
+
<% end %>
|
|
29
|
+
<% end %>
|
|
30
|
+
</script>
|
|
31
|
+
<% end %>
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
<% integration = store_integration('google_analytics') %>
|
|
2
|
+
|
|
3
|
+
<% if integration.present? %>
|
|
4
|
+
<% if use_gtm? %>
|
|
5
|
+
<!-- Google Tag Manager -->
|
|
6
|
+
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
|
|
7
|
+
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
|
|
8
|
+
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
|
|
9
|
+
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
|
|
10
|
+
})(window,document,'script','dataLayer','<%= integration.preferred_google_tag_manager_id %>');</script>
|
|
11
|
+
<!-- End Google Tag Manager -->
|
|
12
|
+
|
|
13
|
+
<script>
|
|
14
|
+
window.dataLayer = window.dataLayer || [];
|
|
15
|
+
|
|
16
|
+
<% if try_spree_current_user %>
|
|
17
|
+
<% cache try_spree_current_user, expires_in: 1.hour do %>
|
|
18
|
+
dataLayer.push({
|
|
19
|
+
user_id: "<%= try_spree_current_user.id %>",
|
|
20
|
+
user_properties: <%= google_analytics_user_properties_json(try_spree_current_user) %>
|
|
21
|
+
});
|
|
22
|
+
<% end %>
|
|
23
|
+
<% end %>
|
|
24
|
+
</script>
|
|
25
|
+
<% else %>
|
|
26
|
+
<!-- Google tag (gtag.js) -->
|
|
27
|
+
<script async src="https://www.googletagmanager.com/gtag/js?id=<%= store_integration('google_analytics').preferred_measurement_id %>"></script>
|
|
28
|
+
<script>
|
|
29
|
+
window.dataLayer = window.dataLayer || [];
|
|
30
|
+
function gtag(){dataLayer.push(arguments);}
|
|
31
|
+
|
|
32
|
+
gtag('js', new Date());
|
|
33
|
+
GA_MEASUREMENT_ID = "<%= integration.preferred_measurement_id %>";
|
|
34
|
+
|
|
35
|
+
<%# [#1063] send_page_view: false にして自動page_viewを無効化し、
|
|
36
|
+
Turbo遷移にも追従するStimulusコントローラ側(turbo:load)から一元送信する。 %>
|
|
37
|
+
<% if ENV['GA_DEBUG_MODE'].present? %>
|
|
38
|
+
gtag('config', GA_MEASUREMENT_ID, { "debug_mode": true, "send_page_view": false });
|
|
39
|
+
<% else %>
|
|
40
|
+
gtag('config', GA_MEASUREMENT_ID, { "send_page_view": false });
|
|
41
|
+
<% end %>
|
|
42
|
+
|
|
43
|
+
<% if try_spree_current_user %>
|
|
44
|
+
<% cache try_spree_current_user, expires_in: 1.hour do %>
|
|
45
|
+
gtag('set', 'user_id', "<%= try_spree_current_user.id %>");
|
|
46
|
+
gtag('set', 'user_properties', <%= google_analytics_user_properties_json(try_spree_current_user) %>);
|
|
47
|
+
<% end %>
|
|
48
|
+
<% end %>
|
|
49
|
+
</script>
|
|
50
|
+
<% end %>
|
|
51
|
+
|
|
52
|
+
<%# [#1063] Turbo遷移でpage_viewを再送するStimulusコントローラのJSをロード。
|
|
53
|
+
importmap pin はあってもエントリが無いとモジュールが実行されないため、
|
|
54
|
+
ここで明示的に application モジュールを読み込む。
|
|
55
|
+
コントローラのマウント要素(data-controller)は body 側(_body_start)に置く。 %>
|
|
56
|
+
<%= javascript_import_module_tag 'application-spree_google_analytics' %>
|
|
57
|
+
<% end %>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<% if store_integration('google_analytics').present? %>
|
|
2
|
+
<% cache [spree_base_cache_key, @product, @selected_variant].compact do %>
|
|
3
|
+
<script>
|
|
4
|
+
<% if use_gtm? %>
|
|
5
|
+
if (window.dataLayer) {
|
|
6
|
+
dataLayer.push(<%= google_analytics_view_item_json %>);
|
|
7
|
+
}
|
|
8
|
+
<% else %>
|
|
9
|
+
if (window.gtag) {
|
|
10
|
+
gtag('event', 'view_item', <%= google_analytics_view_item_json %>);
|
|
11
|
+
}
|
|
12
|
+
<% end %>
|
|
13
|
+
</script>
|
|
14
|
+
<% end %>
|
|
15
|
+
<% end %>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<% if store_integration('google_analytics').present? %>
|
|
2
|
+
<script>
|
|
3
|
+
<% safely do %>
|
|
4
|
+
<% if use_gtm? %>
|
|
5
|
+
if (window.dataLayer) {
|
|
6
|
+
dataLayer.push(<%= google_analytics_remove_from_cart_event_json(@line_item, @line_item.quantity, nil) %>);
|
|
7
|
+
}
|
|
8
|
+
<% else %>
|
|
9
|
+
if (window.gtag) {
|
|
10
|
+
gtag('event', 'remove_from_cart', <%= google_analytics_remove_from_cart_event_json(@line_item, @line_item.quantity, nil) %>);
|
|
11
|
+
}
|
|
12
|
+
<% end %>
|
|
13
|
+
<% end %>
|
|
14
|
+
</script>
|
|
15
|
+
<% end %>
|
data/config/importmap.rb
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
pin 'application-spree_google_analytics', to: 'spree_google_analytics/application.js', preload: false
|
|
2
|
+
|
|
3
|
+
pin_all_from SpreeGoogleAnalytics::Engine.root.join('app/javascript/spree_google_analytics/controllers'),
|
|
4
|
+
under: 'spree_google_analytics/controllers',
|
|
5
|
+
to: 'spree_google_analytics/controllers',
|
|
6
|
+
preload: 'application-spree_google_analytics'
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
Rails.application.config.after_initialize do
|
|
2
|
+
Rails.application.config.spree.integrations << Spree::Integrations::GoogleAnalytics
|
|
3
|
+
|
|
4
|
+
if Rails.application.config.respond_to?(:spree_storefront)
|
|
5
|
+
Rails.application.config.spree_storefront.head_partials << 'spree_google_analytics/head'
|
|
6
|
+
Rails.application.config.spree_storefront.body_start_partials << 'spree_google_analytics/body_start'
|
|
7
|
+
Rails.application.config.spree_storefront.body_end_partials << 'spree_google_analytics/body_end'
|
|
8
|
+
|
|
9
|
+
Rails.application.config.spree_storefront.cart_partials << 'spree_google_analytics/cart'
|
|
10
|
+
Rails.application.config.spree_storefront.add_to_cart_partials << 'spree_google_analytics/add_to_cart'
|
|
11
|
+
Rails.application.config.spree_storefront.remove_from_cart_partials << 'spree_google_analytics/remove_from_cart'
|
|
12
|
+
|
|
13
|
+
Rails.application.config.spree_storefront.checkout_complete_partials << 'spree_google_analytics/checkout_complete'
|
|
14
|
+
|
|
15
|
+
Rails.application.config.spree_storefront.product_partials << 'spree_google_analytics/product'
|
|
16
|
+
Rails.application.config.spree_storefront.add_to_wishlist_partials << 'spree_google_analytics/add_to_wishlist'
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
---
|
|
2
|
+
en:
|
|
3
|
+
spree:
|
|
4
|
+
admin:
|
|
5
|
+
integrations:
|
|
6
|
+
google_analytics:
|
|
7
|
+
description: Google Analytics 4 is a powerful tool that helps businesses understand and analyze their website and app data.
|
|
8
|
+
reports_warning: It can take up to 48 hours for the data to appear in standard reports
|
|
9
|
+
measurement_id: Measurement ID
|
|
10
|
+
api_secret: API Secret
|
|
11
|
+
google_tag_manager_id: Google Tag Manager ID
|
|
12
|
+
client: Client Type
|
|
13
|
+
client_help: Choose between Google Analytics 4 (direct gtag.js implementation) or Google Tag Manager (dataLayer events)
|
data/config/routes.rb
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module SpreeGoogleAnalytics
|
|
2
|
+
module Generators
|
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
|
4
|
+
class_option :migrate, type: :boolean, default: true
|
|
5
|
+
|
|
6
|
+
def add_migrations
|
|
7
|
+
run 'bundle exec rake railties:install:migrations FROM=spree_google_analytics'
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def run_migrations
|
|
11
|
+
run_migrations = options[:migrate] || ['', 'y', 'Y'].include?(ask('Would you like to run the migrations now? [Y/n]'))
|
|
12
|
+
if run_migrations
|
|
13
|
+
run 'bin/rails db:migrate'
|
|
14
|
+
else
|
|
15
|
+
puts 'Skipping rails db:migrate, don\'t forget to run it!'
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module SpreeGoogleAnalytics
|
|
2
|
+
class Configuration < Spree::Preferences::Configuration
|
|
3
|
+
|
|
4
|
+
# Some example preferences are shown below, for more information visit:
|
|
5
|
+
# https://docs.spreecommerce.org/developer/contributing/creating-an-extension
|
|
6
|
+
|
|
7
|
+
# preference :enabled, :boolean, default: true
|
|
8
|
+
# preference :dark_chocolate, :boolean, default: true
|
|
9
|
+
# preference :color, :string, default: 'Red'
|
|
10
|
+
# preference :favorite_number, :integer
|
|
11
|
+
# preference :supported_locales, :array, default: [:en]
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
module SpreeGoogleAnalytics
|
|
2
|
+
class Engine < Rails::Engine
|
|
3
|
+
require 'spree/core'
|
|
4
|
+
isolate_namespace Spree
|
|
5
|
+
engine_name 'spree_google_analytics'
|
|
6
|
+
|
|
7
|
+
# use rspec for tests
|
|
8
|
+
config.generators do |g|
|
|
9
|
+
g.test_framework :rspec
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
initializer 'spree_google_analytics.environment', before: :load_config_initializers do |_app|
|
|
13
|
+
SpreeGoogleAnalytics::Config = SpreeGoogleAnalytics::Configuration.new
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
initializer 'spree_google_analytics.assets' do |app|
|
|
17
|
+
if app.config.respond_to?(:assets)
|
|
18
|
+
app.config.assets.paths << root.join('app/javascript')
|
|
19
|
+
app.config.assets.paths << root.join('vendor/javascript')
|
|
20
|
+
app.config.assets.paths << root.join('vendor/stylesheets')
|
|
21
|
+
app.config.assets.precompile += %w[spree_google_analytics_manifest]
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
initializer 'spree_google_analytics.importmap', before: 'importmap' do |app|
|
|
26
|
+
app.config.importmap.paths << root.join('config/importmap.rb')
|
|
27
|
+
# https://github.com/rails/importmap-rails?tab=readme-ov-file#sweeping-the-cache-in-development-and-test
|
|
28
|
+
app.config.importmap.cache_sweepers << root.join('app/javascript')
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def self.activate
|
|
32
|
+
Dir.glob(File.join(File.dirname(__FILE__), '../../app/**/*_decorator*.rb')) do |c|
|
|
33
|
+
Rails.configuration.cache_classes ? require(c) : load(c)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
config.to_prepare(&method(:activate).to_proc)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
File without changes
|
|
File without changes
|
metadata
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: ba_spree_google_analytics
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.1.2
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Vendo Connect Inc., Vendo Sp. z o.o.
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2026-08-20 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: spree
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: 5.1.0
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: 5.1.0
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: spree_storefront
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: 5.1.0
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ">="
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: 5.1.0
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: spree_admin
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ">="
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: 5.1.0
|
|
48
|
+
type: :runtime
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ">="
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: 5.1.0
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: spree_extension
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - '='
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: 0.1.0
|
|
62
|
+
type: :runtime
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - '='
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: 0.1.0
|
|
69
|
+
description:
|
|
70
|
+
email: hello@spreecommerce.org
|
|
71
|
+
executables: []
|
|
72
|
+
extensions: []
|
|
73
|
+
extra_rdoc_files: []
|
|
74
|
+
files:
|
|
75
|
+
- LICENSE
|
|
76
|
+
- README.md
|
|
77
|
+
- Rakefile
|
|
78
|
+
- app/.gitkeep
|
|
79
|
+
- app/assets/config/spree_google_analytics_manifest.js
|
|
80
|
+
- app/assets/images/integration_icons/google-analytics-logo.png
|
|
81
|
+
- app/controllers/.gitkeep
|
|
82
|
+
- app/controllers/spree_google_analytics/store_controller_decorator.rb
|
|
83
|
+
- app/helpers/spree_google_analytics/base_helper.rb
|
|
84
|
+
- app/javascript/spree_google_analytics/application.js
|
|
85
|
+
- app/javascript/spree_google_analytics/controllers/spree_google_analytics_controller.js
|
|
86
|
+
- app/models/.gitkeep
|
|
87
|
+
- app/models/spree/integrations/google_analytics.rb
|
|
88
|
+
- app/presenters/spree_google_analytics/checkout_presenter.rb
|
|
89
|
+
- app/presenters/spree_google_analytics/order_presenter.rb
|
|
90
|
+
- app/presenters/spree_google_analytics/payment_presenter.rb
|
|
91
|
+
- app/presenters/spree_google_analytics/product_presenter.rb
|
|
92
|
+
- app/serializers/.gitkeep
|
|
93
|
+
- app/services/.gitkeep
|
|
94
|
+
- app/views/spree/admin/integrations/forms/_google_analytics.html.erb
|
|
95
|
+
- app/views/spree_google_analytics/_add_to_cart.html.erb
|
|
96
|
+
- app/views/spree_google_analytics/_add_to_wishlist.erb
|
|
97
|
+
- app/views/spree_google_analytics/_body_end.html.erb
|
|
98
|
+
- app/views/spree_google_analytics/_body_start.html.erb
|
|
99
|
+
- app/views/spree_google_analytics/_cart.html.erb
|
|
100
|
+
- app/views/spree_google_analytics/_checkout_complete.html.erb
|
|
101
|
+
- app/views/spree_google_analytics/_head.html.erb
|
|
102
|
+
- app/views/spree_google_analytics/_product.html.erb
|
|
103
|
+
- app/views/spree_google_analytics/_remove_from_cart.html.erb
|
|
104
|
+
- config/importmap.rb
|
|
105
|
+
- config/initializers/spree.rb
|
|
106
|
+
- config/locales/en.yml
|
|
107
|
+
- config/routes.rb
|
|
108
|
+
- lib/ba_spree_google_analytics.rb
|
|
109
|
+
- lib/generators/spree_google_analytics/install/install_generator.rb
|
|
110
|
+
- lib/spree_google_analytics.rb
|
|
111
|
+
- lib/spree_google_analytics/configuration.rb
|
|
112
|
+
- lib/spree_google_analytics/engine.rb
|
|
113
|
+
- lib/spree_google_analytics/factories.rb
|
|
114
|
+
- lib/spree_google_analytics/testing_support/factories/google_analytics_integration.rb
|
|
115
|
+
- lib/spree_google_analytics/version.rb
|
|
116
|
+
- vendor/javascript/.keep
|
|
117
|
+
- vendor/stylesheets/.keep
|
|
118
|
+
homepage: https://github.com/be-agile/ba_spree_google_analytics
|
|
119
|
+
licenses:
|
|
120
|
+
- MIT
|
|
121
|
+
metadata:
|
|
122
|
+
bug_tracker_uri: https://github.com/spree/spree_google_analytics/issues
|
|
123
|
+
changelog_uri: https://github.com/spree/spree_google_analytics/releases/tag/v1.1.2
|
|
124
|
+
documentation_uri: https://docs.spreecommerce.org/
|
|
125
|
+
source_code_uri: https://github.com/spree/spree_google_analytics/tree/v1.1.2
|
|
126
|
+
post_install_message:
|
|
127
|
+
rdoc_options: []
|
|
128
|
+
require_paths:
|
|
129
|
+
- lib
|
|
130
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
131
|
+
requirements:
|
|
132
|
+
- - ">="
|
|
133
|
+
- !ruby/object:Gem::Version
|
|
134
|
+
version: '3.0'
|
|
135
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
136
|
+
requirements:
|
|
137
|
+
- - ">="
|
|
138
|
+
- !ruby/object:Gem::Version
|
|
139
|
+
version: '0'
|
|
140
|
+
requirements:
|
|
141
|
+
- none
|
|
142
|
+
rubygems_version: 3.4.9
|
|
143
|
+
signing_key:
|
|
144
|
+
specification_version: 4
|
|
145
|
+
summary: Spree Commerce Google analytics Extension
|
|
146
|
+
test_files: []
|