staccato-rails 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 79453c5e3437d648aabe2a13cd116db0ba2073ea
4
- data.tar.gz: c163d245693375382faf05e44dee976c1bafc013
3
+ metadata.gz: c5ffa71cc4564ecb6712bdcc9afb3aef2ea095d4
4
+ data.tar.gz: 7d60616ef0a17d347d288951f0831cb03ae9948e
5
5
  SHA512:
6
- metadata.gz: c221d044d4d9656d4be4b0ac6500b691533a2c9c8ee177ef4717737ac4f0358a5a0709c586d51a7eaa9e847ea277ddcfd999005c8b382ea63c57535d57f4ed29
7
- data.tar.gz: abb48affccf27c06d39982439de6ad5ef9e42686a6f3cfaeaf1bdb1be78f95512f9c514fb655c721cbdf29c0de6548b982f1fa27c435c836b61c00a30ce5e0a0
6
+ metadata.gz: ea22eab05dfbc4d2992bd90a90c1115d87d0d4c28d885d883c729d9314f000c43da395bb96ab2befddab82d129d2f5c754444657169730ae31c371ec177955e1
7
+ data.tar.gz: f91310fce5330337318e41d55e49cd51b83bf03c018b5e5b72a821da0e9c11a021eae761d3c2a2b790ab3ad1227629587510ff944695b9e668d193ad4b0c06c2
@@ -1 +1 @@
1
- 2.3.0
1
+ 2.4
@@ -1,3 +1,9 @@
1
+ ## Staccato-Rails 0.1.0 ##
2
+
3
+ * Support the addition of details into the hit via `global_context` and `hit_context`
4
+
5
+ *Tony Pitale <@tpitale>*
6
+
1
7
  ## Staccato-Rails 0.0.1 ##
2
8
 
3
9
  * Initial implementation
data/README.md CHANGED
@@ -49,6 +49,8 @@ In controllers, `tracker` is made available to you:
49
49
  tracker.event(category: 'video', action: 'play', label: 'cars', value: 1)
50
50
  ```
51
51
 
52
+ Note: if you have an existing method named `tracker`, this is also available with the more verbose `staccato_tracker`.
53
+
52
54
  ## Overriding the client_id ##
53
55
 
54
56
  A method is added to your controller called `staccato_client_id`. By default, it's implementation looks like:
@@ -83,6 +85,30 @@ config.staccato.pageviews = false
83
85
  config.staccato.exceptions = false # default
84
86
  ```
85
87
 
88
+ ## Adding Global and Hit context ##
89
+
90
+ To add values like `user_ip` to all hits called by `tracker` (in both your own code, and staccato-rails) create a method `global_context` in your controller and return a hash:
91
+
92
+ ```ruby
93
+ def global_context
94
+ {
95
+ user_ip: request.remote_ip
96
+ }
97
+ end
98
+ ```
99
+
100
+ To add values only to the hits sent by staccato-rails (but not your own use of `tracker`) for pageviews and timing create a method `hit_context` in your controller and return a hash:
101
+
102
+ ```ruby
103
+ def hit_context
104
+ {
105
+ user_agent: "cURL"
106
+ }
107
+ end
108
+ ```
109
+
110
+ If per-action control over the hits sent to GA is required you're better off just using `Staccato` directly at this point.
111
+
86
112
  ## Contributing
87
113
 
88
114
  1. Fork it
@@ -1,4 +1,4 @@
1
1
  # Do not use this module for anything but version
2
2
  module StaccatoRails
3
- VERSION = '0.0.1'
3
+ VERSION = '0.1.0'
4
4
  end
@@ -1,7 +1,21 @@
1
1
  module Staccato
2
2
  module SessionTracking
3
- def tracker
4
- @tracker ||= Staccato.tracker(staccato_tracker_id, staccato_client_id)
3
+ def self.included(controller)
4
+ controller.class_eval do
5
+ alias_method :tracker, :staccato_tracker unless defined?(tracker)
6
+ end
7
+ end
8
+
9
+ def global_context
10
+ {}
11
+ end
12
+
13
+ def hit_context
14
+ {}
15
+ end
16
+
17
+ def staccato_tracker
18
+ @staccato_tracker ||= Staccato.tracker(staccato_tracker_id, staccato_client_id, global_context)
5
19
  end
6
20
 
7
21
  # pull tracker id from config
@@ -14,10 +28,13 @@ module Staccato
14
28
  session['staccato.client_id'] ||= Staccato.build_client_id
15
29
  end
16
30
 
31
+ # This is called in an `ensure` block by actionpack
32
+ # errors raised here _may_ be particularly dangerous
17
33
  def append_info_to_payload(payload)
18
34
  super
19
35
 
20
- payload["staccato.tracker"] = tracker
36
+ payload["staccato.tracker"] = staccato_tracker
37
+ payload["staccato.context"] = hit_context
21
38
  end
22
39
  end
23
40
  end
@@ -23,7 +23,7 @@ module Staccato
23
23
 
24
24
  def track!
25
25
  return unless get?
26
- tracker.pageview(path: path, hostname: hostname)
26
+ tracker.pageview(context.merge(path: path, hostname: hostname))
27
27
  end
28
28
 
29
29
  private
@@ -39,6 +39,10 @@ module Staccato
39
39
  @tracker ||= payload['staccato.tracker']
40
40
  end
41
41
 
42
+ def context
43
+ @context ||= payload['staccato.context']
44
+ end
45
+
42
46
  def path_prefix
43
47
  Rails.application.config.staccato.pageview_prefix.to_s
44
48
  end
@@ -21,10 +21,20 @@ module Staccato
21
21
  @view_runtime ||= payload[:view_runtime]
22
22
  end
23
23
 
24
+ def times
25
+ [
26
+ {label: :total, time: total_runtime},
27
+ {label: :db, time: db_runtime},
28
+ {label: :view, time: view_runtime}
29
+ ]
30
+ end
31
+
24
32
  def track!
25
- tracker.timing(category: :rails, variable: :runtime, label: :total, time: total_runtime)
26
- tracker.timing(category: :rails, variable: :runtime, label: :db, time: db_runtime)
27
- tracker.timing(category: :rails, variable: :runtime, label: :view, time: view_runtime)
33
+ params = context.merge(category: :rails, variable: :runtime)
34
+
35
+ times.each do |time|
36
+ tracker.timing(params.merge(time))
37
+ end
28
38
  end
29
39
 
30
40
  private
@@ -39,6 +49,10 @@ module Staccato
39
49
  def tracker
40
50
  @tracker ||= payload['staccato.tracker']
41
51
  end
52
+
53
+ def context
54
+ @context ||= payload['staccato.context']
55
+ end
42
56
  end
43
57
  end
44
58
  end
@@ -3,6 +3,7 @@ require 'spec_helper'
3
3
  describe Staccato::Subscribers::Page do
4
4
 
5
5
  let(:tracker) { Staccato.tracker(nil) }
6
+ let(:context) { {} }
6
7
  let(:now) {Time.now.to_i}
7
8
  let(:duration) {49}
8
9
 
@@ -18,7 +19,8 @@ describe Staccato::Subscribers::Page do
18
19
  status: 200,
19
20
  view_runtime: 46.848,
20
21
  db_runtime: 0.157,
21
- 'staccato.tracker' => tracker
22
+ 'staccato.tracker' => tracker,
23
+ 'staccato.context' => context
22
24
  }
23
25
  }
24
26
 
@@ -3,6 +3,7 @@ require 'spec_helper'
3
3
  describe Staccato::Subscribers::Timing do
4
4
 
5
5
  let(:tracker) { Staccato.tracker(nil) }
6
+ let(:context) { {user_ip: "127.0.0.1"} }
6
7
  let(:now) {Time.now.to_i}
7
8
  let(:duration) {49} # in seconds
8
9
 
@@ -19,7 +20,8 @@ describe Staccato::Subscribers::Timing do
19
20
  status: 200,
20
21
  view_runtime: 46.848, # milliseconds
21
22
  db_runtime: 0.157, # milliseconds
22
- 'staccato.tracker' => tracker
23
+ 'staccato.tracker' => tracker,
24
+ 'staccato.context' => context
23
25
  }
24
26
  }
25
27
 
@@ -43,14 +45,14 @@ describe Staccato::Subscribers::Timing do
43
45
  it 'tracks total run time' do
44
46
  # convert duration time to milliseconds
45
47
  total_runtime = duration.to_f*1000
46
- expect(tracker).to have_received(:timing).with(category: :rails, variable: :runtime, label: :total, time: total_runtime)
48
+ expect(tracker).to have_received(:timing).with(user_ip: "127.0.0.1", category: :rails, variable: :runtime, label: :total, time: total_runtime)
47
49
  end
48
50
 
49
51
  it 'tracks db run time' do
50
- expect(tracker).to have_received(:timing).with(category: :rails, variable: :runtime, label: :db, time: 0.157)
52
+ expect(tracker).to have_received(:timing).with(user_ip: "127.0.0.1", category: :rails, variable: :runtime, label: :db, time: 0.157)
51
53
  end
52
54
 
53
55
  it 'tracks view rendering run time' do
54
- expect(tracker).to have_received(:timing).with(category: :rails, variable: :runtime, label: :view, time: 46.848)
56
+ expect(tracker).to have_received(:timing).with(user_ip: "127.0.0.1", category: :rails, variable: :runtime, label: :view, time: 46.848)
55
57
  end
56
58
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: staccato-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tony Pitale
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-10 00:00:00.000000000 Z
11
+ date: 2017-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -177,7 +177,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
177
177
  version: '0'
178
178
  requirements: []
179
179
  rubyforge_project:
180
- rubygems_version: 2.5.1
180
+ rubygems_version: 2.6.8
181
181
  signing_key:
182
182
  specification_version: 4
183
183
  summary: Rails integration with Staccato for Google Analytics measurement.