ga_events 0.2.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +20 -1
- data/TODO +0 -1
- data/app/assets/javascripts/ga_events.js.coffee +21 -31
- data/ga_events.gemspec +1 -1
- data/lib/ga_events/event.rb +2 -1
- data/lib/ga_events/list.rb +1 -1
- data/lib/ga_events/middleware.rb +4 -2
- data/lib/ga_events/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NDljN2FmMjUyMGVlZTFiY2ZjZGFlYmQ5ZWQ0NmM1NzQxMTBkNmVkMw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MGE5NzUxMDdkYzA3MjJjYWNhZmI4MDM0ZjcwMzc5OTc4M2RlNjdjYQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZGJlYTU3ZTExOGJmMTdlY2Q1Yzk2M2VjZDExMGNiMmYxMjg1OGExZDBmNWU4
|
10
|
+
OWJmNmJjNDZkYTk1YWI1NmY0ODFhMGFkZGIyNGIyYWU0NzVlNmE3YzM0YmEy
|
11
|
+
M2E3NjZiOTYxYzg2M2M3YjljNmNjMzExY2RjMmQ3MGMzOTBiMGQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YWE3ZTdkZGE3ZjkwNThhYjFhZjhhMDVjMDNjN2E5NzcyN2JhZDI2Yjg5MDA3
|
14
|
+
OTJmOTg0YWY5YzI4NjgxMTEzYTg1ODBkOTk1NWU1M2RmNmMxODU4ODUzOTU4
|
15
|
+
MjlkYTFjZmZkNWJlMzQ3MzBlOWI3YjllMzc3NThhZWVkYTZiYmE=
|
data/README.md
CHANGED
@@ -42,7 +42,16 @@ GaEvents.Event.adapter = function() {
|
|
42
42
|
}
|
43
43
|
```
|
44
44
|
|
45
|
-
|
45
|
+
For Google Universal Analytics use:
|
46
|
+
|
47
|
+
```javascript
|
48
|
+
GaEvents.Event.adapter = function() {
|
49
|
+
return new GaEvents.GoogleUniversalAnalyticsAdapter();
|
50
|
+
}
|
51
|
+
```
|
52
|
+
|
53
|
+
If you are using Google Tag Manager you can add custom events which are then
|
54
|
+
passed through to Google Analytics.
|
46
55
|
|
47
56
|
```javascript
|
48
57
|
GaEvents.Event.adapter = function() {
|
@@ -79,6 +88,12 @@ new GaEvents.Event(category, action, label, value)
|
|
79
88
|
We have taken special care of tracking events while the DOM is loading.
|
80
89
|
Events get collected until the DOM is ready and flushed afterwards.
|
81
90
|
|
91
|
+
### Default values
|
92
|
+
|
93
|
+
While collecting hundreds of thousands of events on a daily basis in
|
94
|
+
Google Analytics we found corrupted aggregated events when the event label or
|
95
|
+
value is omitted. We now enforce a default label ("-") and value (1).
|
96
|
+
|
82
97
|
### Too many events
|
83
98
|
|
84
99
|
Use something like this snippet to get informed of bloating HTTP headers with
|
@@ -101,6 +116,10 @@ end
|
|
101
116
|
|
102
117
|
Yes please! Use pull requests.
|
103
118
|
|
119
|
+
### Credits
|
120
|
+
|
121
|
+
* [jhilden](https://github.com/jhilden) for ideas and Rails 4 support
|
122
|
+
|
104
123
|
## More docs and tools
|
105
124
|
|
106
125
|
* [Google Analytics: Event Tracking](https://developers.google.com/analytics/devguides/collection/gajs/eventTrackerGuide)
|
@@ -24,34 +24,23 @@ class GaEvents.Event
|
|
24
24
|
@list = []
|
25
25
|
|
26
26
|
# Add all events to a queue to flush them later
|
27
|
-
constructor: (@category, @action, @label, @value) ->
|
27
|
+
constructor: (@category = "-", @action = "-", @label = "-", @value = 1) ->
|
28
28
|
@klass.list.push @
|
29
29
|
@klass.flush()
|
30
30
|
|
31
|
-
|
32
|
-
#
|
33
|
-
#
|
34
|
-
#
|
31
|
+
to_hash: ->
|
32
|
+
# Category, action and label must be of type string.
|
33
|
+
action: "#{@action}"
|
34
|
+
category: "#{@category}"
|
35
|
+
label: "#{@label}"
|
36
|
+
# Value has to be a positive integer or defaults to 1
|
37
|
+
value: @to_positive_integer(@value)
|
35
38
|
|
36
|
-
|
37
|
-
|
38
|
-
category: "#{@category}"
|
39
|
-
data.label = "#{@label}" if @is_present @label
|
39
|
+
to_positive_integer: (n) ->
|
40
|
+
if isFinite(n) and parseInt(n) >= 0 then parseInt n else 1
|
40
41
|
|
41
|
-
|
42
|
-
|
43
|
-
if isFinite(@value) and Number(@value) % 1 is 0
|
44
|
-
# Google Analytics expects a positive integer
|
45
|
-
if (value = parseInt @value) > -1
|
46
|
-
data.value = value
|
47
|
-
else
|
48
|
-
throw "Negative integers are not supported at this time."
|
49
|
-
else
|
50
|
-
throw "The parameter 'value' must be of type integer."
|
51
|
-
|
52
|
-
@klass.adapter().push data
|
53
|
-
|
54
|
-
is_present: (value) -> value? and value != ""
|
42
|
+
# https://developers.google.com/analytics/devguides/collection/gajs/eventTrackerGuide#SettingUpEventTracking
|
43
|
+
push_to_adapter: -> @klass.adapter().push @to_hash()
|
55
44
|
|
56
45
|
jQuery =>
|
57
46
|
@may_flush = true
|
@@ -67,17 +56,18 @@ class GaEvents.Event
|
|
67
56
|
class GaEvents.GoogleTagManagerAdapter
|
68
57
|
constructor: (@event = "ga_event") ->
|
69
58
|
push: (data) ->
|
70
|
-
data
|
71
|
-
data
|
59
|
+
data.event = @event
|
60
|
+
data.non_interaction = true
|
72
61
|
window.dataLayer.push data
|
73
62
|
|
63
|
+
class GaEvents.GoogleUniversalAnalyticsAdapter
|
64
|
+
push: (h) -> window.ga "send", "event", h.category, h.action, h.label, h.value
|
65
|
+
|
74
66
|
class GaEvents.GoogleAnalyticsAdapter
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
data.push true # opt_noninteraction
|
80
|
-
window._gaq.push data
|
67
|
+
# Send events non_interactive => no influence on bounce rates
|
68
|
+
push: (h) ->
|
69
|
+
window._gaq.push(
|
70
|
+
["_trackEvent", h.category, h.action, h.label, h.value, true])
|
81
71
|
|
82
72
|
class GaEvents.NullAdapter
|
83
73
|
push: (obj) -> console.log obj if console?
|
data/ga_events.gemspec
CHANGED
data/lib/ga_events/event.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module GaEvents
|
2
2
|
class Event < Struct.new(:category, :action, :label, :value)
|
3
|
-
|
3
|
+
# Default values are set here, see README.md for details.
|
4
|
+
def initialize(category = '-', action = '-', label = '-', value = 1)
|
4
5
|
super
|
5
6
|
GaEvents::List << self
|
6
7
|
end
|
data/lib/ga_events/list.rb
CHANGED
data/lib/ga_events/middleware.rb
CHANGED
@@ -10,6 +10,10 @@ module GaEvents
|
|
10
10
|
# Parts borrowed from Rails:
|
11
11
|
# https://github.com/rails/rails/blob/v3.2.14/actionpack/lib/action_dispatch/middleware/flash.rb
|
12
12
|
flash = env['rack.session'] && env['rack.session']['flash']
|
13
|
+
|
14
|
+
# Fix for Rails 4
|
15
|
+
flash &&= flash['flashes'] if Rails::VERSION::MAJOR > 3
|
16
|
+
|
13
17
|
GaEvents::List.init(flash && flash['ga_events'])
|
14
18
|
|
15
19
|
status, headers, response = @app.call(env)
|
@@ -20,7 +24,6 @@ module GaEvents
|
|
20
24
|
|
21
25
|
# Can outgrow, headers might get too big
|
22
26
|
serialized = GaEvents::List.to_s
|
23
|
-
|
24
27
|
if request.xhr?
|
25
28
|
# AJAX request
|
26
29
|
headers['X-GA-Events'] = serialized
|
@@ -55,4 +58,3 @@ module GaEvents
|
|
55
58
|
end
|
56
59
|
end
|
57
60
|
end
|
58
|
-
|
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: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Florian Dütsch
|
@@ -10,20 +10,20 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-
|
13
|
+
date: 2013-10-21 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rails
|
17
17
|
requirement: !ruby/object:Gem::Requirement
|
18
18
|
requirements:
|
19
|
-
- -
|
19
|
+
- - ! '>='
|
20
20
|
- !ruby/object:Gem::Version
|
21
21
|
version: '3.1'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
requirements:
|
26
|
-
- -
|
26
|
+
- - ! '>='
|
27
27
|
- !ruby/object:Gem::Version
|
28
28
|
version: '3.1'
|
29
29
|
description: Google Analytics' Event Tracking everywhere in your Rails app
|