gabba 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/README +19 -4
- data/lib/gabba/gabba.rb +136 -31
- data/lib/gabba/version.rb +1 -1
- data/spec/gabba_spec.rb +36 -22
- metadata +20 -39
data/Gemfile.lock
CHANGED
data/README
CHANGED
@@ -14,20 +14,30 @@ HOW TO USE:
|
|
14
14
|
|
15
15
|
Gabba::Gabba.new("UT-1234", "mydomain.com").event("Videos", "Play", "ID", "123", true)
|
16
16
|
|
17
|
+
* Works with existing client-side Google Analytics cookies
|
18
|
+
|
19
|
+
gabba = Gabba::Gabba.new("UT-1234", "mydomain.com")
|
20
|
+
|
21
|
+
# grab the __utma unique identifier
|
22
|
+
gabba.identify_user(cookies[:__utma])
|
23
|
+
|
24
|
+
# trigger actions as normal
|
25
|
+
gabba.page_view("something", "track/me")
|
26
|
+
|
17
27
|
* Setting custom vars
|
18
28
|
|
19
29
|
# Index: 1 through 5
|
20
30
|
index = 1
|
21
|
-
|
31
|
+
|
22
32
|
# Scope: VISITOR, SESSION or PAGE
|
23
33
|
scope = Gabba::Gabba::VISITOR
|
24
|
-
|
34
|
+
|
25
35
|
# Set var
|
26
36
|
gabba.set_custom_var(index, 'Name', 'Value', scope)
|
27
|
-
|
37
|
+
|
28
38
|
# Track the event (all vars will be included)
|
29
39
|
gabba.event(...)
|
30
|
-
|
40
|
+
|
31
41
|
# Track the page view (all vars will be included)
|
32
42
|
gabba.page_view(...)
|
33
43
|
|
@@ -39,3 +49,8 @@ HOW TO USE:
|
|
39
49
|
# Delete var with this index
|
40
50
|
gabba.delete_custom_var index- Track a non-interactive custom event
|
41
51
|
|
52
|
+
* Track ecommerce transactions
|
53
|
+
|
54
|
+
g = Gabba::Gabba.new("UT-6666", "myawesomeshop.net")
|
55
|
+
g.transaction("123456789", "1000.00", 'Acme Clothing', '1.29', '5.00', 'Los Angeles', 'California', 'USA')
|
56
|
+
|
data/lib/gabba/gabba.rb
CHANGED
@@ -5,11 +5,11 @@ require 'cgi'
|
|
5
5
|
require File.dirname(__FILE__) + '/version'
|
6
6
|
|
7
7
|
module Gabba
|
8
|
-
|
8
|
+
|
9
9
|
class NoGoogleAnalyticsAccountError < RuntimeError; end
|
10
10
|
class NoGoogleAnalyticsDomainError < RuntimeError; end
|
11
11
|
class GoogleAnalyticsNetworkError < RuntimeError; end
|
12
|
-
|
12
|
+
|
13
13
|
class Gabba
|
14
14
|
GOOGLE_HOST = "www.google-analytics.com"
|
15
15
|
BEACON_PATH = "/__utm.gif"
|
@@ -21,42 +21,80 @@ module Gabba
|
|
21
21
|
PAGE = 3
|
22
22
|
|
23
23
|
ESCAPES = %w{ ' ! * ) }
|
24
|
-
|
24
|
+
|
25
25
|
attr_accessor :utmwv, :utmn, :utmhn, :utmcs, :utmul, :utmdt, :utmp, :utmac, :utmt, :utmcc, :user_agent
|
26
|
-
|
26
|
+
|
27
|
+
# Public: Initialize Gabba Google Analytics Tracking Object.
|
28
|
+
#
|
29
|
+
# ga_acct - A String containing your Google Analytics account id.
|
30
|
+
# domain - A String containing which domain you want the tracking data to be logged from.
|
31
|
+
# agent - A String containing the user agent you want the tracking to appear to be coming from.
|
32
|
+
# Defaults to "Gabba 0.2 Agent" or whatever the corrent version is.
|
33
|
+
#
|
34
|
+
# Example:
|
35
|
+
#
|
36
|
+
# g = Gabba::Gabba.new("UT-1234", "mydomain.com")
|
37
|
+
#
|
27
38
|
def initialize(ga_acct, domain, agent = Gabba::USER_AGENT)
|
28
39
|
@utmwv = "4.4sh" # GA version
|
29
40
|
@utmcs = "UTF-8" # charset
|
30
41
|
@utmul = "en-us" # language
|
31
|
-
|
42
|
+
|
32
43
|
@utmn = random_id
|
33
44
|
@utmhid = random_id
|
34
|
-
|
45
|
+
|
35
46
|
@utmac = ga_acct
|
36
47
|
@utmhn = domain
|
37
48
|
@user_agent = agent
|
38
49
|
|
39
50
|
@custom_vars = []
|
40
51
|
end
|
41
|
-
|
52
|
+
|
53
|
+
# Public: Set a custom variable to be passed along and logged by Google Analytics
|
54
|
+
# (http://code.google.com/apis/analytics/docs/tracking/gaTrackingCustomVariables.html)
|
55
|
+
#
|
56
|
+
# index - Integer between 1 and 5 for this custom variable
|
57
|
+
# name - String with the name of the custom variable
|
58
|
+
# value - String with the value for teh custom variable
|
59
|
+
# scope - Integer with custom variable scope must be 1 (VISITOR), 2 (SESSION) or 3 (PAGE)
|
60
|
+
#
|
61
|
+
# Example:
|
62
|
+
#
|
63
|
+
# g = Gabba::Gabba.new("UT-1234", "mydomain.com")
|
64
|
+
# g.set_custom_var(1, 'awesomeness', 'supreme', Gabba::VISITOR)
|
65
|
+
# # => ['awesomeness', 'supreme', 1]
|
66
|
+
#
|
67
|
+
# Returns array with the custom variable data
|
42
68
|
def set_custom_var(index, name, value, scope)
|
43
69
|
raise "Index must be between 1 and 5" unless (1..5).include?(index)
|
44
70
|
raise "Scope must be 1 (VISITOR), 2 (SESSION) or 3 (PAGE)" unless (1..3).include?(scope)
|
45
|
-
|
71
|
+
|
46
72
|
@custom_vars[index] = [ name, value, scope ]
|
47
73
|
end
|
48
|
-
|
74
|
+
|
75
|
+
# Public: Delete a previously set custom variable so if is not passed along and logged by Google Analytics
|
76
|
+
# (http://code.google.com/apis/analytics/docs/tracking/gaTrackingCustomVariables.html)
|
77
|
+
#
|
78
|
+
# index - Integer between 1 and 5 for this custom variable
|
79
|
+
#
|
80
|
+
# Example:
|
81
|
+
# g = Gabba::Gabba.new("UT-1234", "mydomain.com")
|
82
|
+
# g.delete_custom_var(1)
|
83
|
+
#
|
49
84
|
def delete_custom_var(index)
|
50
85
|
raise "Index must be between 1 and 5" unless (1..5).include?(index)
|
51
86
|
|
52
87
|
@custom_vars.delete_at(index)
|
53
88
|
end
|
54
|
-
|
89
|
+
|
90
|
+
# Public: Renders the custom variable data in the format needed for GA
|
91
|
+
# (http://code.google.com/apis/analytics/docs/tracking/gaTrackingCustomVariables.html)
|
92
|
+
# Called before actually sending the data along to GA.
|
55
93
|
def custom_var_data
|
56
94
|
names = []
|
57
95
|
values = []
|
58
96
|
scopes = []
|
59
|
-
|
97
|
+
|
60
98
|
idx = 1
|
61
99
|
@custom_vars.each_with_index do |(n, v, s), i|
|
62
100
|
next if !n || !v || (/\w/ !~ n) || (/\w/ !~ v)
|
@@ -66,15 +104,28 @@ module Gabba
|
|
66
104
|
scopes << "#{prefix}#{escape(s)}"
|
67
105
|
idx = i + 1
|
68
106
|
end
|
69
|
-
|
107
|
+
|
70
108
|
names.empty? ? "" : "8(#{names.join('*')})9(#{values.join('*')})11(#{scopes.join('*')})"
|
71
109
|
end
|
72
|
-
|
110
|
+
|
111
|
+
# Public: Record a page view in Google Analytics
|
112
|
+
#
|
113
|
+
# title - String with the page title for thr page view
|
114
|
+
# page - String with the path for the page view
|
115
|
+
# utmhid - String with the unique visitor id, defaults to a new random value
|
116
|
+
#
|
117
|
+
# Example:
|
118
|
+
#
|
119
|
+
# g = Gabba::Gabba.new("UT-1234", "mydomain.com")
|
120
|
+
# g.page_view("something", "track/me")
|
121
|
+
#
|
73
122
|
def page_view(title, page, utmhid = random_id)
|
74
123
|
check_account_params
|
75
124
|
hey(page_view_params(title, page, utmhid))
|
76
125
|
end
|
77
126
|
|
127
|
+
# Public: Renders the page view params data in the format needed for GA
|
128
|
+
# Called before actually sending the data along to GA.
|
78
129
|
def page_view_params(title, page, utmhid = random_id)
|
79
130
|
options = {
|
80
131
|
:utmwv => @utmwv,
|
@@ -95,12 +146,29 @@ module Gabba
|
|
95
146
|
|
96
147
|
options
|
97
148
|
end
|
98
|
-
|
149
|
+
|
150
|
+
# Public: Record an event in Google Analytics
|
151
|
+
# (http://code.google.com/apis/analytics/docs/gaJS/gaJSApiEventTracking.html)
|
152
|
+
#
|
153
|
+
# category -
|
154
|
+
# action -
|
155
|
+
# label -
|
156
|
+
# value -
|
157
|
+
# utmni -
|
158
|
+
# utmhid -
|
159
|
+
#
|
160
|
+
# Example:
|
161
|
+
#
|
162
|
+
# g = Gabba::Gabba.new("UT-1234", "mydomain.com")
|
163
|
+
# g.event("Videos", "Play", "ID", "123", true)
|
164
|
+
#
|
99
165
|
def event(category, action, label = nil, value = nil, utmni = false, utmhid = random_id)
|
100
166
|
check_account_params
|
101
167
|
hey(event_params(category, action, label, value, utmni, utmhid))
|
102
168
|
end
|
103
169
|
|
170
|
+
# Public: Renders event params data in the format needed for GA
|
171
|
+
# Called before actually sending the data along to GA in Gabba#event
|
104
172
|
def event_params(category, action, label = nil, value = nil, utmni = false, utmhid = false)
|
105
173
|
raise ArgumentError.new("utmni must be a boolean") if (utmni.class != TrueClass && utmni.class != FalseClass)
|
106
174
|
{
|
@@ -118,26 +186,43 @@ module Gabba
|
|
118
186
|
}
|
119
187
|
end
|
120
188
|
|
189
|
+
# Public: Renders event individual param data in the format needed for GA
|
190
|
+
# Called before actually sending the data along to GA in Gabba#event
|
121
191
|
def event_data(category, action, label = nil, value = nil)
|
122
192
|
data = "5(#{category}*#{action}" + (label ? "*#{label})" : ")")
|
123
193
|
data += "(#{value})" if value
|
124
194
|
data
|
125
195
|
end
|
126
|
-
|
196
|
+
|
197
|
+
# Public: Track an entire ecommerce transaction to Google Analytics in one call.
|
198
|
+
# (http://code.google.com/apis/analytics/docs/gaJS/gaJSApiEcommerce.html#_gat.GA_Tracker_._trackTrans)
|
199
|
+
#
|
200
|
+
# order_id - URL-encoded order ID (required). Maps to utmtid
|
201
|
+
# total - Order total (required). Maps to utmtto
|
202
|
+
# store_name - Affiliation or store name (default: nil). Maps to utmtst
|
203
|
+
# tax - Sales tax (default: nil). Maps to utmttx
|
204
|
+
# shipping - Shipping (default: nil). Maps to utmtsp
|
205
|
+
# city - City (default: nil). Maps to utmtci
|
206
|
+
# region - State or Provance (default: nil). Maps to utmtrg
|
207
|
+
# country - Country (default: nil). Maps to utmtco
|
208
|
+
# utmhid - String with the unique visitor id (default: random_id)
|
209
|
+
#
|
210
|
+
# Examples:
|
211
|
+
#
|
212
|
+
# g = Gabba::Gabba.new("UT-1234", "mydomain.com")
|
213
|
+
# g.transaction("123456789", "1000.00")
|
214
|
+
#
|
215
|
+
# g = Gabba::Gabba.new("UT-6666", "myawesomeshop.net")
|
216
|
+
# g.transaction("123456789", "1000.00", 'Acme Clothing', '1.29', '5.00', 'Los Angeles', 'California', 'USA')
|
217
|
+
#
|
127
218
|
def transaction(order_id, total, store_name = nil, tax = nil, shipping = nil, city = nil, region = nil, country = nil, utmhid = random_id)
|
128
219
|
check_account_params
|
129
220
|
hey(transaction_params(order_id, total, store_name, tax, shipping, city, region, country, utmhid))
|
130
221
|
end
|
131
222
|
|
223
|
+
# Public: Renders transaction params data in the format needed for GA
|
224
|
+
# Called before actually sending the data along to GA in Gabba#transaction
|
132
225
|
def transaction_params(order_id, total, store_name, tax, shipping, city, region, country, utmhid)
|
133
|
-
# '1234', // utmtid URL-encoded order ID - required
|
134
|
-
# 'Acme Clothing', // utmtst affiliation or store name
|
135
|
-
# '11.99', // utmtto total - required
|
136
|
-
# '1.29', // utmttx tax
|
137
|
-
# '5', // utmtsp shipping
|
138
|
-
# 'San Jose', // utmtci city
|
139
|
-
# 'California', // utmtrg state or province
|
140
|
-
# 'USA' // utmtco country
|
141
226
|
{
|
142
227
|
:utmwv => @utmwv,
|
143
228
|
:utmn => @utmn,
|
@@ -158,12 +243,16 @@ module Gabba
|
|
158
243
|
:utmtco => country
|
159
244
|
}
|
160
245
|
end
|
161
|
-
|
246
|
+
|
247
|
+
# Public: Track an item purchased in an ecommerce transaction to Google Analytics.
|
248
|
+
# (http://code.google.com/apis/analytics/docs/gaJS/gaJSApiEcommerce.html#_gat.GA_Tracker_._addItem)
|
162
249
|
def add_item(order_id, item_sku, price, quantity, name = nil, category = nil, utmhid = random_id)
|
163
250
|
check_account_params
|
164
251
|
hey(item_params(order_id, item_sku, name, category, price, quantity, utmhid))
|
165
252
|
end
|
166
|
-
|
253
|
+
|
254
|
+
# Public: Renders item purchase params data in the format needed for GA
|
255
|
+
# Called before actually sending the data along to GA in Gabba#add_item
|
167
256
|
def item_params(order_id, item_sku, name, category, price, quantity, utmhid)
|
168
257
|
# '1234', // utmtid URL-encoded order ID - required
|
169
258
|
# 'DD44', // utmipc SKU/code - required
|
@@ -189,10 +278,26 @@ module Gabba
|
|
189
278
|
:utmiqt => quantity
|
190
279
|
}
|
191
280
|
end
|
192
|
-
|
281
|
+
|
282
|
+
# Public: provide the user's __utma attribute from analytics cookie, allowing
|
283
|
+
# better tracking of user flows
|
284
|
+
#
|
285
|
+
# Called before page_view etc
|
286
|
+
#
|
287
|
+
# Examples:
|
288
|
+
# g = Gabba::Gabba.new("UT-1234", "mydomain.com")
|
289
|
+
# g.identify_user(cookies[:__utma])
|
290
|
+
# g.page_view("something", "track/me")
|
291
|
+
#
|
292
|
+
def identify_user(utma)
|
293
|
+
@utma = utma
|
294
|
+
end
|
295
|
+
|
193
296
|
# create magical cookie params used by GA for its own nefarious purposes
|
194
297
|
def cookie_params(utma1 = random_id, utma2 = rand(1147483647) + 1000000000, today = Time.now)
|
195
|
-
|
298
|
+
utma = @utma
|
299
|
+
utma ||= "1.#{utma1}00145214523.#{utma2}.#{today.to_i}.#{today.to_i}.15"
|
300
|
+
"__utma=#{utma};+__utmz=1.#{today.to_i}.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none);"
|
196
301
|
end
|
197
302
|
|
198
303
|
# sanity check that we have needed params to even call GA
|
@@ -219,15 +324,15 @@ module Gabba
|
|
219
324
|
def random_id
|
220
325
|
rand 8999999999 + 1000000000
|
221
326
|
end
|
222
|
-
|
327
|
+
|
223
328
|
def escape(t)
|
224
329
|
return t if !t || (/\w/ !~ t.to_s)
|
225
|
-
|
330
|
+
|
226
331
|
t.to_s.gsub(/[\*'!\)]/) do |m|
|
227
|
-
"'#{ESCAPES.index(m)}"
|
332
|
+
"'#{ESCAPES.index(m)}"
|
228
333
|
end
|
229
334
|
end
|
230
|
-
|
335
|
+
|
231
336
|
end # Gabba Class
|
232
337
|
|
233
338
|
end
|
data/lib/gabba/version.rb
CHANGED
data/spec/gabba_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
require File.dirname(__FILE__) +
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/spec_helper")
|
2
2
|
|
3
3
|
describe Gabba::Gabba do
|
4
|
-
|
4
|
+
|
5
5
|
describe "when tracking page views" do
|
6
6
|
before do
|
7
7
|
@gabba = Gabba::Gabba.new("abc", "123")
|
@@ -9,7 +9,7 @@ describe Gabba::Gabba do
|
|
9
9
|
@gabba.utmcc = ''
|
10
10
|
stub_analytics @gabba.page_view_params("title", "/page/path", "6783939397")
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
it "must require GA account" do
|
14
14
|
lambda {Gabba::Gabba.new(nil, nil).page_view("thing", "thing")}.must_raise(Gabba::NoGoogleAnalyticsAccountError)
|
15
15
|
end
|
@@ -17,7 +17,7 @@ describe Gabba::Gabba do
|
|
17
17
|
it "must require GA domain" do
|
18
18
|
lambda {Gabba::Gabba.new("abs", nil).page_view("thing", "thing")}.must_raise(Gabba::NoGoogleAnalyticsDomainError)
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
it "must be able to create page_view_params" do
|
22
22
|
@gabba.page_view_params("hiya", "/tracker/page")[:utmdt].must_equal("hiya")
|
23
23
|
end
|
@@ -34,7 +34,7 @@ describe Gabba::Gabba do
|
|
34
34
|
@gabba.utmcc = ''
|
35
35
|
stub_analytics @gabba.event_params("cat1", "act1", "lab1", "val1", false, "6783939397")
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
it "must require GA account" do
|
39
39
|
lambda {Gabba::Gabba.new(nil, nil).event("cat1", "act1", "lab1", "val1")}.must_raise(Gabba::NoGoogleAnalyticsAccountError)
|
40
40
|
end
|
@@ -42,7 +42,7 @@ describe Gabba::Gabba do
|
|
42
42
|
it "must require GA domain" do
|
43
43
|
lambda {Gabba::Gabba.new("abs", nil).event("cat1", "act1", "lab1", "val1")}.must_raise(Gabba::NoGoogleAnalyticsDomainError)
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
it "must be able to create event data" do
|
47
47
|
@gabba.event_data("cat1", "act1", "lab1", "val1").must_equal("5(cat1*act1*lab1)(val1)")
|
48
48
|
end
|
@@ -50,7 +50,7 @@ describe Gabba::Gabba do
|
|
50
50
|
it "must be able to create event data with only category and action" do
|
51
51
|
@gabba.event_data("cat1", "act1").must_equal("5(cat1*act1)")
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
it "must do event request to google" do
|
55
55
|
@gabba.event("cat1", "act1", "lab1", "val1", false, "6783939397").code.must_equal("200")
|
56
56
|
end
|
@@ -60,7 +60,7 @@ describe Gabba::Gabba do
|
|
60
60
|
end
|
61
61
|
|
62
62
|
end
|
63
|
-
|
63
|
+
|
64
64
|
describe "when tracking an item" do
|
65
65
|
before do
|
66
66
|
@gabba = Gabba::Gabba.new("abc", "123")
|
@@ -68,7 +68,7 @@ describe Gabba::Gabba do
|
|
68
68
|
@gabba.utmcc = ''
|
69
69
|
stub_analytics @gabba.item_params("orderid", "1234", "widget", "widgets", "9.99", "1", "6783939397")
|
70
70
|
end
|
71
|
-
|
71
|
+
|
72
72
|
it "must require GA account" do
|
73
73
|
lambda {Gabba::Gabba.new(nil, nil).add_item("orderid", "1234", "widget", "widgets", "9.99", "1", "6783939397")}.must_raise(Gabba::NoGoogleAnalyticsAccountError)
|
74
74
|
end
|
@@ -76,12 +76,12 @@ describe Gabba::Gabba do
|
|
76
76
|
it "must require GA domain" do
|
77
77
|
lambda {Gabba::Gabba.new("abs", nil).add_item("orderid", "1234", "widget", "widgets", "9.99", "1", "6783939397")}.must_raise(Gabba::NoGoogleAnalyticsDomainError)
|
78
78
|
end
|
79
|
-
|
79
|
+
|
80
80
|
it "must do add item request to google" do
|
81
81
|
@gabba.add_item("orderid", "1234", "widget", "widgets", "9.99", "1", "6783939397").code.must_equal("200")
|
82
82
|
end
|
83
83
|
end
|
84
|
-
|
84
|
+
|
85
85
|
describe "when tracking a transaction" do
|
86
86
|
before do
|
87
87
|
@gabba = Gabba::Gabba.new("abc", "123")
|
@@ -89,7 +89,7 @@ describe Gabba::Gabba do
|
|
89
89
|
@gabba.utmcc = ''
|
90
90
|
stub_analytics @gabba.transaction_params("orderid", "9.99", "acme stores", ".25", "1.00", "San Jose", "CA", "United States", "6783939397")
|
91
91
|
end
|
92
|
-
|
92
|
+
|
93
93
|
it "must require GA account" do
|
94
94
|
lambda {Gabba::Gabba.new(nil, nil).transaction("orderid", "9.99", "acme stores", ".25", "1.00", "San Jose", "CA", "United States", "6783939397")}.must_raise(Gabba::NoGoogleAnalyticsAccountError)
|
95
95
|
end
|
@@ -97,34 +97,48 @@ describe Gabba::Gabba do
|
|
97
97
|
it "must require GA domain" do
|
98
98
|
lambda {Gabba::Gabba.new("abs", nil).transaction("orderid", "9.99", "acme stores", ".25", "1.00", "San Jose", "CA", "United States", "6783939397")}.must_raise(Gabba::NoGoogleAnalyticsDomainError)
|
99
99
|
end
|
100
|
-
|
100
|
+
|
101
101
|
it "must do transaction request to google" do
|
102
102
|
@gabba.transaction("orderid", "9.99", "acme stores", ".25", "1.00", "San Jose", "CA", "United States", "6783939397").code.must_equal("200")
|
103
103
|
end
|
104
104
|
end
|
105
105
|
|
106
|
+
describe "when using identify_user" do
|
107
|
+
before do
|
108
|
+
@gabba = Gabba::Gabba.new("abc", "123")
|
109
|
+
@gabba.utmn = "1009731272"
|
110
|
+
@gabba.utmcc = ''
|
111
|
+
end
|
112
|
+
it "must use the supplied utma in cookie_params" do
|
113
|
+
# This is how the Google cookie is named
|
114
|
+
cookies = { :__utma => "long_code"}
|
115
|
+
@gabba.identify_user(cookies[:__utma])
|
116
|
+
@gabba.cookie_params.must_match /utma=long_code;/
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
106
120
|
describe "setting a custom var" do
|
107
121
|
before do
|
108
122
|
@gabba = Gabba::Gabba.new("abc", "123")
|
109
123
|
@gabba.utmn = "1009731272"
|
110
124
|
@gabba.utmcc = ''
|
111
125
|
end
|
112
|
-
|
126
|
+
|
113
127
|
it "must return data for a valid var" do
|
114
128
|
@gabba.set_custom_var 1, 'A (B*\'!)', 'Yes', Gabba::Gabba::SESSION
|
115
129
|
@gabba.custom_var_data.must_equal "8(A (B'2'0'1'3)9(Yes)11(2)"
|
116
130
|
end
|
117
|
-
|
131
|
+
|
118
132
|
it "must return data for several valid vards" do
|
119
133
|
@gabba.set_custom_var 1, 'A', 'Yes', Gabba::Gabba::SESSION
|
120
134
|
@gabba.set_custom_var 2, 'B', 'No', Gabba::Gabba::VISITOR
|
121
135
|
@gabba.custom_var_data.must_equal "8(A*B)9(Yes*No)11(2*1)"
|
122
136
|
end
|
123
|
-
|
137
|
+
|
124
138
|
it "must return an empty string if vars aren't set" do
|
125
139
|
@gabba.custom_var_data.must_equal ""
|
126
140
|
end
|
127
|
-
|
141
|
+
|
128
142
|
it "must not include var with an empty value" do
|
129
143
|
@gabba.set_custom_var 1, 'A', 'Yes', Gabba::Gabba::SESSION
|
130
144
|
@gabba.set_custom_var 2, 'B', '', Gabba::Gabba::VISITOR
|
@@ -132,18 +146,18 @@ describe Gabba::Gabba do
|
|
132
146
|
@gabba.set_custom_var 4, 'D', nil, Gabba::Gabba::VISITOR
|
133
147
|
@gabba.custom_var_data.must_equal "8(A)9(Yes)11(2)"
|
134
148
|
end
|
135
|
-
|
149
|
+
|
136
150
|
it "must mention index of the var if non sequential" do
|
137
151
|
@gabba.set_custom_var 2, 'A', 'Y', Gabba::Gabba::SESSION
|
138
152
|
@gabba.set_custom_var 4, 'D', 'N', Gabba::Gabba::VISITOR
|
139
153
|
@gabba.custom_var_data.must_equal "8(2!A*4!D)9(2!Y*4!N)11(2!2*4!1)"
|
140
154
|
end
|
141
|
-
|
155
|
+
|
142
156
|
it "must raise an error if index is outside the 1-5 (incl) range" do
|
143
157
|
lambda { @gabba.set_custom_var(0, 'A', 'B', 1) }.must_raise(RuntimeError)
|
144
158
|
lambda { @gabba.set_custom_var(6, 'A', 'B', 1) }.must_raise(RuntimeError)
|
145
159
|
end
|
146
|
-
|
160
|
+
|
147
161
|
it "must raise an error if scope is outside the 1-3 (incl) range" do
|
148
162
|
lambda { @gabba.set_custom_var(1, 'A', 'B', 0) }.must_raise(RuntimeError)
|
149
163
|
lambda { @gabba.set_custom_var(1, 'A', 'B', 4) }.must_raise(RuntimeError)
|
@@ -156,14 +170,14 @@ describe Gabba::Gabba do
|
|
156
170
|
@gabba.utmn = "1009731272"
|
157
171
|
@gabba.utmcc = ''
|
158
172
|
end
|
159
|
-
|
173
|
+
|
160
174
|
it "must return data for a valid var" do
|
161
175
|
@gabba.set_custom_var 1, 'A (B*\'!)', 'Yes', Gabba::Gabba::SESSION
|
162
176
|
@gabba.delete_custom_var 1
|
163
177
|
@gabba.custom_var_data.must_equal ""
|
164
178
|
end
|
165
179
|
end
|
166
|
-
|
180
|
+
|
167
181
|
def stub_analytics(expected_params)
|
168
182
|
s = stub_request(:get, /www.google-analytics.com\/__utm.gif\?utmac=#{expected_params[:utmac]}&.*/).
|
169
183
|
to_return(:status => 200, :body => "", :headers => {})
|
metadata
CHANGED
@@ -1,33 +1,23 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: gabba
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 2
|
9
|
-
- 0
|
10
|
-
version: 0.2.0
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Ron Evans
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
date: 2012-03-23 00:00:00 Z
|
12
|
+
date: 2012-04-02 00:00:00.000000000Z
|
19
13
|
dependencies: []
|
20
|
-
|
21
14
|
description: Easy server-side tracking for Google Analytics
|
22
|
-
email:
|
15
|
+
email:
|
23
16
|
- ron dot evans at gmail dot com
|
24
17
|
executables: []
|
25
|
-
|
26
18
|
extensions: []
|
27
|
-
|
28
19
|
extra_rdoc_files: []
|
29
|
-
|
30
|
-
files:
|
20
|
+
files:
|
31
21
|
- .gitignore
|
32
22
|
- Gemfile
|
33
23
|
- Gemfile.lock
|
@@ -39,39 +29,30 @@ files:
|
|
39
29
|
- lib/gabba/version.rb
|
40
30
|
- spec/gabba_spec.rb
|
41
31
|
- spec/spec_helper.rb
|
42
|
-
homepage:
|
32
|
+
homepage: ''
|
43
33
|
licenses: []
|
44
|
-
|
45
34
|
post_install_message:
|
46
35
|
rdoc_options: []
|
47
|
-
|
48
|
-
require_paths:
|
36
|
+
require_paths:
|
49
37
|
- lib
|
50
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
39
|
none: false
|
52
|
-
requirements:
|
53
|
-
- -
|
54
|
-
- !ruby/object:Gem::Version
|
55
|
-
|
56
|
-
|
57
|
-
- 0
|
58
|
-
version: "0"
|
59
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
45
|
none: false
|
61
|
-
requirements:
|
62
|
-
- -
|
63
|
-
- !ruby/object:Gem::Version
|
64
|
-
|
65
|
-
segments:
|
66
|
-
- 0
|
67
|
-
version: "0"
|
46
|
+
requirements:
|
47
|
+
- - ! '>='
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
68
50
|
requirements: []
|
69
|
-
|
70
51
|
rubyforge_project: gabba
|
71
52
|
rubygems_version: 1.8.6
|
72
53
|
signing_key:
|
73
54
|
specification_version: 3
|
74
55
|
summary: Easy server-side tracking for Google Analytics
|
75
|
-
test_files:
|
56
|
+
test_files:
|
76
57
|
- spec/gabba_spec.rb
|
77
58
|
- spec/spec_helper.rb
|