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 +8 -8
- data/README.md +10 -1
- data/lib/staccato/rack.rb +11 -6
- data/lib/staccato/rack/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZjlmYTEyODk5YWM2NWVhYjMxMGViZjRkMDY4MTZlMjNjYmQzZGRjYw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
Yzg1YWQyODM4YmRhOThjMTFhODhjY2IyNWZjMzVmNzdkOWMxMzdmNw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZGQxZTc2MjQwNzNiMzMzZmQ0OTNlNWIxMTU4Y2ExODhlN2EzOTgzNzAyNGJj
|
10
|
+
YjA4ODg3YTQ3MTFiMmViMjc0ODVjNTcxNTMyODg4Mzk5MmM4MThmZmVlYWNk
|
11
|
+
MTJiNjk5MmU0YThmNTcyYWIxZWQzYTg3MGJlZjU0Y2ZlNDU3NDc=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
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'
|
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.
|
data/lib/staccato/rack.rb
CHANGED
@@ -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,
|
37
|
-
|
38
|
-
|
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
|
-
|
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)
|