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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7bfd98e74a3c8164034e720f074c623e461e197f
4
- data.tar.gz: b91ab16168e6fa4301741c0a32a45107e28d46f6
3
+ metadata.gz: 901b2af03cc91c3ad7ccef91dedfd1514e452357
4
+ data.tar.gz: 83494b26ea230cf54836b3d67eb6efc88cbac45f
5
5
  SHA512:
6
- metadata.gz: 7d0d3df7bb8e468751d299e7073d00924119d6e035ea436a1384f02785f462523473c58d5b11a649dd7db3e1bb5fc365ea67f62dbf3fa8151f9587d011b7f96a
7
- data.tar.gz: f65476622c0be90b84619dd09bd9d5299a90507e46738e7f0fc7525d950e9ea0adcef385256f05203d27a633d3eac6dadf39b9016d255cec1f827e82636d6c80
6
+ metadata.gz: 1772c4ed5abe7395b6cf651f48ef05ec7454b3e30c80d9e54989407e8dd510fdba40f2ff827b5041dbe93fc22160eba8dc612fe780657bce4ba55bb5da6f50ce
7
+ data.tar.gz: a33c3b9ea6cb8e4ae7104085b392c7d0bd49ed1121eaef0eace1c9157f11098843236f66792c0138286e2e11c3ee41bb5d2ce97676428f1ef28f3b812e9cc269
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## 0.2.2
2
+
3
+ - Added `exclude_method` option
4
+ - Added support for batch events
5
+ - Fixed cookie encoding
6
+ - Fixed `options` variable from being modified
7
+
1
8
  ## 0.2.1
2
9
 
3
10
  - Fixed IE 8 error
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
- Track bots [master]
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
- options = {}
6
- if params[:time] and (time = Time.at(params[:time].to_f) rescue nil) and (1.minute.ago..Time.now).cover?(time)
7
- options[:time] = time
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
- # publish to each subscriber
10
- if @controller
11
- options[:controller] ||= @controller
12
- options[:user] ||= Ahoy.fetch_user(@controller)
13
- if @controller.respond_to?(:current_visit)
14
- options[:visit] ||= @controller.current_visit
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
- end
17
- options[:time] ||= Time.zone.now
19
+ options[:time] ||= Time.zone.now
18
20
 
19
- subscribers = Ahoy.subscribers
20
- if subscribers.any?
21
- subscribers.each do |subscriber|
22
- subscriber.track(name, properties, options)
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
@@ -1,3 +1,3 @@
1
1
  module Ahoy
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
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.1
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-17 00:00:00.000000000 Z
11
+ date: 2014-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable