ga_events 1.3.1 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/.rubocop.yml +37 -0
- data/CHANGELOG.md +23 -0
- data/Gemfile +4 -1
- data/README.md +11 -2
- data/Rakefile +2 -6
- data/app/assets/javascripts/ga_events.js.coffee +25 -6
- data/ga_events.gemspec +6 -5
- 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 -21
- data/lib/ga_events/version.rb +3 -1
- data/lib/ga_events.rb +3 -1
- data/spec/middleware_spec.rb +2 -0
- data/spec/spec_helper.rb +2 -0
- metadata +9 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 205433864fd2efabf0cf787da0be314c9bc48fd644773d8df29f6ca66327ba43
|
4
|
+
data.tar.gz: fa05cd8ee83f4b73fa23a3562e19d0ec2fcbb1a684c7ee49c357d0e78a54c3a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 472515474d12c53c4f3d43b8c577a45776ed983149c8347940294ca1128e907d101f48054eee7c00468cafdc3f1e7aba33c3cdfa08f43d81ebc0bd25c91f884f
|
7
|
+
data.tar.gz: 483bbdb595f20e852ec8f6b74366251e91e84b76cde7454721136d42cfd31586e36c88bd015ac6cbf321a673e2779e5f29b96cb345924d7606f648e36da67aa9
|
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
@@ -25,3 +25,26 @@ The format suggested at http://keepachangelog.com/ is used.
|
|
25
25
|
|
26
26
|
### Added
|
27
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
@@ -13,8 +13,8 @@ pushes it to Google Analytics via ga.js or Google Tag Manager.
|
|
13
13
|
|
14
14
|
## Dependencies
|
15
15
|
|
16
|
-
* Ruby >=
|
17
|
-
* Rails
|
16
|
+
* Ruby >= 2.3
|
17
|
+
* Rails 4.2 onwards
|
18
18
|
* jQuery
|
19
19
|
|
20
20
|
## Installation
|
@@ -70,6 +70,15 @@ GaEvents.Event.adapter = function() {
|
|
70
70
|
}
|
71
71
|
```
|
72
72
|
|
73
|
+
### Optional consent settings
|
74
|
+
|
75
|
+
Events are flushed immediatly by default. If you need to wait for user consent
|
76
|
+
you can set `GaEvents.Event.require_user_consent = true`.
|
77
|
+
|
78
|
+
With `require_user_consent` enabled all events are buffered until
|
79
|
+
`GaEvents.Event.user_consent_given = true` is set. Events are flushed as soon
|
80
|
+
as `GaEvents.Event.flush()` is called.
|
81
|
+
|
73
82
|
### Testing
|
74
83
|
|
75
84
|
For your testing pleasure we included `NullAdapter`.
|
data/Rakefile
CHANGED
@@ -9,6 +9,8 @@ class GaEvents.Event
|
|
9
9
|
@may_flush: false
|
10
10
|
@header_key: "X-GA-Events"
|
11
11
|
@html_key: "ga-events"
|
12
|
+
@require_user_consent: false
|
13
|
+
@user_consent_given: false
|
12
14
|
klass: @
|
13
15
|
|
14
16
|
# Decompose a event-string (ruby side) into an event object.
|
@@ -23,6 +25,8 @@ class GaEvents.Event
|
|
23
25
|
|
24
26
|
# Events should not be send to an adapter unless the DOM has finished loading.
|
25
27
|
@flush: ->
|
28
|
+
return if @require_user_consent && !@user_consent_given
|
29
|
+
|
26
30
|
if @list.length > 0 and @may_flush
|
27
31
|
$.map @list, (event) -> event.push_to_adapter()
|
28
32
|
@list = []
|
@@ -32,11 +36,21 @@ class GaEvents.Event
|
|
32
36
|
@klass.list.push @
|
33
37
|
@klass.flush()
|
34
38
|
|
39
|
+
escape: (str) ->
|
40
|
+
return unless str
|
41
|
+
"#{str}".replace(/ä/g, "ae")
|
42
|
+
.replace(/ö/g, "oe")
|
43
|
+
.replace(/ü/g, "ue")
|
44
|
+
.replace(/Ä/g, "Ae")
|
45
|
+
.replace(/Ö/g, "Oe")
|
46
|
+
.replace(/Ü/g, "Ue")
|
47
|
+
.replace(/ß/g, "ss")
|
48
|
+
|
35
49
|
to_hash: ->
|
36
|
-
# Category, action and label must be of type string.
|
37
|
-
action:
|
38
|
-
category:
|
39
|
-
label:
|
50
|
+
# Category, action and label must be escaped and of type string.
|
51
|
+
action: @escape(@action)
|
52
|
+
category: @escape(@category)
|
53
|
+
label: @escape(@label)
|
40
54
|
# Value has to be a positive integer or defaults to 1
|
41
55
|
value: @to_positive_integer(@value)
|
42
56
|
|
@@ -50,12 +64,17 @@ class GaEvents.Event
|
|
50
64
|
@may_flush = true
|
51
65
|
@flush()
|
52
66
|
|
53
|
-
|
67
|
+
process_xhr = (xhr) =>
|
54
68
|
xhr_events = xhr.getResponseHeader @header_key
|
55
69
|
@from_string xhr_events if xhr_events?
|
56
70
|
|
71
|
+
$(document).ajaxComplete((_, xhr) -> process_xhr(xhr))
|
72
|
+
$(document).on "turbolinks:request-end", (event) ->
|
73
|
+
xhr = event.originalEvent.data.xhr
|
74
|
+
process_xhr(xhr)
|
75
|
+
|
57
76
|
@from_dom()
|
58
|
-
|
77
|
+
|
59
78
|
|
60
79
|
class GaEvents.GoogleTagManagerAdapter
|
61
80
|
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/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,31 +37,29 @@ module GaEvents
|
|
35
37
|
private
|
36
38
|
|
37
39
|
def init_event_list(env)
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
flash
|
42
|
-
|
43
|
-
#
|
44
|
-
|
45
|
-
|
46
|
-
GaEvents::List.init(flash && flash['ga_events'])
|
40
|
+
flash = env['rack.session'] && env['rack.session']['flash'] &&
|
41
|
+
env['rack.session']['flash']['flashes']
|
42
|
+
|
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
|
-
|
54
|
-
flash_hash.discard('ga_events')
|
51
|
+
flash = env['rack.session'] && env['rack.session']['flash'] &&
|
52
|
+
env['rack.session']['flash']['flashes']
|
53
|
+
|
54
|
+
return unless flash
|
55
55
|
|
56
|
-
|
56
|
+
flash['ga_events'] = serialized_data
|
57
57
|
end
|
58
58
|
|
59
|
-
def normalize_response(
|
60
|
-
|
61
|
-
|
62
|
-
|
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
|
63
63
|
end
|
64
64
|
|
65
65
|
def inject_div(response, serialized_data)
|
@@ -74,5 +74,13 @@ module GaEvents
|
|
74
74
|
headers.key?('Content-Type') &&
|
75
75
|
headers['Content-Type'].include?('text/html')
|
76
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
|
77
85
|
end
|
78
86
|
end
|
data/lib/ga_events/version.rb
CHANGED
data/lib/ga_events.rb
CHANGED
data/spec/middleware_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ga_events
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Florian Dütsch
|
8
8
|
- Sven Winkler
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2021-09-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -17,14 +17,14 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - ">="
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: '
|
20
|
+
version: '4.2'
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - ">="
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version: '
|
27
|
+
version: '4.2'
|
28
28
|
description: Google Analytics' Event Tracking everywhere in your Rails app)
|
29
29
|
email:
|
30
30
|
- florian.duetsch@nix-wie-weg.de
|
@@ -34,6 +34,7 @@ extensions: []
|
|
34
34
|
extra_rdoc_files: []
|
35
35
|
files:
|
36
36
|
- ".gitignore"
|
37
|
+
- ".rubocop.yml"
|
37
38
|
- CHANGELOG.md
|
38
39
|
- Gemfile
|
39
40
|
- LICENSE
|
@@ -53,7 +54,7 @@ files:
|
|
53
54
|
homepage: https://github.com/Nix-wie-weg/ga_events
|
54
55
|
licenses: []
|
55
56
|
metadata: {}
|
56
|
-
post_install_message:
|
57
|
+
post_install_message:
|
57
58
|
rdoc_options: []
|
58
59
|
require_paths:
|
59
60
|
- lib
|
@@ -68,9 +69,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
68
69
|
- !ruby/object:Gem::Version
|
69
70
|
version: '0'
|
70
71
|
requirements: []
|
71
|
-
|
72
|
-
|
73
|
-
signing_key:
|
72
|
+
rubygems_version: 3.0.3
|
73
|
+
signing_key:
|
74
74
|
specification_version: 4
|
75
75
|
summary: This gem allows you to annotate events everywhere in the code of your Rails
|
76
76
|
app. A rack middleware is automatically inserted into the stack. It transports the
|