staccato 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/.travis.yml +2 -3
- data/CHANGELOG.md +6 -0
- data/README.md +1 -1
- data/lib/staccato/hit.rb +7 -3
- data/lib/staccato/measurable.rb +44 -0
- data/lib/staccato/measurement/product.rb +5 -0
- data/lib/staccato/measurement/product_impression.rb +5 -0
- data/lib/staccato/version.rb +1 -1
- data/spec/integration/measurement/checkout_option_spec.rb +3 -3
- data/spec/integration/measurement/checkout_spec.rb +3 -3
- data/spec/integration/measurement/product_impression_spec.rb +100 -23
- data/spec/integration/measurement/product_spec.rb +97 -24
- data/spec/integration/measurement/promotion_spec.rb +3 -3
- data/spec/integration/measurement/transaction_spec.rb +3 -3
- data/spec/lib/staccato/pageview_spec.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1de9ca3518d24e4139fc2311de9ff15aa79d18a2
|
4
|
+
data.tar.gz: bccdd80d9c617e2303ce2290ceddcd06828d888d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fde81fda9b06a81f5c45cea7ed60cfe51fd4942ff7f104227817e2424666654976ab6ad935efb27a114e5d2b6ae1840bc5cdde33bd451770a1e92cd15a5eba70
|
7
|
+
data.tar.gz: 58e26c6147b312c0a8ed846d39b36edd416d6a8a7f20c60f6a5eb048c8a8417fe21a387924145da2e9e5560e088920444838edefb005c2209ceb4e669e59e9ef
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
2.2.2
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -431,7 +431,7 @@ You can also make your own Adapters by implementing any class that responds to `
|
|
431
431
|
One such example might be for a new `net/http` adapter which accepts more options for configuring the connection:
|
432
432
|
|
433
433
|
```ruby
|
434
|
-
class
|
434
|
+
class CustomAdapter
|
435
435
|
attr_reader :uri
|
436
436
|
|
437
437
|
def initialize(uri, options={})
|
data/lib/staccato/hit.rb
CHANGED
@@ -135,11 +135,15 @@ module Staccato
|
|
135
135
|
end
|
136
136
|
|
137
137
|
# Add a measurement by its symbol name with options
|
138
|
-
#
|
138
|
+
#
|
139
139
|
# @param key [Symbol] any one of the measurable classes lookup key
|
140
|
-
# @param options [Hash]
|
140
|
+
# @param options [Hash or Object] for the measurement
|
141
141
|
def add_measurement(key, options = {})
|
142
|
-
|
142
|
+
if options.is_a?(Hash)
|
143
|
+
self.measurements << Measurement.lookup(key).new(options)
|
144
|
+
else
|
145
|
+
self.measurements << options
|
146
|
+
end
|
143
147
|
end
|
144
148
|
|
145
149
|
# Measurements for this hit
|
data/lib/staccato/measurable.rb
CHANGED
@@ -28,9 +28,53 @@ module Staccato
|
|
28
28
|
''
|
29
29
|
end
|
30
30
|
|
31
|
+
# not all measurements allow custom dimensions or metrics
|
32
|
+
def custom_fields_allowed?
|
33
|
+
false
|
34
|
+
end
|
35
|
+
|
31
36
|
# collects the parameters from options for this measurement
|
32
37
|
# @return [Hash]
|
33
38
|
def params
|
39
|
+
{}.
|
40
|
+
merge!(measurable_params).
|
41
|
+
merge!(custom_dimensions).
|
42
|
+
merge!(custom_metrics).
|
43
|
+
reject {|_,v| v.nil?}
|
44
|
+
end
|
45
|
+
|
46
|
+
# Set a custom dimension value at an index
|
47
|
+
# @param dimension_index [Integer]
|
48
|
+
# @param value
|
49
|
+
def add_custom_dimension(dimension_index, value)
|
50
|
+
return unless custom_fields_allowed?
|
51
|
+
self.custom_dimensions["#{prefix}cd#{dimension_index}"] = value
|
52
|
+
end
|
53
|
+
|
54
|
+
# Custom dimensions for this measurable
|
55
|
+
# @return [Hash]
|
56
|
+
def custom_dimensions
|
57
|
+
@custom_dimensions ||= {}
|
58
|
+
end
|
59
|
+
|
60
|
+
# Set a custom metric value at an index
|
61
|
+
# @param metric_index [Integer]
|
62
|
+
# @param value
|
63
|
+
def add_custom_metric(metric_index, value)
|
64
|
+
return unless custom_fields_allowed?
|
65
|
+
self.custom_metrics["#{prefix}cm#{metric_index}"] = value
|
66
|
+
end
|
67
|
+
|
68
|
+
# Custom metrics for this measurable
|
69
|
+
# @return [Hash]
|
70
|
+
def custom_metrics
|
71
|
+
@custom_metrics ||= {}
|
72
|
+
end
|
73
|
+
|
74
|
+
private
|
75
|
+
|
76
|
+
# @private
|
77
|
+
def measurable_params
|
34
78
|
Hash[
|
35
79
|
fields.map { |field,key|
|
36
80
|
next if key.nil?
|
@@ -14,6 +14,11 @@ module Staccato
|
|
14
14
|
'il' + list_index.to_s + 'pi' + index.to_s
|
15
15
|
end
|
16
16
|
|
17
|
+
# product impression allow custom dimensions and metrics
|
18
|
+
def custom_fields_allowed?
|
19
|
+
true
|
20
|
+
end
|
21
|
+
|
17
22
|
# Product impression measurement options fields
|
18
23
|
FIELDS = {
|
19
24
|
index: nil,
|
data/lib/staccato/version.rb
CHANGED
@@ -18,18 +18,18 @@ describe Staccato::Measurement::CheckoutOption do
|
|
18
18
|
})
|
19
19
|
}
|
20
20
|
|
21
|
-
let(:
|
21
|
+
let(:measurement_options) {{
|
22
22
|
step: 1,
|
23
23
|
step_options: 'Visa'
|
24
24
|
}}
|
25
25
|
|
26
26
|
before(:each) do
|
27
|
-
pageview.add_measurement(:checkout_option,
|
27
|
+
pageview.add_measurement(:checkout_option, measurement_options)
|
28
28
|
|
29
29
|
pageview.track!
|
30
30
|
end
|
31
31
|
|
32
|
-
it 'tracks the
|
32
|
+
it 'tracks the measurement' do
|
33
33
|
expect(Net::HTTP).to have_received(:post_form).with(uri, {
|
34
34
|
'v' => 1,
|
35
35
|
'tid' => 'UA-XXXX-Y',
|
@@ -18,18 +18,18 @@ describe Staccato::Measurement::Checkout do
|
|
18
18
|
})
|
19
19
|
}
|
20
20
|
|
21
|
-
let(:
|
21
|
+
let(:measurement_options) {{
|
22
22
|
step: 1,
|
23
23
|
step_options: 'Visa'
|
24
24
|
}}
|
25
25
|
|
26
26
|
before(:each) do
|
27
|
-
pageview.add_measurement(:checkout,
|
27
|
+
pageview.add_measurement(:checkout, measurement_options)
|
28
28
|
|
29
29
|
pageview.track!
|
30
30
|
end
|
31
31
|
|
32
|
-
it 'tracks the
|
32
|
+
it 'tracks the measurement' do
|
33
33
|
expect(Net::HTTP).to have_received(:post_form).with(uri, {
|
34
34
|
'v' => 1,
|
35
35
|
'tid' => 'UA-XXXX-Y',
|
@@ -5,40 +5,48 @@ describe Staccato::Measurement::ProductImpression do
|
|
5
5
|
let(:tracker) {Staccato.tracker('UA-XXXX-Y')}
|
6
6
|
let(:response) {stub(:body => '', :status => 201)}
|
7
7
|
|
8
|
+
let(:pageview) {
|
9
|
+
tracker.build_pageview({
|
10
|
+
path: '/home',
|
11
|
+
hostname: 'mystore.com',
|
12
|
+
title: 'Home Page'
|
13
|
+
})
|
14
|
+
}
|
15
|
+
|
16
|
+
let(:impression_list_options) {{
|
17
|
+
index: 1,
|
18
|
+
name: 'Search Results'
|
19
|
+
}}
|
20
|
+
|
21
|
+
let(:product_impression_options) {{
|
22
|
+
index: 1,
|
23
|
+
list_index: 1, # match the impression_list above
|
24
|
+
id: 'P12345',
|
25
|
+
name: 'T-Shirt',
|
26
|
+
category: 'Apparel',
|
27
|
+
brand: 'Your Brand',
|
28
|
+
variant: 'Purple',
|
29
|
+
position: 1,
|
30
|
+
price: 14.60
|
31
|
+
}}
|
32
|
+
|
33
|
+
let(:product_impression) { Staccato::Measurement::ProductImpression.new(product_impression_options) }
|
34
|
+
|
8
35
|
before(:each) do
|
9
36
|
SecureRandom.stubs(:uuid).returns('555')
|
10
37
|
Net::HTTP.stubs(:post_form).returns(response)
|
11
38
|
end
|
12
39
|
|
13
|
-
context 'a pageview with
|
14
|
-
let(:pageview) {
|
15
|
-
tracker.build_pageview({
|
16
|
-
path: '/home',
|
17
|
-
hostname: 'mystore.com',
|
18
|
-
title: 'Home Page'
|
19
|
-
})
|
20
|
-
}
|
21
|
-
|
22
|
-
let(:measurment_options) {{
|
23
|
-
index: 1,
|
24
|
-
list_index: 1, # match the impression_list above
|
25
|
-
id: 'P12345',
|
26
|
-
name: 'T-Shirt',
|
27
|
-
category: 'Apparel',
|
28
|
-
brand: 'Your Brand',
|
29
|
-
variant: 'Purple',
|
30
|
-
position: 1,
|
31
|
-
price: 14.60
|
32
|
-
}}
|
40
|
+
context 'a pageview with an List Impression' do
|
33
41
|
|
34
42
|
before(:each) do
|
35
|
-
pageview.add_measurement(:impression_list,
|
36
|
-
pageview.add_measurement(:product_impression,
|
43
|
+
pageview.add_measurement(:impression_list, impression_list_options)
|
44
|
+
pageview.add_measurement(:product_impression, product_impression_options)
|
37
45
|
|
38
46
|
pageview.track!
|
39
47
|
end
|
40
48
|
|
41
|
-
it 'tracks the
|
49
|
+
it 'tracks the measurement' do
|
42
50
|
expect(Net::HTTP).to have_received(:post_form).with(uri, {
|
43
51
|
'v' => 1,
|
44
52
|
'tid' => 'UA-XXXX-Y',
|
@@ -58,4 +66,73 @@ describe Staccato::Measurement::ProductImpression do
|
|
58
66
|
})
|
59
67
|
end
|
60
68
|
end
|
69
|
+
|
70
|
+
context 'with some custom dimensions' do
|
71
|
+
|
72
|
+
before(:each) do
|
73
|
+
pageview.add_measurement(:impression_list, impression_list_options)
|
74
|
+
product_impression.add_custom_dimension(1, 'Apple')
|
75
|
+
product_impression.add_custom_dimension(5, 'Samsung')
|
76
|
+
pageview.add_measurement(:product_impression, product_impression)
|
77
|
+
|
78
|
+
pageview.track!
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'has custom dimensions data' do
|
82
|
+
expect(Net::HTTP).to have_received(:post_form).with(uri, {
|
83
|
+
'v' => 1,
|
84
|
+
'tid' => 'UA-XXXX-Y',
|
85
|
+
'cid' => '555',
|
86
|
+
't' => 'pageview',
|
87
|
+
'dh' => 'mystore.com',
|
88
|
+
'dp' => '/home',
|
89
|
+
'dt' => 'Home Page',
|
90
|
+
'il1nm' => 'Search Results',
|
91
|
+
'il1pi1id' => 'P12345',
|
92
|
+
'il1pi1nm' => 'T-Shirt',
|
93
|
+
'il1pi1br' => 'Your Brand',
|
94
|
+
'il1pi1ca' => 'Apparel',
|
95
|
+
'il1pi1va' => 'Purple',
|
96
|
+
'il1pi1pr' => 14.60,
|
97
|
+
'il1pi1ps' => 1,
|
98
|
+
'il1pi1cd1' => 'Apple',
|
99
|
+
'il1pi1cd5' => 'Samsung'
|
100
|
+
})
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
context 'with some custom metrics' do
|
105
|
+
|
106
|
+
before(:each) do
|
107
|
+
pageview.add_measurement(:impression_list, impression_list_options)
|
108
|
+
product_impression.add_custom_metric(1, 43.20)
|
109
|
+
product_impression.add_custom_metric(3, 8)
|
110
|
+
pageview.add_measurement(:product_impression, product_impression)
|
111
|
+
|
112
|
+
pageview.track!
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'has custom metric data' do
|
116
|
+
expect(Net::HTTP).to have_received(:post_form).with(uri, {
|
117
|
+
'v' => 1,
|
118
|
+
'tid' => 'UA-XXXX-Y',
|
119
|
+
'cid' => '555',
|
120
|
+
't' => 'pageview',
|
121
|
+
'dh' => 'mystore.com',
|
122
|
+
'dp' => '/home',
|
123
|
+
'dt' => 'Home Page',
|
124
|
+
'il1nm' => 'Search Results',
|
125
|
+
'il1pi1id' => 'P12345',
|
126
|
+
'il1pi1nm' => 'T-Shirt',
|
127
|
+
'il1pi1br' => 'Your Brand',
|
128
|
+
'il1pi1ca' => 'Apparel',
|
129
|
+
'il1pi1va' => 'Purple',
|
130
|
+
'il1pi1pr' => 14.60,
|
131
|
+
'il1pi1ps' => 1,
|
132
|
+
'il1pi1cm1' => 43.20,
|
133
|
+
'il1pi1cm3' => 8
|
134
|
+
})
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
61
138
|
end
|
@@ -5,42 +5,113 @@ describe Staccato::Measurement::Product do
|
|
5
5
|
let(:tracker) {Staccato.tracker('UA-XXXX-Y')}
|
6
6
|
let(:response) {stub(:body => '', :status => 201)}
|
7
7
|
|
8
|
+
let(:event) {
|
9
|
+
tracker.build_event({
|
10
|
+
category: 'search',
|
11
|
+
action: 'click',
|
12
|
+
label: 'results',
|
13
|
+
product_action: 'click',
|
14
|
+
product_action_list: 'Search Results'
|
15
|
+
})
|
16
|
+
}
|
17
|
+
|
18
|
+
let(:product_options) {{
|
19
|
+
index: 1,
|
20
|
+
id: 'P12345',
|
21
|
+
name: 'T-Shirt',
|
22
|
+
category: 'Apparel',
|
23
|
+
brand: 'Your Brand',
|
24
|
+
variant: 'Purple',
|
25
|
+
quantity: 2,
|
26
|
+
position: 1,
|
27
|
+
price: 14.60,
|
28
|
+
coupon_code: 'ILUVTEES'
|
29
|
+
}}
|
30
|
+
|
31
|
+
let(:product) { Staccato::Measurement::Product.new(product_options) }
|
32
|
+
|
8
33
|
before(:each) do
|
9
34
|
SecureRandom.stubs(:uuid).returns('555')
|
10
35
|
Net::HTTP.stubs(:post_form).returns(response)
|
11
36
|
end
|
12
37
|
|
13
|
-
context 'a pageview with
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
38
|
+
context 'a pageview with an event' do
|
39
|
+
|
40
|
+
before do
|
41
|
+
event.add_measurement(:product, product_options)
|
42
|
+
event.track!
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'tracks the measurement' do
|
46
|
+
expect(Net::HTTP).to have_received(:post_form).with(uri, {
|
47
|
+
'v' => 1,
|
48
|
+
'tid' => 'UA-XXXX-Y',
|
49
|
+
'cid' => '555',
|
50
|
+
't' => 'event',
|
51
|
+
'ec' => 'search',
|
52
|
+
'ea' => 'click',
|
53
|
+
'el' => 'results',
|
54
|
+
'pa' => 'click',
|
55
|
+
'pal' => 'Search Results',
|
56
|
+
'pr1id' => 'P12345',
|
57
|
+
'pr1nm' => 'T-Shirt',
|
58
|
+
'pr1ca' => 'Apparel',
|
59
|
+
'pr1br' => 'Your Brand',
|
60
|
+
'pr1va' => 'Purple',
|
61
|
+
'pr1qt' => 2,
|
62
|
+
'pr1ps' => 1,
|
63
|
+
'pr1pr' => 14.60,
|
64
|
+
'pr1cc' => 'ILUVTEES'
|
21
65
|
})
|
22
|
-
|
66
|
+
end
|
23
67
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
name: 'T-Shirt',
|
28
|
-
category: 'Apparel',
|
29
|
-
brand: 'Your Brand',
|
30
|
-
variant: 'Purple',
|
31
|
-
quantity: 2,
|
32
|
-
position: 1,
|
33
|
-
price: 14.60,
|
34
|
-
coupon_code: 'ILUVTEES'
|
35
|
-
}}
|
68
|
+
end
|
69
|
+
|
70
|
+
context "with some custom dimensions" do
|
36
71
|
|
37
72
|
before(:each) do
|
38
|
-
|
73
|
+
product.add_custom_dimension(1, 'Apple')
|
74
|
+
product.add_custom_dimension(5, 'Samsung')
|
75
|
+
event.add_measurement(:product, product)
|
76
|
+
event.track!
|
77
|
+
end
|
39
78
|
|
79
|
+
it 'has custom dimensions' do
|
80
|
+
expect(Net::HTTP).to have_received(:post_form).with(uri, {
|
81
|
+
'v' => 1,
|
82
|
+
'tid' => 'UA-XXXX-Y',
|
83
|
+
'cid' => '555',
|
84
|
+
't' => 'event',
|
85
|
+
'ec' => 'search',
|
86
|
+
'ea' => 'click',
|
87
|
+
'el' => 'results',
|
88
|
+
'pa' => 'click',
|
89
|
+
'pal' => 'Search Results',
|
90
|
+
'pr1id' => 'P12345',
|
91
|
+
'pr1nm' => 'T-Shirt',
|
92
|
+
'pr1ca' => 'Apparel',
|
93
|
+
'pr1br' => 'Your Brand',
|
94
|
+
'pr1va' => 'Purple',
|
95
|
+
'pr1qt' => 2,
|
96
|
+
'pr1ps' => 1,
|
97
|
+
'pr1pr' => 14.60,
|
98
|
+
'pr1cc' => 'ILUVTEES',
|
99
|
+
'pr1cd1' => 'Apple',
|
100
|
+
'pr1cd5' => 'Samsung'
|
101
|
+
})
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
context "with some custom metrics" do
|
106
|
+
|
107
|
+
before do
|
108
|
+
product.add_custom_metric(1, 78)
|
109
|
+
product.add_custom_metric(3, 30.40)
|
110
|
+
event.add_measurement(:product, product)
|
40
111
|
event.track!
|
41
112
|
end
|
42
113
|
|
43
|
-
it '
|
114
|
+
it 'has custom metrics' do
|
44
115
|
expect(Net::HTTP).to have_received(:post_form).with(uri, {
|
45
116
|
'v' => 1,
|
46
117
|
'tid' => 'UA-XXXX-Y',
|
@@ -59,7 +130,9 @@ describe Staccato::Measurement::Product do
|
|
59
130
|
'pr1qt' => 2,
|
60
131
|
'pr1ps' => 1,
|
61
132
|
'pr1pr' => 14.60,
|
62
|
-
'pr1cc' => 'ILUVTEES'
|
133
|
+
'pr1cc' => 'ILUVTEES',
|
134
|
+
'pr1cm1' => 78,
|
135
|
+
'pr1cm3' => 30.40
|
63
136
|
})
|
64
137
|
end
|
65
138
|
end
|
@@ -18,7 +18,7 @@ describe Staccato::Measurement::Promotion do
|
|
18
18
|
})
|
19
19
|
}
|
20
20
|
|
21
|
-
let(:
|
21
|
+
let(:measurement_options) {{
|
22
22
|
index: 1,
|
23
23
|
id: 'PROMO_1234',
|
24
24
|
name: 'Summer Sale',
|
@@ -27,12 +27,12 @@ describe Staccato::Measurement::Promotion do
|
|
27
27
|
}}
|
28
28
|
|
29
29
|
before(:each) do
|
30
|
-
pageview.add_measurement(:promotion,
|
30
|
+
pageview.add_measurement(:promotion, measurement_options)
|
31
31
|
|
32
32
|
pageview.track!
|
33
33
|
end
|
34
34
|
|
35
|
-
it 'tracks the
|
35
|
+
it 'tracks the measurement' do
|
36
36
|
expect(Net::HTTP).to have_received(:post_form).with(uri, {
|
37
37
|
'v' => 1,
|
38
38
|
'tid' => 'UA-XXXX-Y',
|
@@ -18,7 +18,7 @@ describe Staccato::Measurement::Transaction do
|
|
18
18
|
})
|
19
19
|
}
|
20
20
|
|
21
|
-
let(:
|
21
|
+
let(:measurement_options) {{
|
22
22
|
transaction_id: 'T12345',
|
23
23
|
affiliation: 'Your Store',
|
24
24
|
revenue: 37.39,
|
@@ -29,12 +29,12 @@ describe Staccato::Measurement::Transaction do
|
|
29
29
|
}}
|
30
30
|
|
31
31
|
before(:each) do
|
32
|
-
pageview.add_measurement(:transaction,
|
32
|
+
pageview.add_measurement(:transaction, measurement_options)
|
33
33
|
|
34
34
|
pageview.track!
|
35
35
|
end
|
36
36
|
|
37
|
-
it 'tracks the
|
37
|
+
it 'tracks the measurement' do
|
38
38
|
expect(Net::HTTP).to have_received(:post_form).with(uri, {
|
39
39
|
'v' => 1,
|
40
40
|
'tid' => 'UA-XXXX-Y',
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: staccato
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tony Pitale
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -173,7 +173,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
173
173
|
version: '0'
|
174
174
|
requirements: []
|
175
175
|
rubyforge_project:
|
176
|
-
rubygems_version: 2.
|
176
|
+
rubygems_version: 2.4.5
|
177
177
|
signing_key:
|
178
178
|
specification_version: 4
|
179
179
|
summary: Ruby Google Analytics Measurement
|
@@ -194,4 +194,3 @@ test_files:
|
|
194
194
|
- spec/lib/staccato/pageview_spec.rb
|
195
195
|
- spec/lib/staccato/tracker_spec.rb
|
196
196
|
- spec/spec_helper.rb
|
197
|
-
has_rdoc:
|