staccato-rack 0.3.1 → 0.3.2

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,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MzA4MWM1MTMwNzkxMjRkZDg0Njk5ODE3ZmMwNTk5NjI1OTc4ZWNiZQ==
4
+ ZjlmYTEyODk5YWM2NWVhYjMxMGViZjRkMDY4MTZlMjNjYmQzZGRjYw==
5
5
  data.tar.gz: !binary |-
6
- NjZmMmYzMmE0YWM3ZmJjYjYzN2I5MjM2NzE4YjY4ZjczODEzOGU2NQ==
6
+ Yzg1YWQyODM4YmRhOThjMTFhODhjY2IyNWZjMzVmNzdkOWMxMzdmNw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- Y2NmODRlYzAwMGVjODVmN2JiZTFjYjNkMDhiNmJjZTk2YmM3ZWFhNTc3ZjMz
10
- ZjU0Y2Q2YzBkMjkxMzhiZTMyYmQ2Nzc3NjlkN2RkMjQzOTFkMGM5YWEwNDk2
11
- MTZkNjdhNTZlNDE2ZWJlNjVjODI0YTljYmJhOTVkNDU3Yzg4MDc=
9
+ ZGQxZTc2MjQwNzNiMzMzZmQ0OTNlNWIxMTU4Y2ExODhlN2EzOTgzNzAyNGJj
10
+ YjA4ODg3YTQ3MTFiMmViMjc0ODVjNTcxNTMyODg4Mzk5MmM4MThmZmVlYWNk
11
+ MTJiNjk5MmU0YThmNTcyYWIxZWQzYTg3MGJlZjU0Y2ZlNDU3NDc=
12
12
  data.tar.gz: !binary |-
13
- MzAwMDk3MWIzM2E2Y2RjZDZkZjQyZDVmOGE3YTFmOWQ0N2ViZDlmMTM1ZjZj
14
- MWZiMWE2YzQ1YzgzNDllY2E3ZmI3N2NjN2QxMWU3OWI5YzE2NjY4M2FkMjE5
15
- ZjY4NjM4OTRhZWU1YmIxMTgzMTY5ZTY4NmYzM2MzNmVkNjQ0N2Q=
13
+ M2ZiNjg4ZmRmZjY3ZDA2Y2E0ZjNlMWFmMWQ3NjEyNmNmNTY5OWQ2MWIzMmMx
14
+ NjA4NjdlNDgzMThjZTEzNDIzOTFmMTEyY2E4ODZjNjMzODhlYzgwYThmZDI0
15
+ ZGFmM2RlYmFkZDRkNTVhNDQwNmExNjYwZjAyY2EzNzgwNmE4ODk=
data/README.md CHANGED
@@ -27,8 +27,17 @@ using in middleware:
27
27
  using in your Rails application, add the following line to your application config file (`config/application.rb` for Rails 3 and above, `config/environment.rb` for Rails 2):
28
28
 
29
29
  ```ruby
30
- config.middleware.use Staccato::Rack::Middleware, 'UA-TRACKING-KEY-HERE', logger: Rails.logger
30
+ config.middleware.use Staccato::Rack::Middleware, 'UA-TRACKING-KEY-HERE'
31
31
  ```
32
+
33
+ if you want logging in rails add a initializers file with the following
34
+
35
+ ```ruby
36
+ ContikiApi::Application.configure do
37
+ config.middleware.use Staccato::Rack::Middleware, Rails.application.secrets.ga_tracking_id, logger: Rails.logger
38
+ end
39
+ ```
40
+
32
41
  ## Development
33
42
 
34
43
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -5,6 +5,7 @@ require 'ostruct'
5
5
 
6
6
  module Staccato
7
7
  module Rack
8
+ # Proxy Class to do page views
8
9
  class PageView < OpenStruct
9
10
  def initialize
10
11
  super
@@ -33,13 +34,12 @@ module Staccato
33
34
  private
34
35
 
35
36
  def track_hit(tracker, page_view_params, request)
36
- hit = Staccato::Pageview.new(tracker, page_view_params.merge(path: request.fullpath,
37
- hostname: request.host,
38
- user_agent: request.env['HTTP_USER_AGENT'],
39
- user_ip: request.ip))
37
+ hit = Staccato::Pageview.new(tracker, { path: request.fullpath,
38
+ user_agent: request.env['HTTP_USER_AGENT'],
39
+ user_ip: request.ip }.merge(page_view_params))
40
40
  add_custom_to_hit(hit)
41
41
  r = hit.track!
42
- logger.info "GA Tracking: #{hit.params.inspect} => #{r.response.code if r}"
42
+ log_response(r, hit)
43
43
  hit
44
44
  end
45
45
 
@@ -51,8 +51,13 @@ module Staccato
51
51
  hit.add_custom_dimension(p, v)
52
52
  end
53
53
  end
54
+
55
+ def log_response(r, hit)
56
+ logger.info "GA Tracking: #{hit.params.inspect} => #{r.response.code if r}"
57
+ end
54
58
  end
55
59
 
60
+ # Null Logger clas
56
61
  class NullLogger
57
62
  def info(*)
58
63
  end
@@ -72,7 +77,7 @@ module Staccato
72
77
  end
73
78
 
74
79
  def call(env)
75
- env['staccato.pageview'] = PageView.new.tap{|p| p.logger = @logger }
80
+ env['staccato.pageview'] = PageView.new.tap { |p| p.logger = @logger }
76
81
 
77
82
  @last_hit = nil
78
83
  status, headers, body = @app.call(env)
@@ -2,6 +2,6 @@
2
2
  module Staccato
3
3
  # rack module
4
4
  module Rack
5
- VERSION = '0.3.1'
5
+ VERSION = '0.3.2'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: staccato-rack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Grant Speelman