rack-tracker 0.2.4 → 0.2.5

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: 9e06fd93da7b2594ba21af4171a47a389f2ffb1e
4
- data.tar.gz: 73edb90317f7a22edd542ab35ec423e3c2fc6d68
3
+ metadata.gz: b7d3f0a731a9473254d058fda92f9e088a255470
4
+ data.tar.gz: 897423fe72752a8dc9a7a49513b6554b70245f53
5
5
  SHA512:
6
- metadata.gz: fb4613641c9e9702f74910113054b3790e735af819d3e8a1deb375084e4600ca4153f714156619fc216d55134aea0042af5f16a1b76bf4ac42da79a4c244b0f1
7
- data.tar.gz: 8bd52e40757e7a90187093db950825cc37d4f13d376b68c142e02f6a4a9c0bde81c8a9eb9052f41666ae37c45b914b6b465d8380900eef7b8e60391edd57224d
6
+ metadata.gz: d298b6b90718d9fbe380dc47c8408b1c9a7e987b2d85b2eafb98b69fb922289e5797e581891304c23f53dd5b9a0c26600a9cea4982ec7147c36f6f8e230cf6c9
7
+ data.tar.gz: 8480c1144c530cb3ba33739e4c5ecba55e5bcfa036bc14ced3633097590e936464899a49c31011380d1a9be90a8bd126d2034b5fc795aa96160c6de68196069a
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 0.2.5
2
+
3
+ * [BUGFIX] stringify google analytics event values to be api compliant
4
+
1
5
  # 0.2.4
2
6
 
3
7
  * [ENHANCEMENT] support all the rack versions >= 1.5.2
@@ -6,3 +6,12 @@ class OpenStruct
6
6
  @table.dup
7
7
  end unless method_defined? :to_h
8
8
  end
9
+
10
+ class Hash
11
+ def stringify_values
12
+ inject({}) do |options, (key, value)|
13
+ options[key] = value.to_s
14
+ options
15
+ end
16
+ end
17
+ end
@@ -10,7 +10,7 @@ class Rack::Tracker::GoogleAnalytics < Rack::Tracker::Handler
10
10
  end
11
11
 
12
12
  def event
13
- { hitType: self.type }.merge(attributes).compact
13
+ { hitType: self.type }.merge(attributes.stringify_values).compact
14
14
  end
15
15
 
16
16
  def attributes
@@ -20,7 +20,7 @@ class Rack::Tracker::GoogleAnalytics < Rack::Tracker::Handler
20
20
 
21
21
  class Ecommerce < OpenStruct
22
22
  def write
23
- ["ecommerce:#{self.type}", self.to_h.except(:type).compact].to_json.gsub(/\[|\]/, '')
23
+ ["ecommerce:#{self.type}", self.to_h.except(:type).compact.stringify_values].to_json.gsub(/\[|\]/, '')
24
24
  end
25
25
  end
26
26
 
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  class Tracker
3
- VERSION = "0.2.4"
3
+ VERSION = '0.2.5'
4
4
  end
5
5
  end
@@ -48,13 +48,13 @@ RSpec.describe Rack::Tracker::GoogleAnalytics do
48
48
  describe "with a event value" do
49
49
  def env
50
50
  {'tracker' => { 'google_analytics' => [
51
- Rack::Tracker::GoogleAnalytics::Send.new(category: "Users", action: "Login", label: "Standard", value: 5)
51
+ Rack::Tracker::GoogleAnalytics::Send.new(category: "Users", action: "Login", label: "Standard", value: "5")
52
52
  ]}}
53
53
  end
54
54
 
55
55
  subject { described_class.new(env, tracker: 'somebody').render }
56
56
  it "will show events with values" do
57
- expect(subject).to match(%r{ga\(\"send\",{\"hitType\":\"event\",\"eventCategory\":\"Users\",\"eventAction\":\"Login\",\"eventLabel\":\"Standard\",\"eventValue\":5}\)},)
57
+ expect(subject).to match(%r{ga\(\"send\",{\"hitType\":\"event\",\"eventCategory\":\"Users\",\"eventAction\":\"Login\",\"eventLabel\":\"Standard\",\"eventValue\":\"5\"}\)},)
58
58
  end
59
59
  end
60
60
  end
@@ -75,7 +75,7 @@ RSpec.describe Rack::Tracker::GoogleAnalytics do
75
75
  expect(subject).to match(%r{ga\(\"ecommerce:addItem\",#{{id: '1234', name: 'Fluffy Pink Bunnies', sku: 'DD23444', category: 'Party Toys', price: '11.99', quantity: '1'}.to_json}})
76
76
  end
77
77
  it "will add transaction" do
78
- expect(subject).to match(%r{ga\(\"ecommerce:addTransaction\",#{{id: '1234', affiliation: 'Acme Clothing', revenue: 11.99, shipping: '5', tax: '1.29', currency: 'EUR'}.to_json}})
78
+ expect(subject).to match(%r{ga\(\"ecommerce:addTransaction\",#{{id: '1234', affiliation: 'Acme Clothing', revenue: '11.99', shipping: '5', tax: '1.29', currency: 'EUR'}.to_json}})
79
79
  end
80
80
  it "will submit cart" do
81
81
  expect(subject).to match(%r{ga\('ecommerce:send'\);})
@@ -11,7 +11,8 @@ RSpec.describe "Facebook Integration" do
11
11
  subject { page }
12
12
 
13
13
  it "embeds the script tag with tracking event from the controller action" do
14
- expect(page).to have_content('ga("ecommerce:addItem",{"id":"1234","affiliation":"Acme Clothing","revenue":"11.99","shipping":"5","tax":"1.29"})')
14
+ expect(page).to have_content('ga("ecommerce:addItem",{"id":"1234","name":"Fluffy Pink Bunnies","sku":"DD23444","category":"Party Toys","price":"11.99","quantity":"1"})')
15
+ expect(page).to have_content('ga("ecommerce:addTransaction",{"id":"1234","affiliation":"Acme Clothing","revenue":"11.99","shipping":"5","tax":"1.29"})')
15
16
  expect(page).to have_content('ga("send",{"hitType":"event","eventCategory":"button","eventAction":"click","eventLabel":"nav-buttons","eventValue":"X"})')
16
17
  end
17
18
  end
@@ -24,7 +24,8 @@ class MetalController < ActionController::Metal
24
24
 
25
25
  def google_analytics
26
26
  tracker do |t|
27
- t.google_analytics :ecommerce, { type: 'addItem', id: '1234', affiliation: 'Acme Clothing', revenue: '11.99', shipping: '5', tax: '1.29' }
27
+ t.google_analytics :ecommerce, { type: 'addTransaction', id: 1234, affiliation: 'Acme Clothing', revenue: 11.99, shipping: 5, tax: 1.29 }
28
+ t.google_analytics :ecommerce, { type: 'addItem', id: 1234, name: 'Fluffy Pink Bunnies', sku: 'DD23444', category: 'Party Toys', price: 11.99, quantity: 1 }
28
29
  t.google_analytics :send, { type: 'event', category: 'button', action: 'click', label: 'nav-buttons', value: 'X' }
29
30
  end
30
31
  render "metal/index"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-tracker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lars Brillert
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-10-09 00:00:00.000000000 Z
12
+ date: 2014-10-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack