spree_gtm 0.0.14 → 0.0.15

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5664b65b255c9770d756b2a4f8655ff4837ce2e4
4
- data.tar.gz: f58c52f4b815159516365a8beee6c7c33db3b251
3
+ metadata.gz: 68c7a090be3725ad8a368dfc8fc2d868699d57f9
4
+ data.tar.gz: 91b2569964948d4a9c9a25af05b6fe51361757de
5
5
  SHA512:
6
- metadata.gz: 70b92688a4c1e0b7e353250f2fd9aff0b950221cc8f22ed62e18d4f223e0b6b0c5e6711ffa4265dcfc9d08792c5987881d2725afbad1c9de6b4a3479abdf5db8
7
- data.tar.gz: 71f9f55c858697425f51a53707aa3610f5d8f25a4f545a2f9e72a80d0c71ca9d23d31dedc1bdbf9847d760bdc7df01f43ed6e72fa7750302810750ffdf5afb6f
6
+ metadata.gz: cff1c9effa20a91f7f31e42f100e875e25422ca8966d17104a89b32e29b614a1cc193104c12a0cd3555ca7079f0a86075e9678438b9c0d961e18c0efbbccb08e
7
+ data.tar.gz: bc2cffda908ee76c6b6ada78a96cf00fa8a47d02fb320535bd74071d23d50cde41a82565dcfad3953c66963ca27eaf465e3ab4109ac5159a3e927dcb0c8c7661
data/Gemfile CHANGED
@@ -5,3 +5,8 @@ gem 'spree', github: 'spree/spree', branch: '3-1-stable'
5
5
  gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: '3-1-stable'
6
6
 
7
7
  gemspec
8
+
9
+ group :test do
10
+ gem 'rspec'
11
+ gem 'launchy'
12
+ end
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2016 [name of plugin creator]
1
+ Copyright (c) 2016 Rostislav Korin
2
2
  All rights reserved.
3
3
 
4
4
  Redistribution and use in source and binary forms, with or without modification,
data/README.md CHANGED
@@ -1,12 +1,20 @@
1
- Spree Google Tag Maneger Plugin
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.
@@ -0,0 +1,9 @@
1
+ module AuthenticationHelpers
2
+ def sign_in_as!(user)
3
+ visit '/login'
4
+ fill_in "Email", :with => "test@example.com"
5
+ fill_in "Password", :with => "spree123"
6
+ click_button "Login"
7
+ page.should have_content("Logged in successfully")
8
+ end
9
+ end
data/spree_gtm.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
  Gem::Specification.new do |s|
3
3
  s.platform = Gem::Platform::RUBY
4
4
  s.name = 'spree_gtm'
5
- s.version = '0.0.14'
5
+ s.version = '0.0.15'
6
6
  s.summary = 'some summary here'
7
7
  s.description = 'some gem description here'
8
8
  s.required_ruby_version = '>= 2.1.0'
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.14
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-26 00:00:00.000000000 Z
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: