ahoy_matey 0.2.1 → 0.2.2
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 +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +9 -1
- data/app/controllers/ahoy/events_controller.rb +10 -4
- data/lib/ahoy/tracker.rb +19 -14
- data/lib/ahoy/version.rb +1 -1
- data/lib/ahoy_matey.rb +2 -0
- data/vendor/assets/javascripts/ahoy.js +4 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 901b2af03cc91c3ad7ccef91dedfd1514e452357
|
4
|
+
data.tar.gz: 83494b26ea230cf54836b3d67eb6efc88cbac45f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1772c4ed5abe7395b6cf651f48ef05ec7454b3e30c80d9e54989407e8dd510fdba40f2ff827b5041dbe93fc22160eba8dc612fe780657bce4ba55bb5da6f50ce
|
7
|
+
data.tar.gz: a33c3b9ea6cb8e4ae7104085b392c7d0bd49ed1121eaef0eace1c9157f11098843236f66792c0138286e2e11c3ee41bb5d2ce97676428f1ef28f3b812e9cc269
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -367,7 +367,15 @@ Use a different model for events
|
|
367
367
|
Ahoy.subscribers << Ahoy::Subscribers::ActiveRecord.new(model: Event)
|
368
368
|
```
|
369
369
|
|
370
|
-
|
370
|
+
Exclude visits and events
|
371
|
+
|
372
|
+
```ruby
|
373
|
+
Ahoy.exclude_method = proc do |controller|
|
374
|
+
controller.request.ip == "192.168.1.1"
|
375
|
+
end
|
376
|
+
```
|
377
|
+
|
378
|
+
Track bots
|
371
379
|
|
372
380
|
```ruby
|
373
381
|
Ahoy.track_bots = true
|
@@ -2,11 +2,17 @@ module Ahoy
|
|
2
2
|
class EventsController < Ahoy::BaseController
|
3
3
|
|
4
4
|
def create
|
5
|
-
|
6
|
-
|
7
|
-
options
|
5
|
+
events = params[:name] ? [params] : ActiveSupport::JSON.decode(request.body.read)
|
6
|
+
events.each do |event|
|
7
|
+
options = {}
|
8
|
+
if event["time"] and (time = Time.at(event["time"].to_f) rescue nil) and (1.minute.ago..Time.now).cover?(time)
|
9
|
+
options[:time] = time
|
10
|
+
end
|
11
|
+
if event["id"]
|
12
|
+
options[:id] = event["id"]
|
13
|
+
end
|
14
|
+
ahoy.track event["name"], event["properties"], options
|
8
15
|
end
|
9
|
-
ahoy.track params[:name], params[:properties], options
|
10
16
|
render json: {}
|
11
17
|
end
|
12
18
|
|
data/lib/ahoy/tracker.rb
CHANGED
@@ -6,24 +6,29 @@ module Ahoy
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def track(name, properties = {}, options = {})
|
9
|
-
|
10
|
-
|
11
|
-
options
|
12
|
-
|
13
|
-
|
14
|
-
options[:
|
9
|
+
if !(@controller and Ahoy.exclude_method and Ahoy.exclude_method.call(@controller))
|
10
|
+
# publish to each subscriber
|
11
|
+
options = options.dup
|
12
|
+
if @controller
|
13
|
+
options[:controller] ||= @controller
|
14
|
+
options[:user] ||= Ahoy.fetch_user(@controller)
|
15
|
+
if @controller.respond_to?(:current_visit)
|
16
|
+
options[:visit] ||= @controller.current_visit
|
17
|
+
end
|
15
18
|
end
|
16
|
-
|
17
|
-
options[:time] ||= Time.zone.now
|
19
|
+
options[:time] ||= Time.zone.now
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
21
|
+
subscribers = Ahoy.subscribers
|
22
|
+
if subscribers.any?
|
23
|
+
subscribers.each do |subscriber|
|
24
|
+
subscriber.track(name, properties, options)
|
25
|
+
end
|
26
|
+
else
|
27
|
+
$stderr.puts "No subscribers"
|
23
28
|
end
|
24
|
-
else
|
25
|
-
$stderr.puts "No subscribers"
|
26
29
|
end
|
30
|
+
|
31
|
+
true
|
27
32
|
end
|
28
33
|
|
29
34
|
end
|
data/lib/ahoy/version.rb
CHANGED
data/lib/ahoy_matey.rb
CHANGED
@@ -46,6 +46,8 @@ module Ahoy
|
|
46
46
|
(controller.respond_to?(:current_user) && controller.current_user) || (controller.respond_to?(:current_resource_owner, true) && controller.send(:current_resource_owner)) || nil
|
47
47
|
end
|
48
48
|
|
49
|
+
mattr_accessor :exclude_method
|
50
|
+
|
49
51
|
mattr_accessor :subscribers
|
50
52
|
self.subscribers = []
|
51
53
|
|
@@ -27,7 +27,7 @@
|
|
27
27
|
if (ahoy.domain) {
|
28
28
|
cookieDomain = "; domain=" + ahoy.domain;
|
29
29
|
}
|
30
|
-
document.cookie = name + "=" + value + expires + cookieDomain + "; path=/";
|
30
|
+
document.cookie = name + "=" + escape(value) + expires + cookieDomain + "; path=/";
|
31
31
|
}
|
32
32
|
|
33
33
|
function getCookie(name) {
|
@@ -40,7 +40,7 @@
|
|
40
40
|
c = c.substring(1, c.length);
|
41
41
|
}
|
42
42
|
if (c.indexOf(nameEQ) === 0) {
|
43
|
-
return c.substring(nameEQ.length, c.length);
|
43
|
+
return unescape(c.substring(nameEQ.length, c.length));
|
44
44
|
}
|
45
45
|
}
|
46
46
|
return null;
|
@@ -100,7 +100,7 @@
|
|
100
100
|
$.ajax({
|
101
101
|
type: "POST",
|
102
102
|
url: "/ahoy/events",
|
103
|
-
data: JSON.stringify(event),
|
103
|
+
data: JSON.stringify([event]),
|
104
104
|
contentType: "application/json; charset=utf-8",
|
105
105
|
dataType: "json",
|
106
106
|
success: function() {
|
@@ -218,7 +218,7 @@
|
|
218
218
|
$(document).on("click", "a, button, input[type=submit]", function (e) {
|
219
219
|
var $target = $(e.currentTarget);
|
220
220
|
var properties = eventProperties(e);
|
221
|
-
properties.text = properties.tag == "input" ? $target.val() : $.trim($target.text());
|
221
|
+
properties.text = properties.tag == "input" ? $target.val() : $.trim($target.text().replace(/[\s\r\n]+/g, " "));
|
222
222
|
properties.href = $target.attr("href");
|
223
223
|
ahoy.track("$click", properties);
|
224
224
|
});
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ahoy_matey
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|