ga_events 1.2.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +37 -0
- data/CHANGELOG.md +33 -0
- data/Gemfile +4 -1
- data/README.md +2 -2
- data/Rakefile +2 -4
- data/app/assets/javascripts/ga_events.js.coffee +27 -8
- data/ga_events.gemspec +6 -5
- data/lib/ga_events.rb +3 -1
- data/lib/ga_events/engine.rb +2 -0
- data/lib/ga_events/event.rb +3 -1
- data/lib/ga_events/list.rb +2 -0
- data/lib/ga_events/middleware.rb +29 -18
- data/lib/ga_events/version.rb +3 -1
- data/spec/middleware_spec.rb +2 -0
- data/spec/spec_helper.rb +2 -0
- metadata +16 -21
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8733925b29ae71da3da081d25679727857f92ee7bcb5390c72b97a87fc3c9b53
|
4
|
+
data.tar.gz: 67d86fd9ea6ced7564d851b40faa957d2138a92977a5d3197a2a6f7bdcdd7068
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0ffaa24b43857c82f369e98861b82ddd99dca42bc88b97148d4a055210e0ed76b2f82961932e83e03b76264e091a7e698577b07a69cb2efef6d40b92616965c0
|
7
|
+
data.tar.gz: 59e2857a160797e12bfec180e10aadae8f66633e303cb9c41e739a77669ee03f2b13c22faea9f10df263e1d43f2eef172f6c5d03cbca90b7a9944597c8390a77
|
data/.gitignore
CHANGED
data/.rubocop.yml
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.3
|
3
|
+
Exclude:
|
4
|
+
- 'vendor/bundle/**/*'
|
5
|
+
DisplayCopNames: true
|
6
|
+
Style/AsciiComments:
|
7
|
+
Enabled: false
|
8
|
+
Style/Documentation:
|
9
|
+
Enabled: false
|
10
|
+
Metrics/MethodLength:
|
11
|
+
Enabled: false
|
12
|
+
Style/MethodDefParentheses:
|
13
|
+
Enabled: false
|
14
|
+
Layout/MultilineOperationIndentation:
|
15
|
+
EnforcedStyle: aligned
|
16
|
+
Layout/MultilineMethodCallIndentation:
|
17
|
+
EnforcedStyle: indented
|
18
|
+
Layout/MultilineMethodDefinitionBraceLayout:
|
19
|
+
Enabled: true
|
20
|
+
Layout/MultilineHashBraceLayout:
|
21
|
+
Enabled: true
|
22
|
+
Style/SignalException:
|
23
|
+
Enabled: false
|
24
|
+
Metrics/ClassLength:
|
25
|
+
Enabled: false
|
26
|
+
Lint/AssignmentInCondition:
|
27
|
+
Enabled: false
|
28
|
+
Metrics/ParameterLists:
|
29
|
+
Enabled: false
|
30
|
+
Style/MultilineBlockChain:
|
31
|
+
Enabled: false
|
32
|
+
Style/CommentAnnotation:
|
33
|
+
Enabled: false
|
34
|
+
Style/GuardClause:
|
35
|
+
Enabled: false
|
36
|
+
Metrics/BlockLength:
|
37
|
+
Enabled: false
|
data/CHANGELOG.md
CHANGED
@@ -15,3 +15,36 @@ The format suggested at http://keepachangelog.com/ is used.
|
|
15
15
|
|
16
16
|
### Fixed
|
17
17
|
- Error returns white page
|
18
|
+
|
19
|
+
## 1.2.0 - 2014-12-18
|
20
|
+
|
21
|
+
### Added
|
22
|
+
- A Test Adapter that pushes events to a `window.events` array.
|
23
|
+
|
24
|
+
## 1.3.0 - 2017-04-27
|
25
|
+
|
26
|
+
### Added
|
27
|
+
- Support for turbolinks.
|
28
|
+
|
29
|
+
## 1.4.0 - 2018-03-09
|
30
|
+
|
31
|
+
### Fixed
|
32
|
+
- Fixed turbolinks events. To prevent older events the be processed again after page
|
33
|
+
changes orchestrated by turbolinks, events are no longer processed via the
|
34
|
+
injected DOM node. (Because the node would be cached and the event already
|
35
|
+
processed.) Instead the the header-strategy is being used.
|
36
|
+
|
37
|
+
## 1.4.1 - 2018-04-03
|
38
|
+
|
39
|
+
### Fixed
|
40
|
+
- Ensure category, action and label do not include any umlauts or ß chars
|
41
|
+
- Fixed an error where events are remaining after a redirect
|
42
|
+
|
43
|
+
## 2.0.0 - 2018-04-03
|
44
|
+
|
45
|
+
### Removed
|
46
|
+
- Support for rubies < 2.3
|
47
|
+
- Support for rails < 4.2
|
48
|
+
|
49
|
+
### Added
|
50
|
+
- Compatibility for Rails 5
|
data/Gemfile
CHANGED
data/README.md
CHANGED
data/Rakefile
CHANGED
@@ -11,12 +11,16 @@ class GaEvents.Event
|
|
11
11
|
@html_key: "ga-events"
|
12
12
|
klass: @
|
13
13
|
|
14
|
-
# Decompose a
|
14
|
+
# Decompose a event-string (ruby side) into an event object.
|
15
15
|
@from_string: (string) ->
|
16
16
|
$.map string.split("$"), (part) =>
|
17
17
|
[category, action, label, value] = part.split "|"
|
18
18
|
new @(category, action, label, value)
|
19
19
|
|
20
|
+
@from_dom: ->
|
21
|
+
dom_events = $("div[data-#{@html_key}]").data @html_key
|
22
|
+
@from_string dom_events if dom_events?
|
23
|
+
|
20
24
|
# Events should not be send to an adapter unless the DOM has finished loading.
|
21
25
|
@flush: ->
|
22
26
|
if @list.length > 0 and @may_flush
|
@@ -28,11 +32,21 @@ class GaEvents.Event
|
|
28
32
|
@klass.list.push @
|
29
33
|
@klass.flush()
|
30
34
|
|
35
|
+
escape: (str) ->
|
36
|
+
return unless str
|
37
|
+
"#{str}".replace(/ä/g, "ae")
|
38
|
+
.replace(/ö/g, "oe")
|
39
|
+
.replace(/ü/g, "ue")
|
40
|
+
.replace(/Ä/g, "Ae")
|
41
|
+
.replace(/Ö/g, "Oe")
|
42
|
+
.replace(/Ü/g, "Ue")
|
43
|
+
.replace(/ß/g, "ss")
|
44
|
+
|
31
45
|
to_hash: ->
|
32
|
-
# Category, action and label must be of type string.
|
33
|
-
action:
|
34
|
-
category:
|
35
|
-
label:
|
46
|
+
# Category, action and label must be escaped and of type string.
|
47
|
+
action: @escape(@action)
|
48
|
+
category: @escape(@category)
|
49
|
+
label: @escape(@label)
|
36
50
|
# Value has to be a positive integer or defaults to 1
|
37
51
|
value: @to_positive_integer(@value)
|
38
52
|
|
@@ -46,12 +60,17 @@ class GaEvents.Event
|
|
46
60
|
@may_flush = true
|
47
61
|
@flush()
|
48
62
|
|
49
|
-
|
63
|
+
process_xhr = (xhr) =>
|
50
64
|
xhr_events = xhr.getResponseHeader @header_key
|
51
65
|
@from_string xhr_events if xhr_events?
|
52
66
|
|
53
|
-
|
54
|
-
|
67
|
+
$(document).ajaxComplete((_, xhr) -> process_xhr(xhr))
|
68
|
+
$(document).on "turbolinks:request-end", (event) ->
|
69
|
+
xhr = event.originalEvent.data.xhr
|
70
|
+
process_xhr(xhr)
|
71
|
+
|
72
|
+
@from_dom()
|
73
|
+
|
55
74
|
|
56
75
|
class GaEvents.GoogleTagManagerAdapter
|
57
76
|
constructor: (@event = "ga_event") ->
|
data/ga_events.gemspec
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require File.expand_path('lib/ga_events/version', __dir__)
|
3
4
|
|
4
5
|
Gem::Specification.new do |gem|
|
5
6
|
gem.authors = ['Florian Dütsch', 'Sven Winkler']
|
@@ -19,11 +20,11 @@ Gem::Specification.new do |gem|
|
|
19
20
|
gem.homepage = 'https://github.com/Nix-wie-weg/ga_events'
|
20
21
|
|
21
22
|
gem.files = `git ls-files`.split($OUTPUT_RECORD_SEPARATOR)
|
22
|
-
gem.executables = gem.files.grep(
|
23
|
-
gem.test_files = gem.files.grep(
|
23
|
+
gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
|
24
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
24
25
|
gem.name = 'ga_events'
|
25
26
|
gem.require_paths = ['lib']
|
26
27
|
gem.version = GaEvents::VERSION
|
27
28
|
|
28
|
-
gem.add_dependency 'rails', '>=
|
29
|
+
gem.add_dependency 'rails', '>= 4.2'
|
29
30
|
end
|
data/lib/ga_events.rb
CHANGED
data/lib/ga_events/engine.rb
CHANGED
data/lib/ga_events/event.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module GaEvents
|
2
|
-
|
4
|
+
Event = Struct.new(:category, :action, :label, :value) do
|
3
5
|
# Default values are set here, see README.md for details.
|
4
6
|
def initialize(category = '-', action = '-', label = '-', value = 1)
|
5
7
|
super
|
data/lib/ga_events/list.rb
CHANGED
data/lib/ga_events/middleware.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rack/utils'
|
2
4
|
|
3
5
|
module GaEvents
|
@@ -16,11 +18,11 @@ module GaEvents
|
|
16
18
|
|
17
19
|
# Can outgrow, headers might get too big
|
18
20
|
serialized = GaEvents::List.to_s
|
19
|
-
if request
|
21
|
+
if xhr_or_turbolinks?(request)
|
20
22
|
# AJAX request
|
21
23
|
headers['X-GA-Events'] = serialized
|
22
24
|
|
23
|
-
elsif
|
25
|
+
elsif redirect?(status)
|
24
26
|
# 30x/redirect? Then add event list to flash to survive the redirect.
|
25
27
|
add_events_to_flash(env, serialized)
|
26
28
|
|
@@ -35,28 +37,29 @@ module GaEvents
|
|
35
37
|
private
|
36
38
|
|
37
39
|
def init_event_list(env)
|
38
|
-
|
39
|
-
|
40
|
-
# https://github.com/rails/rails/blob/v3.2.14/actionpack/lib/action_dispatch/middleware/flash.rb
|
41
|
-
flash = env['rack.session'] && env['rack.session']['flash']
|
42
|
-
|
43
|
-
# Fix for Rails 4
|
44
|
-
flash &&= flash['flashes'] if Rails::VERSION::MAJOR > 3
|
40
|
+
flash = env['rack.session'] && env['rack.session']['flash'] &&
|
41
|
+
env['rack.session']['flash']['flashes']
|
45
42
|
|
46
|
-
|
43
|
+
# The key has to be removed from the flash here to ensure it does not
|
44
|
+
# remain after the finished redirect. This copies the behaviour of the
|
45
|
+
# "#use" and "#sweep" methods of the rails flash middleware:
|
46
|
+
# https://github.com/rails/rails/blob/v3.2.14/actionpack/lib/action_dispatch/middleware/flash.rb#L220
|
47
|
+
GaEvents::List.init(flash&.delete('ga_events'))
|
47
48
|
end
|
48
49
|
|
49
50
|
def add_events_to_flash env, serialized_data
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
51
|
+
flash = env['rack.session'] && env['rack.session']['flash'] &&
|
52
|
+
env['rack.session']['flash']['flashes']
|
53
|
+
|
54
|
+
return unless flash
|
55
|
+
|
56
|
+
flash['ga_events'] = serialized_data
|
54
57
|
end
|
55
58
|
|
56
|
-
def normalize_response(
|
57
|
-
|
58
|
-
|
59
|
-
|
59
|
+
def normalize_response(response)
|
60
|
+
response = response.body if response.respond_to?(:body)
|
61
|
+
response = response.join if response.respond_to?(:join)
|
62
|
+
response
|
60
63
|
end
|
61
64
|
|
62
65
|
def inject_div(response, serialized_data)
|
@@ -71,5 +74,13 @@ module GaEvents
|
|
71
74
|
headers.key?('Content-Type') &&
|
72
75
|
headers['Content-Type'].include?('text/html')
|
73
76
|
end
|
77
|
+
|
78
|
+
def redirect?(status)
|
79
|
+
(300..399).cover?(status)
|
80
|
+
end
|
81
|
+
|
82
|
+
def xhr_or_turbolinks?(request)
|
83
|
+
request.xhr? || request.env['HTTP_TURBOLINKS_REFERRER']
|
84
|
+
end
|
74
85
|
end
|
75
86
|
end
|
data/lib/ga_events/version.rb
CHANGED
data/spec/middleware_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,33 +1,30 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ga_events
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
5
|
-
prerelease:
|
4
|
+
version: 2.0.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Florian Dütsch
|
9
8
|
- Sven Winkler
|
10
|
-
autorequire:
|
9
|
+
autorequire:
|
11
10
|
bindir: bin
|
12
11
|
cert_chain: []
|
13
|
-
date:
|
12
|
+
date: 2020-11-20 00:00:00.000000000 Z
|
14
13
|
dependencies:
|
15
14
|
- !ruby/object:Gem::Dependency
|
16
15
|
name: rails
|
17
16
|
requirement: !ruby/object:Gem::Requirement
|
18
|
-
none: false
|
19
17
|
requirements:
|
20
|
-
- -
|
18
|
+
- - ">="
|
21
19
|
- !ruby/object:Gem::Version
|
22
|
-
version: '
|
20
|
+
version: '4.2'
|
23
21
|
type: :runtime
|
24
22
|
prerelease: false
|
25
23
|
version_requirements: !ruby/object:Gem::Requirement
|
26
|
-
none: false
|
27
24
|
requirements:
|
28
|
-
- -
|
25
|
+
- - ">="
|
29
26
|
- !ruby/object:Gem::Version
|
30
|
-
version: '
|
27
|
+
version: '4.2'
|
31
28
|
description: Google Analytics' Event Tracking everywhere in your Rails app)
|
32
29
|
email:
|
33
30
|
- florian.duetsch@nix-wie-weg.de
|
@@ -36,7 +33,8 @@ executables: []
|
|
36
33
|
extensions: []
|
37
34
|
extra_rdoc_files: []
|
38
35
|
files:
|
39
|
-
- .gitignore
|
36
|
+
- ".gitignore"
|
37
|
+
- ".rubocop.yml"
|
40
38
|
- CHANGELOG.md
|
41
39
|
- Gemfile
|
42
40
|
- LICENSE
|
@@ -55,27 +53,25 @@ files:
|
|
55
53
|
- spec/spec_helper.rb
|
56
54
|
homepage: https://github.com/Nix-wie-weg/ga_events
|
57
55
|
licenses: []
|
58
|
-
|
56
|
+
metadata: {}
|
57
|
+
post_install_message:
|
59
58
|
rdoc_options: []
|
60
59
|
require_paths:
|
61
60
|
- lib
|
62
61
|
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
-
none: false
|
64
62
|
requirements:
|
65
|
-
- -
|
63
|
+
- - ">="
|
66
64
|
- !ruby/object:Gem::Version
|
67
65
|
version: '0'
|
68
66
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
-
none: false
|
70
67
|
requirements:
|
71
|
-
- -
|
68
|
+
- - ">="
|
72
69
|
- !ruby/object:Gem::Version
|
73
70
|
version: '0'
|
74
71
|
requirements: []
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
specification_version: 3
|
72
|
+
rubygems_version: 3.0.3
|
73
|
+
signing_key:
|
74
|
+
specification_version: 4
|
79
75
|
summary: This gem allows you to annotate events everywhere in the code of your Rails
|
80
76
|
app. A rack middleware is automatically inserted into the stack. It transports the
|
81
77
|
event data to the client. Normal requests get a DIV injected, AJAX requests get
|
@@ -85,4 +81,3 @@ summary: This gem allows you to annotate events everywhere in the code of your R
|
|
85
81
|
test_files:
|
86
82
|
- spec/middleware_spec.rb
|
87
83
|
- spec/spec_helper.rb
|
88
|
-
has_rdoc:
|