gabba 0.4.2 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -3,5 +3,6 @@ source "http://rubygems.org"
3
3
  # Specify your gem's dependencies in gabba.gemspec
4
4
  gemspec
5
5
 
6
+ gem 'rake'
6
7
  gem 'minitest'
7
8
  gem 'webmock'
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gabba (0.4.2)
4
+ gabba (1.0.1)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -9,6 +9,7 @@ GEM
9
9
  addressable (2.2.2)
10
10
  crack (0.1.8)
11
11
  minitest (2.0.0)
12
+ rake (0.9.2.2)
12
13
  webmock (1.6.1)
13
14
  addressable (>= 2.2.2)
14
15
  crack (>= 0.1.7)
@@ -19,4 +20,5 @@ PLATFORMS
19
20
  DEPENDENCIES
20
21
  gabba!
21
22
  minitest
23
+ rake
22
24
  webmock
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.authors = ["Ron Evans"]
10
10
  s.email = ["ron dot evans at gmail dot com"]
11
- s.homepage = ""
11
+ s.homepage = "https://github.com/hybridgroup/gabba"
12
12
  s.summary = %q{Easy server-side tracking for Google Analytics}
13
13
  s.description = %q{Easy server-side tracking for Google Analytics}
14
14
 
@@ -1,6 +1,7 @@
1
1
  # yo, easy server-side tracking for Google Analytics... hey!
2
- require "uri"
3
- require "net/http"
2
+ require 'uri'
3
+ require 'net/http'
4
+ require 'ipaddr'
4
5
  require 'cgi'
5
6
  require File.dirname(__FILE__) + '/version'
6
7
 
@@ -22,7 +23,7 @@ module Gabba
22
23
 
23
24
  ESCAPES = %w{ ' ! * ) }
24
25
 
25
- attr_accessor :utmwv, :utmn, :utmhn, :utmcs, :utmul, :utmdt, :utmp, :utmac, :utmt, :utmcc, :user_agent, :utma, :utmz
26
+ attr_accessor :utmwv, :utmn, :utmhn, :utmcs, :utmul, :utmdt, :utmp, :utmac, :utmt, :utmcc, :user_agent, :utma, :utmz, :utmr, :utmip
26
27
 
27
28
  # Public: Initialize Gabba Google Analytics Tracking Object.
28
29
  #
@@ -45,7 +46,7 @@ module Gabba
45
46
 
46
47
  @utmac = ga_acct
47
48
  @utmhn = domain
48
- @user_agent = agent
49
+ @user_agent = (agent && agent.length > 0) ? agent : Gabba::USER_AGENT
49
50
 
50
51
  @custom_vars = []
51
52
  end
@@ -137,7 +138,9 @@ module Gabba
137
138
  :utmhid => utmhid,
138
139
  :utmp => page,
139
140
  :utmac => @utmac,
140
- :utmcc => @utmcc || cookie_params
141
+ :utmcc => @utmcc || cookie_params,
142
+ :utmr => @utmr,
143
+ :utmip => @utmip
141
144
  }
142
145
 
143
146
  # Add custom vars if present
@@ -182,7 +185,9 @@ module Gabba
182
185
  :utmul => @utmul,
183
186
  :utmhid => utmhid,
184
187
  :utmac => @utmac,
185
- :utmcc => @utmcc || cookie_params
188
+ :utmcc => @utmcc || cookie_params,
189
+ :utmr => @utmr,
190
+ :utmip => @utmip
186
191
  }
187
192
  end
188
193
 
@@ -240,7 +245,9 @@ module Gabba
240
245
  :utmtsp => shipping,
241
246
  :utmtci => city,
242
247
  :utmtrg => region,
243
- :utmtco => country
248
+ :utmtco => country,
249
+ :utmr => @utmr,
250
+ :utmip => @utmip
244
251
  }
245
252
  end
246
253
 
@@ -275,7 +282,9 @@ module Gabba
275
282
  :utmipn => name,
276
283
  :utmiva => category,
277
284
  :utmipr => price,
278
- :utmiqt => quantity
285
+ :utmiqt => quantity,
286
+ :utmr => @utmr,
287
+ :utmip => @utmip
279
288
  }
280
289
  end
281
290
 
@@ -292,6 +301,35 @@ module Gabba
292
301
  def identify_user(utma, utmz=nil)
293
302
  @utma = utma
294
303
  @utmz = utmz
304
+ self
305
+ end
306
+
307
+ # Public: provide the utmr attribute, allowing for referral tracking
308
+ #
309
+ # Called before page_view etc
310
+ #
311
+ # Examples:
312
+ # g = Gabba::Gabba.new("UT-1234", "mydomain.com")
313
+ # g.referer(request.env['HTTP_REFERER'])
314
+ # g.page_view("something", "track/me")
315
+ #
316
+ def referer(utmr)
317
+ @utmr = utmr
318
+ self
319
+ end
320
+
321
+ # Public: provide the utmip attribute, allowing for IP address tracking
322
+ #
323
+ # Called before page_view etc
324
+ #
325
+ # Examples:
326
+ # g = Gabba::Gabba.new("UT-1234", "mydomain.com")
327
+ # g.ip(request.env["REMOTE_ADDR"])
328
+ # g.page_view("something", "track/me")
329
+ #
330
+ def ip(utmip)
331
+ @utmip = ::IPAddr.new(utmip).mask(24).to_s
332
+ self
295
333
  end
296
334
 
297
335
  # create magical cookie params used by GA for its own nefarious purposes
@@ -1,5 +1,5 @@
1
1
  module Gabba
2
2
  unless const_defined?('VERSION')
3
- VERSION = "0.4.2"
3
+ VERSION = "1.0.1"
4
4
  end
5
5
  end
@@ -25,6 +25,18 @@ describe Gabba::Gabba do
25
25
  it "must do page view request to google" do
26
26
  @gabba.page_view("title", "/page/path", "6783939397").code.must_equal("200")
27
27
  end
28
+
29
+ it "should use Gabba user agent if none is specified" do
30
+ @gabba.user_agent.must_equal(Gabba::Gabba::USER_AGENT)
31
+ end
32
+
33
+ it "should use Gabba user agent if nil is specified" do
34
+ Gabba::Gabba.new("abc","123",nil).user_agent.must_equal(Gabba::Gabba::USER_AGENT)
35
+ end
36
+
37
+ it "should use Gabba user agent if blank is specified" do
38
+ Gabba::Gabba.new("abc","123","").user_agent.must_equal(Gabba::Gabba::USER_AGENT)
39
+ end
28
40
  end
29
41
 
30
42
  describe "when tracking custom events" do
@@ -124,6 +136,47 @@ describe Gabba::Gabba do
124
136
  end
125
137
  end
126
138
 
139
+ describe "when using referer" do
140
+ referer = "http://www.someurl.com/blah/blah"
141
+ before do
142
+ @gabba = Gabba::Gabba.new("abc", "123")
143
+ @gabba.referer(referer)
144
+ end
145
+ it "must use the specified referer in page_view_params" do
146
+ @gabba.page_view_params("whocares","doesntmatter")[:utmr].must_equal(referer)
147
+ end
148
+ it "must use the specified referer in event_params" do
149
+ @gabba.event_params("whocares","doesntmatter")[:utmr].must_equal(referer)
150
+ end
151
+ it "must use the specified referer in transaction_params" do
152
+ @gabba.transaction_params('order_id', 'total', 'store_name', 'tax', 'shipping', 'city', 'region', 'country', 'utmhid')[:utmr].must_equal(referer)
153
+ end
154
+ it "must use the specified referer in item_params" do
155
+ @gabba.item_params('order_id', 'item_sku', 'name', 'category', 'price', 'quantity', 'utmhid')[:utmr].must_equal(referer)
156
+ end
157
+ end
158
+
159
+ describe "when using ip" do
160
+ ip = "123.123.123.123"
161
+ masked_ip = "123.123.123.0"
162
+ before do
163
+ @gabba = Gabba::Gabba.new("abc", "123")
164
+ @gabba.ip(ip)
165
+ end
166
+ it "must use the specified referer in page_view_params" do
167
+ @gabba.page_view_params("whocares","doesntmatter")[:utmip].must_equal(masked_ip)
168
+ end
169
+ it "must use the specified referer in event_params" do
170
+ @gabba.event_params("whocares","doesntmatter")[:utmip].must_equal(masked_ip)
171
+ end
172
+ it "must use the specified referer in transaction_params" do
173
+ @gabba.transaction_params('order_id', 'total', 'store_name', 'tax', 'shipping', 'city', 'region', 'country', 'utmhid')[:utmip].must_equal(masked_ip)
174
+ end
175
+ it "must use the specified referer in item_params" do
176
+ @gabba.item_params('order_id', 'item_sku', 'name', 'category', 'price', 'quantity', 'utmhid')[:utmip].must_equal(masked_ip)
177
+ end
178
+ end
179
+
127
180
  describe "setting a custom var" do
128
181
  before do
129
182
  @gabba = Gabba::Gabba.new("abc", "123")
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
- hash: 11
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 4
9
- - 2
10
- version: 0.4.2
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-10-20 00:00:00 Z
12
+ date: 2012-11-08 00:00:00.000000000 Z
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,36 @@ files:
39
29
  - lib/gabba/version.rb
40
30
  - spec/gabba_spec.rb
41
31
  - spec/spec_helper.rb
42
- homepage: ""
32
+ homepage: https://github.com/hybridgroup/gabba
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
- hash: 3
56
- segments:
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ segments:
57
45
  - 0
58
- version: "0"
59
- required_rubygems_version: !ruby/object:Gem::Requirement
46
+ hash: -242928597146007543
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
48
  none: false
61
- requirements:
62
- - - ">="
63
- - !ruby/object:Gem::Version
64
- hash: 3
65
- segments:
49
+ requirements:
50
+ - - ! '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ segments:
66
54
  - 0
67
- version: "0"
55
+ hash: -242928597146007543
68
56
  requirements: []
69
-
70
57
  rubyforge_project: gabba
71
58
  rubygems_version: 1.8.24
72
59
  signing_key:
73
60
  specification_version: 3
74
61
  summary: Easy server-side tracking for Google Analytics
75
- test_files:
62
+ test_files:
76
63
  - spec/gabba_spec.rb
77
64
  - spec/spec_helper.rb