ga_events 0.1.7 → 0.2.0
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 +9 -3
- data/lib/ga_events/event.rb +4 -1
- data/lib/ga_events/list.rb +3 -1
- data/lib/ga_events/middleware.rb +17 -4
- data/lib/ga_events/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
---
|
|
2
2
|
!binary "U0hBMQ==":
|
|
3
3
|
metadata.gz: !binary |-
|
|
4
|
-
|
|
4
|
+
YTJhMGE3MTIxYTVhNDZlOGI2ZjhmZjgwNDFkZjU4M2ZhYmUxZmQzYg==
|
|
5
5
|
data.tar.gz: !binary |-
|
|
6
|
-
|
|
6
|
+
N2QzYzE4MWM4NjY0ZjY4MWY4MDk5ZTlmYmU4ZDY1ODZiODNhYTI0Zg==
|
|
7
7
|
!binary "U0hBNTEy":
|
|
8
8
|
metadata.gz: !binary |-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
MmJmMjJlY2EwOWE4ZDA4N2QwM2QwZjZlM2M5OGIzMWUwZjEzNWFjZGY5NTc3
|
|
10
|
+
YTNmMjkwMmI0ODViMGJlOTNhYjMyZWVhNmQ5NGEzOGRhOGEyOWUyOTRjZjEx
|
|
11
|
+
ZjFhOTZmMzRiMWEwZTZkMjEwZDllNzlmMTA3YzhjOTQ2MzU0YTg=
|
|
12
12
|
data.tar.gz: !binary |-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
ZDM3NmFiY2Q1OGFjMTM2ZDQ3NDE2Yzg0NDU1ZTI4MGU0NWU0Yjk3MzcwY2E2
|
|
14
|
+
ZGY3OWVkMzcwMzdlMTM1MzgwMDhmMGE4MTllZjUyM2VjYjFmZTUzYTM4YWFj
|
|
15
|
+
OTRkMzU1NTFjYTA2ZDA5MzNiNzJlYTliYjAwZjgwZTU4ZGRmNDQ=
|
data/README.md
CHANGED
|
@@ -6,13 +6,19 @@ This gem alllows you to annotate events everywhere in the code of your Rails
|
|
|
6
6
|
app.
|
|
7
7
|
A rack middleware is automatically inserted into the stack. It transports
|
|
8
8
|
the event data to the client. Normal requests get a DIV injected, Ajax requests
|
|
9
|
-
get a data-pounded custom HTTP header appended.
|
|
9
|
+
get a data-pounded custom HTTP header appended. In case of redirects the data
|
|
10
|
+
survives inside Rails' flash.
|
|
10
11
|
The asset pipeline-ready CoffeeScript extracts this data on the client-side and
|
|
11
12
|
pushes it to Google Analytics via ga.js or Google Tag Manager.
|
|
12
13
|
|
|
14
|
+
## Dependencies
|
|
15
|
+
|
|
16
|
+
* Rails 3.1 onwards
|
|
17
|
+
* jQuery
|
|
18
|
+
|
|
13
19
|
## Installation
|
|
14
20
|
|
|
15
|
-
|
|
21
|
+
Add it to your `Gemfile` with:
|
|
16
22
|
|
|
17
23
|
```ruby
|
|
18
24
|
gem 'ga_events'
|
|
@@ -20,7 +26,7 @@ gem 'ga_events'
|
|
|
20
26
|
|
|
21
27
|
Run the `bundle` command to install it.
|
|
22
28
|
|
|
23
|
-
Add to the top of your `application.js
|
|
29
|
+
Add to the top of your `application.js` (but after requiring jQuery):
|
|
24
30
|
|
|
25
31
|
```javascript
|
|
26
32
|
//= require ga_events.js
|
data/lib/ga_events/event.rb
CHANGED
data/lib/ga_events/list.rb
CHANGED
|
@@ -14,8 +14,10 @@ module GaEvents::List
|
|
|
14
14
|
data.present?
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
# Init list, optionally with a string of serialized events
|
|
18
|
+
def self.init(str = nil)
|
|
18
19
|
Thread.current[:ga_events] = []
|
|
20
|
+
(str || '').split('$').each { |s| GaEvents::Event.from_string(s) }
|
|
19
21
|
end
|
|
20
22
|
|
|
21
23
|
def self.data
|
data/lib/ga_events/middleware.rb
CHANGED
|
@@ -2,15 +2,19 @@ require 'rack/utils'
|
|
|
2
2
|
|
|
3
3
|
module GaEvents
|
|
4
4
|
class Middleware
|
|
5
|
-
|
|
6
5
|
def initialize(app)
|
|
7
6
|
@app = app
|
|
8
7
|
end
|
|
9
8
|
def call(env)
|
|
10
|
-
|
|
9
|
+
# Handle events stored in flash
|
|
10
|
+
# Parts borrowed from Rails:
|
|
11
|
+
# https://github.com/rails/rails/blob/v3.2.14/actionpack/lib/action_dispatch/middleware/flash.rb
|
|
12
|
+
flash = env['rack.session'] && env['rack.session']['flash']
|
|
13
|
+
GaEvents::List.init(flash && flash['ga_events'])
|
|
14
|
+
|
|
11
15
|
status, headers, response = @app.call(env)
|
|
12
|
-
headers = Rack::Utils::HeaderHash.new(headers)
|
|
13
16
|
|
|
17
|
+
headers = Rack::Utils::HeaderHash.new(headers)
|
|
14
18
|
if GaEvents::List.present?
|
|
15
19
|
request = Rack::Request.new(env)
|
|
16
20
|
|
|
@@ -18,10 +22,19 @@ module GaEvents
|
|
|
18
22
|
serialized = GaEvents::List.to_s
|
|
19
23
|
|
|
20
24
|
if request.xhr?
|
|
25
|
+
# AJAX request
|
|
21
26
|
headers['X-GA-Events'] = serialized
|
|
27
|
+
|
|
28
|
+
elsif (300..399).include?(status)
|
|
29
|
+
# 30x/redirect? Then add event list to flash to survive the redirect.
|
|
30
|
+
flash_hash = env[ActionDispatch::Flash::KEY]
|
|
31
|
+
flash_hash ||= ActionDispatch::Flash::FlashHash.new
|
|
32
|
+
flash_hash['ga_events'] = serialized
|
|
33
|
+
env[ActionDispatch::Flash::KEY] = flash_hash
|
|
34
|
+
|
|
22
35
|
elsif is_html?(status, headers)
|
|
23
36
|
body = response
|
|
24
|
-
body = body.each.to_a.join
|
|
37
|
+
body = body.each.to_a.join if body.respond_to?(:each)
|
|
25
38
|
body = body.sub('</body>',
|
|
26
39
|
"<div data-ga-events='#{serialized}'></div>\\0")
|
|
27
40
|
response = [body]
|
data/lib/ga_events/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ga_events
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Florian Dütsch
|
|
@@ -10,7 +10,7 @@ authors:
|
|
|
10
10
|
autorequire:
|
|
11
11
|
bindir: bin
|
|
12
12
|
cert_chain: []
|
|
13
|
-
date: 2013-
|
|
13
|
+
date: 2013-09-09 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
16
|
name: rails
|
|
@@ -68,7 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
68
68
|
version: '0'
|
|
69
69
|
requirements: []
|
|
70
70
|
rubyforge_project:
|
|
71
|
-
rubygems_version: 2.0.
|
|
71
|
+
rubygems_version: 2.0.7
|
|
72
72
|
signing_key:
|
|
73
73
|
specification_version: 4
|
|
74
74
|
summary: This gem allows you to annotate events everywhere in the code of your Rails
|