ahoy_matey 2.0.1 → 2.0.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: 640c91af9741127b748f530d102751a73f71b4c9
4
- data.tar.gz: b341bf79dc207745b63f7a419711d402f2fc8cc0
3
+ metadata.gz: 0c48c8c5793b7e8f7c53ee1fcfed647340749cee
4
+ data.tar.gz: ad2e9686bebde7233be8804ac899a1672f352240
5
5
  SHA512:
6
- metadata.gz: 9f154fb9aefbee54089fc9c6e269c26e7f09eb4229c211ccd073d9d8a25fb191c875155a687e358966ff20b9dc3c39bf00e1a6701eda787ed212a800e594408c
7
- data.tar.gz: ddac0a216a109b50904be1a2553cfa48df607908dacb50a3329f88bf8a7025faaa86df4e067247390dac8c2dbccc2d520fcabe50e072fe4240111682ffb46b5e
6
+ metadata.gz: 5b3a16dd65efc501a56fa2a6e2574dc228dbc236d97d352153bd6012b85243450753a62f4155737a2d43610ac619f225004492ed8bcfc8a5e088ef93b67fb56a
7
+ data.tar.gz: 23e2ee9cc5ec7d772cce7a4af348b95b93090c5d3a7113fd1d47fcd9fe3bbca4cbbb145cbc21d3826ca159d984566e3e1c8f3b45d89d9a7319bba2ae2d8026eb
@@ -1,3 +1,10 @@
1
+ ## 2.0.2
2
+
3
+ - Fixed error on duplicate records
4
+ - Fixed message when visit not found for geocoding
5
+ - Better compatibility with GeoLite2
6
+ - Better browser compatibility for Ahoy.js
7
+
1
8
  ## 2.0.1
2
9
 
3
10
  - Added `Ahoy.server_side_visits = :when_needed` to automatically create visits server-side when needed for events and `visitable`
data/README.md CHANGED
@@ -79,7 +79,7 @@ skip_before_action :track_ahoy_visit
79
79
 
80
80
  This is typically useful for APIs.
81
81
 
82
- You can also defer visit tracking to JavaScript. This is useful for preventing bots (that aren’t detected by their user agent) and users with cookies disabled from creating a new visit on each request. `:when_needed` will create visits server-side when needed by events, and `false` will discard events without a visit.
82
+ You can also defer visit tracking to JavaScript. This is useful for preventing bots (that aren’t detected by their user agent) and users with cookies disabled from creating a new visit on each request. `:when_needed` will create visits server-side only when needed by events, and `false` will disable server-side creation completely, discarding events without a visit.
83
83
 
84
84
  ```ruby
85
85
  Ahoy.server_side_visits = :when_needed
@@ -120,7 +120,7 @@ class ApplicationController < ActionController::Base
120
120
  protected
121
121
 
122
122
  def track_action
123
- ahoy.track "Viewed action", request.path_parameters
123
+ ahoy.track "Ran action", request.path_parameters
124
124
  end
125
125
  end
126
126
  ```
@@ -263,6 +263,27 @@ Change the job queue with:
263
263
  Ahoy.job_queue = :low_priority
264
264
  ```
265
265
 
266
+ #### Geocoding Performance
267
+
268
+ To avoid calls to a remote API, download the [GeoLite2 City database](https://dev.maxmind.com/geoip/geoip2/geolite2/) and configure Geocoder to use it.
269
+
270
+ Add this line to your application’s Gemfile:
271
+
272
+ ```ruby
273
+ gem 'maxminddb'
274
+ ```
275
+
276
+ And create an initializer at `config/initializers/geocoder.rb` with:
277
+
278
+ ```ruby
279
+ Geocoder.configure(
280
+ ip_lookup: :geoip2,
281
+ geoip2: {
282
+ file: Rails.root.join("lib", "GeoLite2-City.mmdb")
283
+ }
284
+ )
285
+ ```
286
+
266
287
  ### Token Generation
267
288
 
268
289
  Ahoy uses random UUIDs for visit and visitor tokens by default, but you can use your own generator like [Druuid](https://github.com/recurly/druuid).
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
19
19
 
20
20
  spec.add_dependency "railties", ">= 4.2"
21
21
  spec.add_dependency "addressable"
22
- spec.add_dependency "geocoder"
22
+ spec.add_dependency "geocoder", ">= 1.4.5"
23
23
  spec.add_dependency "browser", "~> 2.0"
24
24
  spec.add_dependency "referer-parser", ">= 0.3"
25
25
  spec.add_dependency "user_agent_parser"
@@ -7,14 +7,13 @@ module Ahoy
7
7
  begin
8
8
  Geocoder.search(ip).first
9
9
  rescue => e
10
- Rails.logger.warn "[ahoy] Geocode error: #{e.class.name}: #{e.message}"
10
+ Ahoy.log "Geocode error: #{e.class.name}: #{e.message}"
11
11
  nil
12
12
  end
13
13
 
14
- if location
14
+ if location && location.country.present?
15
15
  data = {
16
- visit_token: visit_token,
17
- country: location.try(:country).presence,
16
+ country: location.country,
18
17
  region: location.try(:state).presence,
19
18
  city: location.try(:city).presence,
20
19
  postal_code: location.try(:postal_code).presence,
@@ -17,7 +17,7 @@ gem 'ahoy_matey', '~> 2'
17
17
  And run:
18
18
 
19
19
  ```sh
20
- bundle install
20
+ bundle update ahoy_matey
21
21
  ```
22
22
 
23
23
  Add to `config/initializers/ahoy.rb`:
@@ -66,6 +66,10 @@ module Ahoy
66
66
 
67
67
  mattr_accessor :token_generator
68
68
  self.token_generator = -> { SecureRandom.uuid }
69
+
70
+ def self.log(message)
71
+ Rails.logger.info { "[ahoy] #{message}" }
72
+ end
69
73
  end
70
74
 
71
75
  ActiveSupport.on_load(:action_controller) do
@@ -4,7 +4,11 @@ module Ahoy
4
4
  @visit = visit_model.create!(slice_data(visit_model, data))
5
5
  rescue => e
6
6
  raise e unless unique_exception?(e)
7
- remove_instance_variable(:@visit)
7
+
8
+ # so next call to visit will try to fetch from DB
9
+ if defined?(@visit)
10
+ remove_instance_variable(:@visit)
11
+ end
8
12
  end
9
13
 
10
14
  def track_event(data)
@@ -18,19 +22,20 @@ module Ahoy
18
22
  raise e unless unique_exception?(e)
19
23
  end
20
24
  else
21
- Rails.logger.warn "[ahoy] Event excluded since visit not created: #{data[:visit_token]}"
25
+ Ahoy.log "Event excluded since visit not created: #{data[:visit_token]}"
22
26
  end
23
27
  end
24
28
 
25
29
  def geocode(data)
26
- data = slice_data(visit_model, data.except(:visit_token))
30
+ visit_token = data.delete(:visit_token)
31
+ data = slice_data(visit_model, data)
27
32
  if defined?(Mongoid::Document) && visit_model < Mongoid::Document
28
33
  # upsert since visit might not be found due to eventual consistency
29
- visit_model.where(visit_token: ahoy.visit_token).find_one_and_update({"$set": data}, {upsert: true})
34
+ visit_model.where(visit_token: visit_token).find_one_and_update({"$set": data}, {upsert: true})
30
35
  elsif visit
31
36
  visit.update_attributes(data)
32
37
  else
33
- Rails.logger.warn "[ahoy] Visit for geocode not found: #{data[:visit_token]}"
38
+ Ahoy.log "Visit for geocode not found: #{visit_token}"
34
39
  end
35
40
  end
36
41
 
@@ -65,7 +65,11 @@ module Ahoy
65
65
  if exclude?
66
66
  debug "Geocode excluded"
67
67
  else
68
- @store.geocode(data.select { |_, v| v })
68
+ data = {
69
+ visit_token: visit_token
70
+ }.merge(data).select { |_, v| v }
71
+
72
+ @store.geocode(data)
69
73
  true
70
74
  end
71
75
  rescue => e
@@ -256,7 +260,7 @@ module Ahoy
256
260
  end
257
261
 
258
262
  def debug(message)
259
- Rails.logger.debug { "[ahoy] #{message}" }
263
+ Ahoy.log message
260
264
  end
261
265
  end
262
266
  end
@@ -1,3 +1,3 @@
1
1
  module Ahoy
2
- VERSION = "2.0.1"
2
+ VERSION = "2.0.2"
3
3
  end
@@ -98,7 +98,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
98
98
  * Ahoy.js
99
99
  * Simple, powerful JavaScript analytics
100
100
  * https://github.com/ankane/ahoy.js
101
- * v0.3.0
101
+ * v0.3.1
102
102
  * MIT License
103
103
  */
104
104
 
@@ -186,10 +186,13 @@ function ready(callback) {
186
186
  }
187
187
 
188
188
  function matchesSelector(element, selector) {
189
- if (element.matches) {
190
- return element.matches(selector);
189
+ var matches = element.matches || element.matchesSelector || element.mozMatchesSelector || element.msMatchesSelector || element.oMatchesSelector || element.webkitMatchesSelector;
190
+
191
+ if (matches) {
192
+ return matches.apply(element, [selector]);
191
193
  } else {
192
- return element.msMatchesSelector(selector);
194
+ log("Unable to match");
195
+ return false;
193
196
  }
194
197
  }
195
198
 
@@ -216,7 +219,6 @@ function generateId() {
216
219
  }
217
220
 
218
221
  function saveEventQueue() {
219
- // TODO add stringify method for IE 7 and under
220
222
  if (canStringify) {
221
223
  setCookie("ahoy_events", JSON.stringify(eventQueue), 1);
222
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: 2.0.1
4
+ version: 2.0.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: 2018-02-27 00:00:00.000000000 Z
11
+ date: 2018-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: 1.4.5
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: 1.4.5
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: browser
57
57
  requirement: !ruby/object:Gem::Requirement