gabba 0.3.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gabba (0.2.0)
4
+ gabba (0.4.1)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
data/Rakefile CHANGED
@@ -3,6 +3,8 @@ Bundler::GemHelper.install_tasks
3
3
 
4
4
  task :default => :spec
5
5
 
6
+ task :test => :spec
7
+
6
8
  task :spec do
7
9
  ruby "spec/gabba_spec.rb"
8
10
  end
@@ -0,0 +1,67 @@
1
+ # Gabba
2
+
3
+ Simple class to send custom server-side events to Google Analytics
4
+
5
+ Heavily influenced by the http://code.google.com/p/serversidegoogleanalytics
6
+
7
+ ## Examples
8
+
9
+ ### Track page views
10
+
11
+ ```ruby
12
+ Gabba::Gabba.new("UT-1234", "mydomain.com").page_view("something", "track/me")
13
+ ```
14
+
15
+ ### Track custom events
16
+
17
+ ```ruby
18
+ Gabba::Gabba.new("UT-1234", "mydomain.com").event("Videos", "Play", "ID", "123", true)
19
+ ```
20
+
21
+ ### Works with existing client-side Google Analytics cookies
22
+
23
+ ```ruby
24
+ gabba = Gabba::Gabba.new("UT-1234", "mydomain.com")
25
+
26
+ # grab the __utma and (optionally) __utmz unique identifiers
27
+ gabba.identify_user(cookies[:__utma], cookies[:__utmz])
28
+
29
+ # trigger actions as normal
30
+ gabba.page_view("something", "track/me")
31
+ ```
32
+
33
+ ### Setting custom vars
34
+
35
+ ```ruby
36
+ # Index: 1 through 5
37
+ index = 1
38
+
39
+ # Scope: VISITOR, SESSION or PAGE
40
+ scope = Gabba::Gabba::VISITOR
41
+
42
+ # Set var
43
+ gabba.set_custom_var(index, 'Name', 'Value', scope)
44
+
45
+ # Track the event (all vars will be included)
46
+ gabba.event(...)
47
+
48
+ # Track the page view (all vars will be included)
49
+ gabba.page_view(...)
50
+ ```
51
+
52
+ ### Removing custom vars
53
+
54
+ ```ruby
55
+ # Index: 1 through 5
56
+ index = 1
57
+
58
+ # Delete var with this index
59
+ gabba.delete_custom_var index
60
+ ```
61
+
62
+ ### Track ecommerce transactions
63
+
64
+ ```ruby
65
+ g = Gabba::Gabba.new("UT-6666", "myawesomeshop.net")
66
+ g.transaction("123456789", "1000.00", 'Acme Clothing', '1.29', '5.00', 'Los Angeles', 'California', 'USA')
67
+ ```
@@ -22,7 +22,7 @@ module Gabba
22
22
 
23
23
  ESCAPES = %w{ ' ! * ) }
24
24
 
25
- attr_accessor :utmwv, :utmn, :utmhn, :utmcs, :utmul, :utmdt, :utmp, :utmac, :utmt, :utmcc, :user_agent
25
+ attr_accessor :utmwv, :utmn, :utmhn, :utmcs, :utmul, :utmdt, :utmp, :utmac, :utmt, :utmcc, :user_agent, :utma, :utmz
26
26
 
27
27
  # Public: Initialize Gabba Google Analytics Tracking Object.
28
28
  #
@@ -279,25 +279,26 @@ module Gabba
279
279
  }
280
280
  end
281
281
 
282
- # Public: provide the user's __utma attribute from analytics cookie, allowing
282
+ # Public: provide the user's __utma and __utmz attributes from analytics cookie, allowing
283
283
  # better tracking of user flows
284
284
  #
285
285
  # Called before page_view etc
286
286
  #
287
287
  # Examples:
288
288
  # g = Gabba::Gabba.new("UT-1234", "mydomain.com")
289
- # g.identify_user(cookies[:__utma])
289
+ # g.identify_user(cookies[:__utma], cookies[:__utmz])
290
290
  # g.page_view("something", "track/me")
291
291
  #
292
- def identify_user(utma)
292
+ def identify_user(utma, utmz=nil)
293
293
  @utma = utma
294
+ @utmz = utmz
294
295
  end
295
296
 
296
297
  # create magical cookie params used by GA for its own nefarious purposes
297
298
  def cookie_params(utma1 = random_id, utma2 = rand(1147483647) + 1000000000, today = Time.now)
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);"
299
+ @utma ||= "1.#{utma1}00145214523.#{utma2}.#{today.to_i}.#{today.to_i}.15"
300
+ @utmz ||= "1.#{today.to_i}.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)"
301
+ "__utma=#{@utma};+__utmz=#{@utmz};"
301
302
  end
302
303
 
303
304
  # sanity check that we have needed params to even call GA
@@ -1,5 +1,5 @@
1
1
  module Gabba
2
2
  unless const_defined?('VERSION')
3
- VERSION = "0.3.0"
3
+ VERSION = "0.4.1"
4
4
  end
5
5
  end
@@ -113,7 +113,14 @@ describe Gabba::Gabba do
113
113
  # This is how the Google cookie is named
114
114
  cookies = { :__utma => "long_code"}
115
115
  @gabba.identify_user(cookies[:__utma])
116
- @gabba.cookie_params.must_match /utma=long_code;/
116
+ @gabba.cookie_params.must_match(/utma=long_code;/)
117
+ @gabba.cookie_params.must_match(/utmz=.*direct.*;/)
118
+ end
119
+ it "must use the optionally supplied utmz in cookie_params" do
120
+ cookies = { :__utma => "long_code", :__utmz => "utmz_code" }
121
+ @gabba.identify_user(cookies[:__utma], cookies[:__utmz])
122
+ @gabba.cookie_params.must_match(/utma=long_code;/)
123
+ @gabba.cookie_params.must_match(/utmz=utmz_code;/)
117
124
  end
118
125
  end
119
126
 
metadata CHANGED
@@ -1,58 +1,77 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: gabba
3
- version: !ruby/object:Gem::Version
4
- version: 0.3.0
3
+ version: !ruby/object:Gem::Version
4
+ hash: 13
5
5
  prerelease:
6
+ segments:
7
+ - 0
8
+ - 4
9
+ - 1
10
+ version: 0.4.1
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - Ron Evans
9
14
  autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
- date: 2012-04-02 00:00:00.000000000Z
17
+
18
+ date: 2012-10-20 00:00:00 Z
13
19
  dependencies: []
20
+
14
21
  description: Easy server-side tracking for Google Analytics
15
- email:
22
+ email:
16
23
  - ron dot evans at gmail dot com
17
24
  executables: []
25
+
18
26
  extensions: []
27
+
19
28
  extra_rdoc_files: []
20
- files:
29
+
30
+ files:
21
31
  - .gitignore
22
32
  - Gemfile
23
33
  - Gemfile.lock
24
- - README
25
34
  - Rakefile
35
+ - Readme.md
26
36
  - gabba.gemspec
27
37
  - lib/gabba.rb
28
38
  - lib/gabba/gabba.rb
29
39
  - lib/gabba/version.rb
30
40
  - spec/gabba_spec.rb
31
41
  - spec/spec_helper.rb
32
- homepage: ''
42
+ homepage: ""
33
43
  licenses: []
44
+
34
45
  post_install_message:
35
46
  rdoc_options: []
36
- require_paths:
47
+
48
+ require_paths:
37
49
  - lib
38
- required_ruby_version: !ruby/object:Gem::Requirement
50
+ required_ruby_version: !ruby/object:Gem::Requirement
39
51
  none: false
40
- requirements:
41
- - - ! '>='
42
- - !ruby/object:Gem::Version
43
- version: '0'
44
- required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ hash: 3
56
+ segments:
57
+ - 0
58
+ version: "0"
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
60
  none: false
46
- requirements:
47
- - - ! '>='
48
- - !ruby/object:Gem::Version
49
- version: '0'
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ hash: 3
65
+ segments:
66
+ - 0
67
+ version: "0"
50
68
  requirements: []
69
+
51
70
  rubyforge_project: gabba
52
- rubygems_version: 1.8.6
71
+ rubygems_version: 1.8.24
53
72
  signing_key:
54
73
  specification_version: 3
55
74
  summary: Easy server-side tracking for Google Analytics
56
- test_files:
75
+ test_files:
57
76
  - spec/gabba_spec.rb
58
77
  - spec/spec_helper.rb
data/README DELETED
@@ -1,56 +0,0 @@
1
- Simple class to send custom server-side events to Google Analytics
2
- ==================================================================
3
-
4
- Heavily influenced by the http://code.google.com/p/serversidegoogleanalytics
5
-
6
- HOW TO USE:
7
- -----------
8
-
9
- * Track page views
10
-
11
- Gabba::Gabba.new("UT-1234", "mydomain.com").page_view("something", "track/me")
12
-
13
- * Track custom events
14
-
15
- Gabba::Gabba.new("UT-1234", "mydomain.com").event("Videos", "Play", "ID", "123", true)
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
-
27
- * Setting custom vars
28
-
29
- # Index: 1 through 5
30
- index = 1
31
-
32
- # Scope: VISITOR, SESSION or PAGE
33
- scope = Gabba::Gabba::VISITOR
34
-
35
- # Set var
36
- gabba.set_custom_var(index, 'Name', 'Value', scope)
37
-
38
- # Track the event (all vars will be included)
39
- gabba.event(...)
40
-
41
- # Track the page view (all vars will be included)
42
- gabba.page_view(...)
43
-
44
- * Removing custom vars
45
-
46
- # Index: 1 through 5
47
- index = 1
48
-
49
- # Delete var with this index
50
- gabba.delete_custom_var index- Track a non-interactive custom event
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
-