spree_gtm 0.0.14 → 0.0.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +5 -0
- data/LICENSE +1 -1
- data/README.md +71 -4
- data/app/views/spree/gtm/_google_tag_manager_head.html.erb +30 -0
- data/spec/requests/admin/gtm_render_tag_spec.rb +20 -0
- data/spec/requests/gtm_dont_render_tag_spec.rb +12 -0
- data/spec/spec_helper.rb +4 -1
- data/spec/support/authentication_helpers.rb +9 -0
- data/spree_gtm.gemspec +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 68c7a090be3725ad8a368dfc8fc2d868699d57f9
|
4
|
+
data.tar.gz: 91b2569964948d4a9c9a25af05b6fe51361757de
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cff1c9effa20a91f7f31e42f100e875e25422ca8966d17104a89b32e29b614a1cc193104c12a0cd3555ca7079f0a86075e9678438b9c0d961e18c0efbbccb08e
|
7
|
+
data.tar.gz: bc2cffda908ee76c6b6ada78a96cf00fa8a47d02fb320535bd74071d23d50cde41a82565dcfad3953c66963ca27eaf465e3ab4109ac5159a3e927dcb0c8c7661
|
data/Gemfile
CHANGED
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,12 +1,20 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
SPREE GOOGLE TAG MANAGER PLUGIN
|
2
|
+
============
|
3
3
|
|
4
4
|
[![Gem Version](https://badge.fury.io/rb/spree_gtm.svg)](https://badge.fury.io/rb/spree_gtm)
|
5
5
|
[![Code Climate](https://codeclimate.com/github/RostislavKorin/spree_gtm/badges/gpa.svg)](https://codeclimate.com/github/RostislavKorin/spree_gtm)
|
6
6
|
[![Build Status](https://travis-ci.org/RostislavKorin/spree_gtm.svg?branch=master)](https://travis-ci.org/RostislavKorin/spree_gtm)
|
7
7
|
|
8
|
+
DESCRIPTION
|
9
|
+
--------------------------------
|
10
|
+
spree_gtm is an extension to Spree (a complete open source commerce solution for Ruby on Rails) that uses for implementation Google Tag Manager
|
11
|
+
|
12
|
+
REQUIREMENTS
|
13
|
+
--------------------------------
|
14
|
+
Spree Core 3.0.0 or greater
|
15
|
+
|
8
16
|
Installation
|
9
|
-
|
17
|
+
--------------------------------
|
10
18
|
|
11
19
|
Add to your spree shop Gemfile
|
12
20
|
|
@@ -15,6 +23,65 @@ Add to your spree shop Gemfile
|
|
15
23
|
Run bundle install
|
16
24
|
|
17
25
|
Configuration
|
18
|
-
|
26
|
+
--------------------------------
|
19
27
|
|
20
28
|
Go to admin > Configuration > gtm, fill in your gtm account id
|
29
|
+
|
30
|
+
Examples
|
31
|
+
--------------------------------
|
32
|
+
This is an exemple of configuration s2m order tag:
|
33
|
+
|
34
|
+
```
|
35
|
+
<script type="text/javascript">
|
36
|
+
<!--
|
37
|
+
function _s2m_t()
|
38
|
+
{
|
39
|
+
var s2m_shop = S2MOrderTransaction( 1347, "4.1.20160413" );
|
40
|
+
var orderInfo = new Object();
|
41
|
+
orderInfo.trans_id = {{transactionId}};
|
42
|
+
orderInfo.trans_type = "order";
|
43
|
+
orderInfo.amount_1 = {{transactionTotal}} - {{transactionShipping}};
|
44
|
+
orderInfo.amount_2 = {{transactionTotal}} - {{transactionShipping}} - {{transactionTax}};
|
45
|
+
orderInfo.amount_3 = {{transactionShipping}} + {{transactionTax}};
|
46
|
+
s2m_shop.set_order_info( orderInfo );
|
47
|
+
|
48
|
+
// Repeat itemInfo# where # increases per product
|
49
|
+
var itemInfo1 = new Object();
|
50
|
+
var products = {{transactionProducts}}
|
51
|
+
for (i=0; i<products.length; i++){
|
52
|
+
itemInfo1.trans_id = {{transactionId}};
|
53
|
+
itemInfo1.item_id = {{transactionProducts}}[i].sku;
|
54
|
+
itemInfo1.item_info_1 = {{transactionProducts}}[i].name;
|
55
|
+
itemInfo1.item_amount_1 = {{transactionProducts}}[i].price;
|
56
|
+
itemInfo1.item_amount_2 = {{transactionProducts}}[i].price;
|
57
|
+
itemInfo1.quantity = {{transactionProducts}}[i].quantity;
|
58
|
+
s2m_shop.add_item_info( itemInfo1 );}
|
59
|
+
|
60
|
+
var userInfo = new Object();
|
61
|
+
userInfo.user_email = {{transactionEmail}};
|
62
|
+
userInfo.customer_id = {{userid}};
|
63
|
+
s2m_shop.set_user_info( userInfo );
|
64
|
+
s2m_shop.transact();
|
65
|
+
}
|
66
|
+
try{
|
67
|
+
var __s2m_host = "demo.shop2market.com";
|
68
|
+
var __s2m_js = document.createElement('script');
|
69
|
+
__s2m_js.type = 'text/javascript'; __s2m_js.async = true;
|
70
|
+
__s2m_js.src = (("https:" == document.location.protocol) ? "https://" : "http://") + __s2m_host + "/javascripts/s2m.js";
|
71
|
+
__s2m_js.onload = _s2m_t;
|
72
|
+
__s2m_js.onreadystatechange = function () {
|
73
|
+
if (this.readyState == 'complete'|| this.readyState == 'loaded') _s2m_t();
|
74
|
+
}
|
75
|
+
var __s2m_script = document.getElementsByTagName('script')[0];
|
76
|
+
__s2m_script.parentNode.insertBefore( __s2m_js, __s2m_script );
|
77
|
+
}catch(err){}
|
78
|
+
-->
|
79
|
+
</script>
|
80
|
+
```
|
81
|
+
where {{transactionId}}, {{transactionTotal}}, {{transactionProducts}} etc. are VARIABLES which you must create in GOOGLE TAG MANAGER taking date from Data Layer.
|
82
|
+
|
83
|
+
RESOURCES
|
84
|
+
--------------------------------
|
85
|
+
https://www.google.com/analytics/tag-manager/
|
86
|
+
|
87
|
+
https://spreecommerce.com/
|
@@ -15,9 +15,39 @@
|
|
15
15
|
<% if @order.present? and @order.email.present? %>
|
16
16
|
dataLayer.push({'transactionEmail': '<%= @order.email %>'});
|
17
17
|
<% end %>
|
18
|
+
|
19
|
+
<% if current_page?('/cart') %>
|
20
|
+
dataLayer.push({'cart': [
|
21
|
+
<%=raw @order.line_items.map { |line_item| "{ 'sku': '#{h line_item.variant.sku}',
|
22
|
+
'name': '#{h line_item.variant.product.name}',
|
23
|
+
'category': '',
|
24
|
+
'price': #{h line_item.price},
|
25
|
+
'quantity': #{h line_item.quantity}}" } .join(",") %>
|
26
|
+
]
|
27
|
+
});
|
28
|
+
<% end %>
|
29
|
+
|
30
|
+
<% if @product %>
|
31
|
+
dataLayer.push({'product': [
|
32
|
+
'name': '<%= @product.name %>',
|
33
|
+
'sku': '<%= @product.sku %>',
|
34
|
+
'price': '<%= @product.price %>'
|
35
|
+
]
|
36
|
+
});
|
37
|
+
<% end %>
|
38
|
+
|
39
|
+
<% if @category %>
|
40
|
+
dataLayer.push({'category': ['name': '<%= @category.name %>']});
|
41
|
+
<% end %>
|
42
|
+
|
43
|
+
<% if @search %>
|
44
|
+
dataLayer.push({'search': ['name': '<%= @category.name %>']});
|
45
|
+
<% end %>
|
46
|
+
|
18
47
|
<% if @order.present? and @order.user.present? %>
|
19
48
|
dataLayer.push({'userid': '<%= @order.user.id %>'});
|
20
49
|
<% end %>
|
50
|
+
|
21
51
|
<% if @order.present? && @order.bill_address.present? %>
|
22
52
|
|
23
53
|
dataLayer.push({
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "GTM value set in controller" do
|
4
|
+
context "value set in controller " do
|
5
|
+
it "should render tag" do
|
6
|
+
user = create(:admin_user, :email => "test@example.com", :password => "spree123")
|
7
|
+
sign_in_as!(user)
|
8
|
+
visit spree.admin_path
|
9
|
+
click_link "Configurations"
|
10
|
+
click_link "Google Tag Manager"
|
11
|
+
fill_in('Gtm accountid', :with => 'bag')
|
12
|
+
click_button "Save"
|
13
|
+
page.should have_content("Gtm has been successfully")
|
14
|
+
visit ('/')
|
15
|
+
page.all('body script', visible: false).each do |script|
|
16
|
+
script.text == "dataLayer, bag"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "GTM value doesnt set in controller" do
|
4
|
+
context "value doesnt set in controller " do
|
5
|
+
it "should doesnt render tag" do
|
6
|
+
visit ('/')
|
7
|
+
page.all('body script', visible: false).each do |script|
|
8
|
+
script.text != "dataLayer"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -22,7 +22,7 @@ require 'ffaker'
|
|
22
22
|
# Requires supporting ruby files with custom matchers and macros, etc,
|
23
23
|
# in spec/support/ and its subdirectories.
|
24
24
|
Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each { |f| require f }
|
25
|
-
|
25
|
+
Capybara.ignore_hidden_elements = false
|
26
26
|
# Requires factories and other useful helpers defined in spree_core.
|
27
27
|
require 'spree/testing_support/authorization_helpers'
|
28
28
|
require 'spree/testing_support/capybara_ext'
|
@@ -34,6 +34,9 @@ require 'spree/testing_support/url_helpers'
|
|
34
34
|
require 'spree_gtm/factories'
|
35
35
|
|
36
36
|
RSpec.configure do |config|
|
37
|
+
|
38
|
+
config.include AuthenticationHelpers, :type => :request
|
39
|
+
config.include Capybara::DSL
|
37
40
|
config.include FactoryGirl::Syntax::Methods
|
38
41
|
|
39
42
|
# Infer an example group's spec type from the file location.
|
data/spree_gtm.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spree_gtm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stanislav O. Pogrebnyak
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-12-
|
12
|
+
date: 2016-12-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: spree_core
|
@@ -200,7 +200,10 @@ files:
|
|
200
200
|
- lib/spree_gtm.rb
|
201
201
|
- lib/spree_gtm/engine.rb
|
202
202
|
- lib/spree_gtm/factories.rb
|
203
|
+
- spec/requests/admin/gtm_render_tag_spec.rb
|
204
|
+
- spec/requests/gtm_dont_render_tag_spec.rb
|
203
205
|
- spec/spec_helper.rb
|
206
|
+
- spec/support/authentication_helpers.rb
|
204
207
|
- spree_gtm.gemspec
|
205
208
|
homepage:
|
206
209
|
licenses:
|